Skip to content

Commit 38cc03f

Browse files
[PS5][Driver] Restore whole-archive state when -fjmc (#115181)
`--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.
1 parent 4d4024e commit 38cc03f

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

clang/lib/Driver/ToolChains/PS4CPU.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,10 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
375375
}
376376

377377
if (UseJMC) {
378+
CmdArgs.push_back("--push-state");
378379
CmdArgs.push_back("--whole-archive");
379380
CmdArgs.push_back("-lSceJmc_nosubmission");
380-
CmdArgs.push_back("--no-whole-archive");
381+
CmdArgs.push_back("--pop-state");
381382
}
382383

383384
if (Args.hasArg(options::OPT_fuse_ld_EQ)) {

clang/test/Driver/ps5-linker.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@
8989

9090
// Test the driver's control over the JustMyCode behavior with linker flags.
9191

92-
// RUN: %clang --target=x86_64-sie-ps5 -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-LIB %s
93-
// RUN: %clang --target=x86_64-sie-ps5 -flto -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-LIB %s
92+
// RUN: %clang --target=x86_64-sie-ps5 -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-JMC %s
93+
// RUN: %clang --target=x86_64-sie-ps5 -flto -fjmc %s -### 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-JMC %s
9494

9595
// CHECK: -plugin-opt=-enable-jmc-instrument
9696

9797
// Check the default library name.
98-
// CHECK-LIB: "--whole-archive" "-lSceJmc_nosubmission" "--no-whole-archive"
98+
// CHECK-JMC: "--push-state" "--whole-archive" "-lSceJmc_nosubmission" "--pop-state"
9999

100100
// Test the driver's control over the -fcrash-diagnostics-dir behavior with linker flags.
101101

0 commit comments

Comments
 (0)