Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 895ca18

Browse files
[PS4/PS5][Driver] Allow -static in PlayStation drivers (llvm#102020)
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
1 parent aa86e5b commit 895ca18

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

clang/lib/Driver/ToolChains/PS4CPU.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ void tools::PS4cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
141141
if (Args.hasArg(options::OPT_pie))
142142
CmdArgs.push_back("-pie");
143143

144+
if (Args.hasArg(options::OPT_static))
145+
CmdArgs.push_back("-static");
144146
if (Args.hasArg(options::OPT_rdynamic))
145147
CmdArgs.push_back("-export-dynamic");
146148
if (Args.hasArg(options::OPT_shared))
@@ -238,6 +240,8 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
238240
if (Args.hasArg(options::OPT_pie))
239241
CmdArgs.push_back("-pie");
240242

243+
if (Args.hasArg(options::OPT_static))
244+
CmdArgs.push_back("-static");
241245
if (Args.hasArg(options::OPT_rdynamic))
242246
CmdArgs.push_back("-export-dynamic");
243247
if (Args.hasArg(options::OPT_shared))
@@ -316,10 +320,6 @@ toolchains::PS4PS5Base::PS4PS5Base(const Driver &D, const llvm::Triple &Triple,
316320
const ArgList &Args, StringRef Platform,
317321
const char *EnvVar)
318322
: Generic_ELF(D, Triple, Args) {
319-
if (Args.hasArg(clang::driver::options::OPT_static))
320-
D.Diag(clang::diag::err_drv_unsupported_opt_for_target)
321-
<< "-static" << Platform;
322-
323323
// Determine where to find the PS4/PS5 libraries.
324324
// If -isysroot was passed, use that as the SDK base path.
325325
// If not, we use the EnvVar if it exists; otherwise use the driver's

clang/test/Driver/ps4-linker.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
// Test that -static is forwarded to the linker
2+
3+
// RUN: %clang --target=x86_64-scei-ps4 -static %s -### 2>&1 | FileCheck --check-prefixes=CHECK-STATIC %s
4+
5+
// CHECK-STATIC: {{ld(\.exe)?}}"
6+
// CHECK-STATIC-SAME: "-static"
7+
18
// Test the driver's control over the JustMyCode behavior with linker flags.
29

310
// RUN: %clang --target=x86_64-scei-ps4 -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK-LTO,CHECK-LIB %s

clang/test/Driver/ps4-pic.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
// CHECK-DIAG-PIE: option '-fno-PIE' was ignored by the PS4 toolchain, using '-fPIC'
2424
// CHECK-DIAG-pic: option '-fno-pic' was ignored by the PS4 toolchain, using '-fPIC'
2525
// CHECK-DIAG-pie: option '-fno-pie' was ignored by the PS4 toolchain, using '-fPIC'
26-
//
27-
// CHECK-STATIC-ERR: unsupported option '-static' for target 'PS4'
2826

2927
// RUN: %clang -c %s -target x86_64-scei-ps4 -### 2>&1 \
3028
// RUN: | FileCheck %s --check-prefix=CHECK-PIC2
@@ -79,9 +77,10 @@
7977
// RUN: not %clang -c %s --target=x86_64-scei-ps4 -mdynamic-no-pic -fPIC -### 2>&1 \
8078
// RUN: | FileCheck %s --check-prefix=CHECK-DYNAMIC-NO-PIC2
8179
//
82-
// -static not supported at all.
83-
// RUN: not %clang -c %s --target=x86_64-scei-ps4 -static -### 2>&1 \
84-
// RUN: | FileCheck %s --check-prefix=CHECK-STATIC-ERR
80+
// The -static argument *doesn't* override PIC: -static only affects
81+
// linking, and -fPIC only affects code generation.
82+
// RUN: %clang -c %s -target x86_64-scei-ps4 -static -fPIC -### 2>&1 \
83+
// RUN: | FileCheck %s --check-prefix=CHECK-PIC2
8584
//
8685
// -fno-PIC etc. is obeyed if -mcmodel=kernel is also present.
8786
// RUN: %clang -c %s -target x86_64-scei-ps4 -mcmodel=kernel -fno-PIC -### 2>&1 \

clang/test/Driver/ps5-linker.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
// Test that -static is forwarded to the linker
2+
3+
// RUN: %clang --target=x86_64-scei-ps5 -static %s -### 2>&1 | FileCheck --check-prefixes=CHECK-STATIC %s
4+
5+
// CHECK-STATIC: {{ld(\.exe)?}}"
6+
// CHECK-STATIC-SAME: "-static"
7+
18
// Test the driver's control over the JustMyCode behavior with linker flags.
29

310
// RUN: %clang --target=x86_64-scei-ps5 -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-LIB %s

clang/test/Driver/ps5-pic.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
// CHECK-DIAG-PIE: option '-fno-PIE' was ignored by the PS5 toolchain, using '-fPIC'
2424
// CHECK-DIAG-pic: option '-fno-pic' was ignored by the PS5 toolchain, using '-fPIC'
2525
// CHECK-DIAG-pie: option '-fno-pie' was ignored by the PS5 toolchain, using '-fPIC'
26-
//
27-
// CHECK-STATIC-ERR: unsupported option '-static' for target 'PS5'
2826

2927
// RUN: %clang -c %s -target x86_64-sie-ps5 -### 2>&1 \
3028
// RUN: | FileCheck %s --check-prefix=CHECK-PIC2
@@ -79,9 +77,10 @@
7977
// RUN: not %clang -c %s --target=x86_64-sie-ps5 -mdynamic-no-pic -fPIC -### 2>&1 \
8078
// RUN: | FileCheck %s --check-prefix=CHECK-DYNAMIC-NO-PIC2
8179
//
82-
// -static not supported at all.
83-
// RUN: not %clang -c %s --target=x86_64-sie-ps5 -static -### 2>&1 \
84-
// RUN: | FileCheck %s --check-prefix=CHECK-STATIC-ERR
80+
// The -static argument *doesn't* override PIC: -static only affects
81+
// linking, and -fPIC only affects code generation.
82+
// RUN: %clang -c %s -target x86_64-sie-ps5 -static -fPIC -### 2>&1 \
83+
// RUN: | FileCheck %s --check-prefix=CHECK-PIC2
8584
//
8685
// -fno-PIC etc. is obeyed if -mcmodel=kernel is also present.
8786
// RUN: %clang -c %s -target x86_64-sie-ps5 -mcmodel=kernel -fno-PIC -### 2>&1 \

0 commit comments

Comments
 (0)