Skip to content

Commit 340cb39

Browse files
[PS5][Driver] Pass layout metrics to the linker (#114435)
Until now, these have been hardcoded as a downstream patches in lld. Add them to the driver so that the private patches can be removed. PS5 only. On PS4, the equivalent hardcoded configuration will remain in the proprietary linker. SIE tracker: TOOLCHAIN-16704
1 parent b77e402 commit 340cb39

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

clang/lib/Driver/ToolChains/PS4CPU.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,9 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
248248
Args.MakeArgString("--sysroot=" + TC.getSDKLibraryRootDir()));
249249

250250
// Default to PIE for non-static executables.
251-
const bool PIE = !Relocatable && !Shared && !Static;
252-
if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
251+
const bool PIE = Args.hasFlag(options::OPT_pie, options::OPT_no_pie,
252+
!Relocatable && !Shared && !Static);
253+
if (PIE)
253254
CmdArgs.push_back("-pie");
254255

255256
if (!Relocatable) {
@@ -276,6 +277,12 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
276277
CmdArgs.push_back("-z");
277278
CmdArgs.push_back("start-stop-visibility=hidden");
278279

280+
CmdArgs.push_back("-z");
281+
CmdArgs.push_back("common-page-size=0x4000");
282+
283+
CmdArgs.push_back("-z");
284+
CmdArgs.push_back("max-page-size=0x4000");
285+
279286
// Patch relocated regions of DWARF whose targets are eliminated at link
280287
// time with specific tombstones, such that they're recognisable by the
281288
// PlayStation debugger.
@@ -295,6 +302,11 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
295302
if (Shared)
296303
CmdArgs.push_back("--shared");
297304

305+
// Provide a base address for non-PIE executables. This includes cases where
306+
// -static is supplied without -pie.
307+
if (!Relocatable && !Shared && !PIE)
308+
CmdArgs.push_back("--image-base=0x400000");
309+
298310
assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
299311
if (Output.isFilename()) {
300312
CmdArgs.push_back("-o");

clang/test/Driver/ps5-linker.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@
2121
// CHECK-NO-PIE-NOT: "-pie"
2222
// CHECK-SHARED: "--shared"
2323

24+
// Test the driver supplies an --image-base to the linker only for non-pie
25+
// executables.
26+
27+
// RUN: %clang --target=x86_64-sie-ps5 -static %s -### 2>&1 | FileCheck --check-prefixes=CHECK-BASE %s
28+
// RUN: %clang --target=x86_64-sie-ps5 -no-pie %s -### 2>&1 | FileCheck --check-prefixes=CHECK-BASE %s
29+
30+
// CHECK-BASE: {{ld(\.exe)?}}"
31+
// CHECK-BASE-SAME: "--image-base=0x400000"
32+
33+
// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-BASE %s
34+
// RUN: %clang --target=x86_64-sie-ps5 -r %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-BASE %s
35+
// RUN: %clang --target=x86_64-sie-ps5 -shared %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-BASE %s
36+
37+
// CHECK-NO-BASE: {{ld(\.exe)?}}"
38+
// CHECK-NO-BASE-NOT: --image-base
39+
2440
// Test the driver passes PlayStation-specific options to the linker that are
2541
// appropriate for the type of output. Many options don't apply for relocatable
2642
// output (-r).
@@ -37,6 +53,8 @@
3753
// CHECK-EXE-SAME: "--unresolved-symbols=report-all"
3854
// CHECK-EXE-SAME: "-z" "now"
3955
// CHECK-EXE-SAME: "-z" "start-stop-visibility=hidden"
56+
// CHECK-EXE-SAME: "-z" "common-page-size=0x4000"
57+
// CHECK-EXE-SAME: "-z" "max-page-size=0x4000"
4058
// CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_*=0xffffffffffffffff"
4159
// CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_ranges=0xfffffffffffffffe"
4260
// CHECK-EXE-SAME: "-z" "dead-reloc-in-nonalloc=.debug_loc=0xfffffffffffffffe"

0 commit comments

Comments
 (0)