[clang] [PS5][Driver] Link main components with -pie by default (PR #102901)

via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 12 06:47:49 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Edd Dawson (playstation-edd)

<details>
<summary>Changes</summary>

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

---
Full diff: https://github.com/llvm/llvm-project/pull/102901.diff


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/PS4CPU.cpp (+4-1) 
- (modified) clang/test/Driver/ps5-linker.c (+15) 


``````````diff
diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 0175b5eb63e657..73f4c4e2fc7a49 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -237,7 +237,10 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
   if (!D.SysRoot.empty())
     CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
-  if (Args.hasArg(options::OPT_pie))
+  // Default to PIE for non-static main components.
+  const bool PIE =
+      !Args.hasArg(options::OPT_r, options::OPT_shared, options::OPT_static);
+  if (Args.hasFlag(options::OPT_pie, options::OPT_no_pie, PIE))
     CmdArgs.push_back("-pie");
 
   if (Args.hasArg(options::OPT_static))
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 95d64d9017be04..fb954b938c1ab9 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -1,3 +1,18 @@
+// Test that PIE is the default for main components
+
+// RUN: %clang --target=x86_64-scei-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-PIE %s
+
+// CHECK-PIE: {{ld(\.exe)?}}"
+// CHECK-PIE-SAME: "-pie"
+
+// RUN: %clang --target=x86_64-scei-ps5 -no-pie %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-PIE %s
+// RUN: %clang --target=x86_64-scei-ps5 -r %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-PIE %s
+// RUN: %clang --target=x86_64-scei-ps5 -shared %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-PIE %s
+// RUN: %clang --target=x86_64-scei-ps5 -static %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-PIE %s
+
+// CHECK-NO-PIE: {{ld(\.exe)?}}"
+// CHECK-NO-PIE-NOT: "-pie"
+
 // Test that -static is forwarded to the linker
 
 // RUN: %clang --target=x86_64-scei-ps5 -static %s -### 2>&1 | FileCheck --check-prefixes=CHECK-STATIC %s

``````````

</details>


https://github.com/llvm/llvm-project/pull/102901


More information about the cfe-commits mailing list