Skip to content

Commit ac5a201

Browse files
[PS5][Driver] Pass default -z options to PS5 linker (#113162)
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. The implementation of these behaviours will remain in the proprietary linker on PS4. SIE tracker: TOOLCHAIN-16704
1 parent dfc4065 commit ac5a201

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

clang/lib/Driver/ToolChains/PS4CPU.cpp

Lines changed: 24 additions & 0 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"
@@ -246,6 +248,28 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
246248
if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
247249
CmdArgs.push_back("-pie");
248250

251+
if (!Relocatable) {
252+
// Lazy binding of PLTs is not supported on PlayStation. They are placed in
253+
// the RelRo segment.
254+
CmdArgs.push_back("-z");
255+
CmdArgs.push_back("now");
256+
257+
// Don't export linker-generated __start/stop... section bookends.
258+
CmdArgs.push_back("-z");
259+
CmdArgs.push_back("start-stop-visibility=hidden");
260+
261+
// Patch relocated regions of DWARF whose targets are eliminated at link
262+
// time with specific tombstones, such that they're recognisable by the
263+
// PlayStation debugger.
264+
CmdArgs.push_back("-z");
265+
CmdArgs.push_back("dead-reloc-in-nonalloc=.debug_*=0xffffffffffffffff");
266+
CmdArgs.push_back("-z");
267+
CmdArgs.push_back(
268+
"dead-reloc-in-nonalloc=.debug_ranges=0xfffffffffffffffe");
269+
CmdArgs.push_back("-z");
270+
CmdArgs.push_back("dead-reloc-in-nonalloc=.debug_loc=0xfffffffffffffffe");
271+
}
272+
249273
if (Args.hasArg(options::OPT_static))
250274
CmdArgs.push_back("-static");
251275
if (Args.hasArg(options::OPT_rdynamic))

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)