Skip to content

Commit 0d931fb

Browse files
[PS5][Driver] Pass default -z options to PS5 linker
Until now, these options have been hardcoded as downstream patches in LLD. Add them to the driver so that the private patches can be removed. PS5 only. These implementation of these behaviours will remain in the proprietary linker on PS4. SIE tracker: TOOLCHAIN-16704
1 parent 25b58c8 commit 0d931fb

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

clang/lib/Driver/ToolChains/PS4CPU.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
229229
const Driver &D = TC.getDriver();
230230
ArgStringList CmdArgs;
231231

232+
const bool Relocatable = Args.hasArg(options::OPT_r);
233+
232234
// Silence warning for "clang -g foo.o -o foo"
233235
Args.ClaimAllArgs(options::OPT_g_Group);
234236
// and "clang -emit-llvm foo.o -o foo"
@@ -240,11 +242,32 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
240242
CmdArgs.push_back(
241243
Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
242244

243-
// Default to PIE for non-static executables.
244-
const bool PIE =
245-
!Args.hasArg(options::OPT_r, options::OPT_shared, options::OPT_static);
246-
if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
247-
CmdArgs.push_back("-pie");
245+
if (!Relocatable) {
246+
// Default to PIE for non-static executables.
247+
const bool PIE = !Args.hasArg(options::OPT_shared, options::OPT_static);
248+
if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
249+
CmdArgs.push_back("-pie");
250+
251+
// Lazy binding of PLTs is not supported on PlayStation. They are placed in
252+
// the RelRo segment.
253+
CmdArgs.push_back("-z");
254+
CmdArgs.push_back("now");
255+
256+
// Don't export linker-generated __start/stop... section bookends.
257+
CmdArgs.push_back("-z");
258+
CmdArgs.push_back("start-stop-visibility=hidden");
259+
260+
// Patch relocated regions of DWARF whose targets are eliminated at link
261+
// time with specific tombstones, such that they're recognisable by the
262+
// PlayStation debugger.
263+
CmdArgs.push_back("-z");
264+
CmdArgs.push_back("dead-reloc-in-nonalloc=.debug*=0xffffffffffffffff");
265+
CmdArgs.push_back("-z");
266+
CmdArgs.push_back(
267+
"dead-reloc-in-nonalloc=.debug_ranges=0xfffffffffffffffe");
268+
CmdArgs.push_back("-z");
269+
CmdArgs.push_back("dead-reloc-in-nonalloc=.debug_loc=0xfffffffffffffffe");
270+
}
248271

249272
if (Args.hasArg(options::OPT_static))
250273
CmdArgs.push_back("-static");

clang/test/Driver/ps5-linker.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@
1414
// CHECK-NO-PIE-NOT: "-pie"
1515
// CHECK-SHARED: "--shared"
1616

17+
// Test the driver passes PlayStation-specific -z options to the linker.
18+
19+
// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-Z %s
20+
21+
// CHECK-Z: {{ld(\.exe)?}}"
22+
// CHECK-Z-SAME: "-z" "now"
23+
// CHECK-Z-SAME: "-z" "start-stop-visibility=hidden"
24+
// CHECK-Z-SAME: "-z" "dead-reloc-in-nonalloc=.debug*=0xffffffffffffffff"
25+
// CHECK-Z-SAME: "-z" "dead-reloc-in-nonalloc=.debug_ranges=0xfffffffffffffffe"
26+
// CHECK-Z-SAME: "-z" "dead-reloc-in-nonalloc=.debug_loc=0xfffffffffffffffe"
27+
28+
// RUN: %clang --target=x86_64-sie-ps5 -r %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-Z %s
29+
30+
// CHECK-NO-Z: {{ld(\.exe)?}}"
31+
// CHECK-NO-Z-NOT: "-z"
32+
1733
// Test that -static is forwarded to the linker
1834

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

0 commit comments

Comments
 (0)