[clang] [PS5][Driver] Link main components with -pie by default (PR #102901)
Edd Dawson via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 21 01:04:06 PDT 2024
https://github.com/playstation-edd updated https://github.com/llvm/llvm-project/pull/102901
>From 0ca2239d21cb414ce5e6fb9057d442c18f61a32e Mon Sep 17 00:00:00 2001
From: Edd Dawson <edd.dawson at sony.com>
Date: Mon, 12 Aug 2024 14:11:11 +0100
Subject: [PATCH 1/3] [PS5][Driver] Link main components with -pie by default
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
---
clang/lib/Driver/ToolChains/PS4CPU.cpp | 5 ++++-
clang/test/Driver/ps5-linker.c | 15 +++++++++++++++
2 files changed, 19 insertions(+), 1 deletion(-)
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
>From b7ff265805d8f2c5e7cb22e8c7fd1440665599a8 Mon Sep 17 00:00:00 2001
From: Edd Dawson <edd.dawson at sony.com>
Date: Wed, 21 Aug 2024 08:48:37 +0100
Subject: [PATCH 2/3] "main components" -> "executables"
---
clang/lib/Driver/ToolChains/PS4CPU.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 73f4c4e2fc7a49..22103eb50803a5 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -237,7 +237,7 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (!D.SysRoot.empty())
CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
- // Default to PIE for non-static main components.
+ // Default to PIE for non-static executables.
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))
>From 7280be4660df554541f0c700d943016ba2d2430d Mon Sep 17 00:00:00 2001
From: Edd Dawson <edd.dawson at sony.com>
Date: Wed, 21 Aug 2024 09:00:49 +0100
Subject: [PATCH 3/3] Add check for "--shared", along with lack of "-pie".
---
clang/test/Driver/ps5-linker.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index fb954b938c1ab9..c462e5a178e4a6 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -7,11 +7,12 @@
// 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 -shared %s -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-PIE,CHECK-SHARED %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"
+// CHECK-SHARED: "--shared"
// Test that -static is forwarded to the linker
More information about the cfe-commits
mailing list