[clang] [PS5][Driver] Restore whole-archive state when `-fjmc` (PR #115181)

Edd Dawson via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 6 10:18:52 PST 2024


https://github.com/playstation-edd updated https://github.com/llvm/llvm-project/pull/115181

>From c2eec3d06ad920ef2b7826fe9b76f1b45574e036 Mon Sep 17 00:00:00 2001
From: Edd Dawson <edd.dawson at sony.com>
Date: Wed, 6 Nov 2024 16:24:46 +0000
Subject: [PATCH 1/2] [PS5][Driver] Restore whole-archive state when `-fjmc`

`--whole-archive` is passed to the linker to have it consume all objects
within the SIE Just My Code library, rather than just those that fulfil
outstanding references.

Prior to this change, `--no-whole-archive` was used to reset the
associated archive handling state in the linker, under the assumption
that `--whole-archive` wasn't already in effect. But that assumption may
be incorrect. So use `--push/pop-state` to restore the previous state,
whatever that may be.

Given the position of these switches on the link line, the problem
described with the outgoing code is unlikely to cause an issue in
practice. But push/pop protect against accidents due to future additions
to and reorderings of arguments.

PS5 only. The proprietary PS4 linker doesn't support `--push/pop-state`,
or an equivalent.

SIE tracker: TOOLCHAIN-16704.
---
 clang/lib/Driver/ToolChains/PS4CPU.cpp | 3 ++-
 clang/test/Driver/ps5-linker.c         | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 261c136de782e7..df43da93d77555 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -375,9 +375,10 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
   }
 
   if (UseJMC) {
+    CmdArgs.push_back("--push-state");
     CmdArgs.push_back("--whole-archive");
     CmdArgs.push_back("-lSceJmc_nosubmission");
-    CmdArgs.push_back("--no-whole-archive");
+    CmdArgs.push_back("--pop-state");
   }
 
   if (Args.hasArg(options::OPT_fuse_ld_EQ)) {
diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index 8a0ade91871295..fb5f8a9ec5cee5 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -95,7 +95,7 @@
 // CHECK: -plugin-opt=-enable-jmc-instrument
 
 // Check the default library name.
-// CHECK-LIB: "--whole-archive" "-lSceJmc_nosubmission" "--no-whole-archive"
+// CHECK-LIB: "--push-state" "--whole-archive" "-lSceJmc_nosubmission" "--pop-state"
 
 // Test the driver's control over the -fcrash-diagnostics-dir behavior with linker flags.
 

>From e8f465066edc9f7230f6751b94de90b71a2eb56a Mon Sep 17 00:00:00 2001
From: Edd Dawson <edd.dawson at sony.com>
Date: Wed, 6 Nov 2024 18:17:57 +0000
Subject: [PATCH 2/2] CHECK-LIB -> CHECK-JMC

---
 clang/test/Driver/ps5-linker.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/test/Driver/ps5-linker.c b/clang/test/Driver/ps5-linker.c
index fb5f8a9ec5cee5..95267942edc172 100644
--- a/clang/test/Driver/ps5-linker.c
+++ b/clang/test/Driver/ps5-linker.c
@@ -89,13 +89,13 @@
 
 // Test the driver's control over the JustMyCode behavior with linker flags.
 
-// RUN: %clang --target=x86_64-sie-ps5 -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-LIB %s
-// RUN: %clang --target=x86_64-sie-ps5 -flto -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-LIB %s
+// RUN: %clang --target=x86_64-sie-ps5 -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-JMC %s
+// RUN: %clang --target=x86_64-sie-ps5 -flto -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-JMC %s
 
 // CHECK: -plugin-opt=-enable-jmc-instrument
 
 // Check the default library name.
-// CHECK-LIB: "--push-state" "--whole-archive" "-lSceJmc_nosubmission" "--pop-state"
+// CHECK-JMC: "--push-state" "--whole-archive" "-lSceJmc_nosubmission" "--pop-state"
 
 // Test the driver's control over the -fcrash-diagnostics-dir behavior with linker flags.
 



More information about the cfe-commits mailing list