From aa97906cdf1ac08e0b5d607914c28dcb2bbc2545 Mon Sep 17 00:00:00 2001 From: Edd Dawson Date: Mon, 5 Aug 2024 17:42:55 +0100 Subject: [PATCH 1/3] [PS4/PS5][Driver] Allow -static in PlayStation drivers On PlayStation, allow users to supply -static to the linker, via the driver. An initial step. Later changes will have the PS5 driver supply additional options to the linker, if and when -static is passed. SIE tracker: TOOLCHAIN-16704 --- clang/lib/Driver/ToolChains/PS4CPU.cpp | 9 +++++---- clang/test/Driver/ps4-linker.c | 7 +++++++ clang/test/Driver/ps4-pic.c | 9 ++++----- clang/test/Driver/ps5-linker.c | 7 +++++++ clang/test/Driver/ps5-pic.c | 9 ++++----- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp b/clang/lib/Driver/ToolChains/PS4CPU.cpp index a9e612c44da06a0..3da9a280fd129d1 100644 --- a/clang/lib/Driver/ToolChains/PS4CPU.cpp +++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp @@ -141,6 +141,9 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (Args.hasArg(options::OPT_pie)) CmdArgs.push_back("-pie"); + + if (Args.hasArg(options::OPT_static)) + CmdArgs.push_back("--static"); if (Args.hasArg(options::OPT_rdynamic)) CmdArgs.push_back("-export-dynamic"); if (Args.hasArg(options::OPT_shared)) @@ -238,6 +241,8 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (Args.hasArg(options::OPT_pie)) CmdArgs.push_back("-pie"); + if (Args.hasArg(options::OPT_static)) + CmdArgs.push_back("--static"); if (Args.hasArg(options::OPT_rdynamic)) CmdArgs.push_back("-export-dynamic"); if (Args.hasArg(options::OPT_shared)) @@ -316,10 +321,6 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const llvm::Triple &Triple, const ArgList &Args, StringRef Platform, const char *EnvVar) : Generic_ELF(D, Triple, Args) { - if (Args.hasArg(clang::driver::options::OPT_static)) - D.Diag(clang::diag::err_drv_unsupported_opt_for_target) - << "-static" << Platform; - // Determine where to find the PS4/PS5 libraries. // If -isysroot was passed, use that as the SDK base path. // If not, we use the EnvVar if it exists; otherwise use the driver's diff --git a/clang/test/Driver/ps4-linker.c b/clang/test/Driver/ps4-linker.c index 2a095d660bf3651..47a515158fe81d0 100644 --- a/clang/test/Driver/ps4-linker.c +++ b/clang/test/Driver/ps4-linker.c @@ -1,3 +1,10 @@ +// Test that -static is forwarded to the linker + +// RUN: %clang --target=x86_64-scei-ps4 -static %s -### 2>&1 | FileCheck --check-prefixes=CHECK-STATIC %s + +// CHECK-STATIC: {{ld(\.exe)?}}" +// CHECK-STATIC-SAME: "--static" + // Test the driver's control over the JustMyCode behavior with linker flags. // RUN: %clang --target=x86_64-scei-ps4 -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK-LTO,CHECK-LIB %s diff --git a/clang/test/Driver/ps4-pic.c b/clang/test/Driver/ps4-pic.c index 0551a79cc125814..3072f379d13c6a3 100644 --- a/clang/test/Driver/ps4-pic.c +++ b/clang/test/Driver/ps4-pic.c @@ -23,8 +23,6 @@ // CHECK-DIAG-PIE: option '-fno-PIE' was ignored by the PS4 toolchain, using '-fPIC' // CHECK-DIAG-pic: option '-fno-pic' was ignored by the PS4 toolchain, using '-fPIC' // CHECK-DIAG-pie: option '-fno-pie' was ignored by the PS4 toolchain, using '-fPIC' -// -// CHECK-STATIC-ERR: unsupported option '-static' for target 'PS4' // RUN: %clang -c %s -target x86_64-scei-ps4 -### 2>&1 \ // RUN: | FileCheck %s --check-prefix=CHECK-PIC2 @@ -79,9 +77,10 @@ // RUN: not %clang -c %s --target=x86_64-scei-ps4 -mdynamic-no-pic -fPIC -### 2>&1 \ // RUN: | FileCheck %s --check-prefix=CHECK-DYNAMIC-NO-PIC2 // -// -static not supported at all. -// RUN: not %clang -c %s --target=x86_64-scei-ps4 -static -### 2>&1 \ -// RUN: | FileCheck %s --check-prefix=CHECK-STATIC-ERR +// The -static argument *doesn't* override PIC: -static only affects +// linking, and -fPIC only affects code generation. +// RUN: %clang -c %s -target x86_64-scei-ps4 -static -fPIC -### 2>&1 \ +// RUN: | FileCheck %s --check-prefix=CHECK-PIC2 // // -fno-PIC etc. is obeyed if -mcmodel=kernel is also present. // RUN: %clang -c %s -target x86_64-scei-ps4 -mcmodel=kernel -fno-PIC -### 2>&1 \ diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c index cf39d5bae97acd7..01c0e20f970ed7d 100644 --- a/clang/test/Driver/ps5-linker.c +++ b/clang/test/Driver/ps5-linker.c @@ -1,3 +1,10 @@ +// Test that -static is forwarded to the linker + +// RUN: %clang --target=x86_64-scei-ps5 -static %s -### 2>&1 | FileCheck --check-prefixes=CHECK-STATIC %s + +// CHECK-STATIC: {{ld(\.exe)?}}" +// CHECK-STATIC-SAME: "--static" + // Test the driver's control over the JustMyCode behavior with linker flags. // RUN: %clang --target=x86_64-scei-ps5 -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-LIB %s diff --git a/clang/test/Driver/ps5-pic.c b/clang/test/Driver/ps5-pic.c index dcb1d50306ae13b..2855bb5ec282ad8 100644 --- a/clang/test/Driver/ps5-pic.c +++ b/clang/test/Driver/ps5-pic.c @@ -23,8 +23,6 @@ // CHECK-DIAG-PIE: option '-fno-PIE' was ignored by the PS5 toolchain, using '-fPIC' // CHECK-DIAG-pic: option '-fno-pic' was ignored by the PS5 toolchain, using '-fPIC' // CHECK-DIAG-pie: option '-fno-pie' was ignored by the PS5 toolchain, using '-fPIC' -// -// CHECK-STATIC-ERR: unsupported option '-static' for target 'PS5' // RUN: %clang -c %s -target x86_64-sie-ps5 -### 2>&1 \ // RUN: | FileCheck %s --check-prefix=CHECK-PIC2 @@ -79,9 +77,10 @@ // RUN: not %clang -c %s --target=x86_64-sie-ps5 -mdynamic-no-pic -fPIC -### 2>&1 \ // RUN: | FileCheck %s --check-prefix=CHECK-DYNAMIC-NO-PIC2 // -// -static not supported at all. -// RUN: not %clang -c %s --target=x86_64-sie-ps5 -static -### 2>&1 \ -// RUN: | FileCheck %s --check-prefix=CHECK-STATIC-ERR +// The -static argument *doesn't* override PIC: -static only affects +// linking, and -fPIC only affects code generation. +// RUN: %clang -c %s -target x86_64-sie-ps5 -static -fPIC -### 2>&1 \ +// RUN: | FileCheck %s --check-prefix=CHECK-PIC2 // // -fno-PIC etc. is obeyed if -mcmodel=kernel is also present. // RUN: %clang -c %s -target x86_64-sie-ps5 -mcmodel=kernel -fno-PIC -### 2>&1 \ From fa9222aa2388bc3040114b0106096499408267a2 Mon Sep 17 00:00:00 2001 From: Edd Dawson Date: Tue, 6 Aug 2024 09:16:01 +0100 Subject: [PATCH 2/3] Remove superfluous linebreak --- clang/lib/Driver/ToolChains/PS4CPU.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp b/clang/lib/Driver/ToolChains/PS4CPU.cpp index 3da9a280fd129d1..e3e4c51e168a7f0 100644 --- a/clang/lib/Driver/ToolChains/PS4CPU.cpp +++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp @@ -141,7 +141,6 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (Args.hasArg(options::OPT_pie)) CmdArgs.push_back("-pie"); - if (Args.hasArg(options::OPT_static)) CmdArgs.push_back("--static"); if (Args.hasArg(options::OPT_rdynamic)) From 9cc12df9b709a7393e5355ec40f97d3d42b33768 Mon Sep 17 00:00:00 2001 From: Edd Dawson Date: Tue, 6 Aug 2024 09:34:47 +0100 Subject: [PATCH 3/3] --static -> -static --- clang/lib/Driver/ToolChains/PS4CPU.cpp | 4 ++-- clang/test/Driver/ps4-linker.c | 2 +- clang/test/Driver/ps5-linker.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp b/clang/lib/Driver/ToolChains/PS4CPU.cpp index e3e4c51e168a7f0..0175b5eb63e6578 100644 --- a/clang/lib/Driver/ToolChains/PS4CPU.cpp +++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp @@ -142,7 +142,7 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-pie"); if (Args.hasArg(options::OPT_static)) - CmdArgs.push_back("--static"); + CmdArgs.push_back("-static"); if (Args.hasArg(options::OPT_rdynamic)) CmdArgs.push_back("-export-dynamic"); if (Args.hasArg(options::OPT_shared)) @@ -241,7 +241,7 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-pie"); if (Args.hasArg(options::OPT_static)) - CmdArgs.push_back("--static"); + CmdArgs.push_back("-static"); if (Args.hasArg(options::OPT_rdynamic)) CmdArgs.push_back("-export-dynamic"); if (Args.hasArg(options::OPT_shared)) diff --git a/clang/test/Driver/ps4-linker.c b/clang/test/Driver/ps4-linker.c index 47a515158fe81d0..a1bc8f925375458 100644 --- a/clang/test/Driver/ps4-linker.c +++ b/clang/test/Driver/ps4-linker.c @@ -3,7 +3,7 @@ // RUN: %clang --target=x86_64-scei-ps4 -static %s -### 2>&1 | FileCheck --check-prefixes=CHECK-STATIC %s // CHECK-STATIC: {{ld(\.exe)?}}" -// CHECK-STATIC-SAME: "--static" +// CHECK-STATIC-SAME: "-static" // Test the driver's control over the JustMyCode behavior with linker flags. diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c index 01c0e20f970ed7d..95d64d9017be04c 100644 --- a/clang/test/Driver/ps5-linker.c +++ b/clang/test/Driver/ps5-linker.c @@ -3,7 +3,7 @@ // RUN: %clang --target=x86_64-scei-ps5 -static %s -### 2>&1 | FileCheck --check-prefixes=CHECK-STATIC %s // CHECK-STATIC: {{ld(\.exe)?}}" -// CHECK-STATIC-SAME: "--static" +// CHECK-STATIC-SAME: "-static" // Test the driver's control over the JustMyCode behavior with linker flags.