Skip to content

Commit 297bb46

Browse files
[PS5][Driver] Link main components with -pie by default (#102901)
The PS5 linker currently forces `-pie` for typical link jobs. Have the driver pass `pie` under the same conditions. With this change we can remove our private linker patch and also allow `-no-pie` to have an effect. SIE tracker: TOOLCHAIN-16704
1 parent 3083459 commit 297bb46

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

clang/lib/Driver/ToolChains/PS4CPU.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,10 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
237237
if (!D.SysRoot.empty())
238238
CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
239239

240-
if (Args.hasArg(options::OPT_pie))
240+
// Default to PIE for non-static executables.
241+
const bool PIE =
242+
!Args.hasArg(options::OPT_r, options::OPT_shared, options::OPT_static);
243+
if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
241244
CmdArgs.push_back("-pie");
242245

243246
if (Args.hasArg(options::OPT_static))

clang/test/Driver/ps5-linker.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
// Test that PIE is the default for main components
2+
3+
// RUN: %clang --target=x86_64-scei-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-PIE %s
4+
5+
// CHECK-PIE: {{ld(\.exe)?}}"
6+
// CHECK-PIE-SAME: "-pie"
7+
8+
// RUN: %clang --target=x86_64-scei-ps5 -no-pie %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-PIE %s
9+
// RUN: %clang --target=x86_64-scei-ps5 -r %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-PIE %s
10+
// RUN: %clang --target=x86_64-scei-ps5 -shared %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-PIE,CHECK-SHARED %s
11+
// RUN: %clang --target=x86_64-scei-ps5 -static %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-PIE %s
12+
13+
// CHECK-NO-PIE: {{ld(\.exe)?}}"
14+
// CHECK-NO-PIE-NOT: "-pie"
15+
// CHECK-SHARED: "--shared"
16+
117
// Test that -static is forwarded to the linker
218

319
// RUN: %clang --target=x86_64-scei-ps5 -static %s -### 2>&1 | FileCheck --check-prefixes=CHECK-STATIC %s

0 commit comments

Comments
 (0)