[clang] a779dc3 - [PS5][Driver] Supply default linker scripts (#114546)

via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 4 10:06:50 PST 2024


Author: Edd Dawson
Date: 2024-11-04T18:06:45Z
New Revision: a779dc3754fe6cd2d72766f6313b3e88c0fd7d35

URL: https://github.com/llvm/llvm-project/commit/a779dc3754fe6cd2d72766f6313b3e88c0fd7d35
DIFF: https://github.com/llvm/llvm-project/commit/a779dc3754fe6cd2d72766f6313b3e88c0fd7d35.diff

LOG: [PS5][Driver] Supply default linker scripts (#114546)

Until now, this has been hardcoded as a downstream patch in lld. Add it
to the driver so that the private patch can be removed.

PS5 only. On PS4, the equivalent hardcoded configuration will remain in
the proprietary linker.

SIE tracker: TOOLCHAIN-16704

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/PS4CPU.cpp
    clang/test/Driver/ps5-linker.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 877cb4e7b1261f..c5299d606f2386 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -293,6 +293,16 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
         "dead-reloc-in-nonalloc=.debug_ranges=0xfffffffffffffffe");
     CmdArgs.push_back("-z");
     CmdArgs.push_back("dead-reloc-in-nonalloc=.debug_loc=0xfffffffffffffffe");
+
+    // The PlayStation loader expects linked objects to be laid out in a
+    // particular way. This is achieved by linker scripts that are supplied
+    // with the SDK. The scripts are inside <sdkroot>/target/lib, which is
+    // added as a search path elsewhere.
+    // "PRX" has long stood for "PlayStation Relocatable eXecutable".
+    CmdArgs.push_back("--default-script");
+    CmdArgs.push_back(Static   ? "static.script"
+                      : Shared ? "prx.script"
+                               : "main.script");
   }
 
   if (Static)

diff  --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 0fcc0f02f5a901..363c431b6937eb 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -66,6 +66,19 @@
 // CHECK-NO-EXE-NOT: "--unresolved-symbols
 // CHECK-NO-EXE-NOT: "-z"
 
+// Test that an appropriate linker script is supplied by the driver.
+
+// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-SCRIPT -DSCRIPT=main %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -shared -### 2>&1 | FileCheck --check-prefixes=CHECK-SCRIPT -DSCRIPT=prx %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -static -### 2>&1 | FileCheck --check-prefixes=CHECK-SCRIPT -DSCRIPT=static %s
+// RUN: %clang --target=x86_64-sie-ps5 %s -r -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-SCRIPT %s
+
+// CHECK-SCRIPT: {{ld(\.exe)?}}"
+// CHECK-SCRIPT-SAME: "--default-script" "[[SCRIPT]].script"
+
+// CHECK-NO-SCRIPT: {{ld(\.exe)?}}"
+// CHECK-NO-SCRIPT-NOT: "--default-script"
+
 // Test that -static is forwarded to the linker
 
 // RUN: %clang --target=x86_64-sie-ps5 -static %s -### 2>&1 | FileCheck --check-prefixes=CHECK-STATIC %s


        


More information about the cfe-commits mailing list