Skip to content

Commit 28626ed

Browse files
Automerge: [PS5][Driver] Allow selection of CRT with -L (#145869)
There's long standing behaviour in PlayStation to allow user-supplied library search paths (`-L`) to influence lookup of CRT objects. This seems to be a historical quirk that has persisted to the present day. This usage of `-L` for CRT selection is deeply entrenched among users of the PS5 toolchain. While this change is conceptually bothersome, it does reflect what's shipped. SIE tracker: TOOLCHAIN-17706
2 parents f2452a1 + 772009c commit 28626ed

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

clang/lib/Driver/ToolChains/PS4CPU.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,10 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
379379
!Relocatable &&
380380
!Args.hasArg(options::OPT_nostartfiles, options::OPT_nostdlib);
381381

382-
auto AddCRTObject = [&](const char *Name) {
383-
CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(Name)));
382+
auto AddCRTObject = [&](StringRef Name) {
383+
// CRT objects can be found on user supplied library paths. This is
384+
// an entrenched expectation on PlayStation.
385+
CmdArgs.push_back(Args.MakeArgString("-l:" + Name));
384386
};
385387

386388
if (AddStartFiles) {

clang/test/Driver/ps5-linker.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@
146146
// RUN: %clang --target=x86_64-sie-ps5 %s -nostdlib++ -static -### 2>&1 | FileCheck --check-prefixes=CHECK-LD,CHECK-STATIC-CRT,CHECK-NO-LIBCPP,CHECK-STATIC-LIBC,CHECK-STATIC-CORE-LIBS %s
147147

148148
// CHECK-LD: {{ld(\.exe)?}}"
149-
// CHECK-MAIN-CRT-SAME: "crt1.o" "crti.o" "crtbegin.o"
150-
// CHECK-SHARED-CRT-SAME: "crti.o" "crtbeginS.o"
151-
// CHECK-STATIC-CRT-SAME: "crt1.o" "crti.o" "crtbeginT.o"
149+
// CHECK-MAIN-CRT-SAME: "-l:crt1.o" "-l:crti.o" "-l:crtbegin.o"
150+
// CHECK-SHARED-CRT-SAME: "-l:crti.o" "-l:crtbeginS.o"
151+
// CHECK-STATIC-CRT-SAME: "-l:crt1.o" "-l:crti.o" "-l:crtbeginT.o"
152152

153153
// CHECK-NO-LIBC-NOT: "-lc{{(_stub_weak)?}}"
154154
// CHECK-NO-LIBCPP-NOT: "-l{{c_stub_weak|stdc\+\+}}"
@@ -161,11 +161,11 @@
161161

162162
// CHECK-PTHREAD-SAME: "-lpthread"
163163

164-
// CHECK-MAIN-CRT-SAME: "crtend.o" "crtn.o"
165-
// CHECK-SHARED-CRT-SAME: "crtendS.o" "crtn.o"
166-
// CHECK-STATIC-CRT-SAME: "crtend.o" "crtn.o"
164+
// CHECK-MAIN-CRT-SAME: "-l:crtend.o" "-l:crtn.o"
165+
// CHECK-SHARED-CRT-SAME: "-l:crtendS.o" "-l:crtn.o"
166+
// CHECK-STATIC-CRT-SAME: "-l:crtend.o" "-l:crtn.o"
167167

168-
// CHECK-NO-CRT-NOT: "crt{{[^"]*}}.o"
168+
// CHECK-NO-CRT-NOT: crt{{[^"]*}}.o"
169169
// CHECK-NO-LIBS-NOT: "-l{{[^"]*}}"
170170

171171
// Test the driver's control over the -fcrash-diagnostics-dir behavior with linker flags.
@@ -186,9 +186,9 @@
186186

187187
// Test implicit library search paths are supplied to the linker, after any
188188
// search paths specified by the user. <sdk-root>/target/lib is implicitly
189-
// added if it exists. CRT objects are found there. "." is always implicitly
190-
// added to library search paths. This is long-standing behavior, unique to
191-
// PlayStation toolchains.
189+
// added if it exists. CRT objects are found there if not on user search paths.
190+
// "." is always implicitly added to library search paths. These are
191+
// long-standing and entrenched behaviors, unique to PlayStation toolchains.
192192

193193
// RUN: rm -rf %t.dir && mkdir %t.dir
194194
// RUN: env SCE_PROSPERO_SDK_DIR=%t.dir %clang --target=x64_64-sie-ps5 %s -### -Luser 2>&1 | FileCheck --check-prefixes=CHECK-NO-TARGETLIB %s
@@ -200,12 +200,10 @@
200200
// CHECK-NO-TARGETLIB-SAME: "-L."
201201

202202
// RUN: mkdir -p %t.dir/myroot/target/lib
203-
// RUN: touch %t.dir/myroot/target/lib/crti.o
204203
// RUN: env SCE_PROSPERO_SDK_DIR=%t.dir/myroot %clang --target=x64_64-sie-ps5 %s -### -Luser 2>&1 | FileCheck --check-prefixes=CHECK-TARGETLIB %s
205204
// RUN: %clang --target=x64_64-sie-ps5 %s -### -Luser --sysroot=%t.dir/myroot 2>&1 | FileCheck --check-prefixes=CHECK-TARGETLIB %s
206205

207206
// CHECK-TARGETLIB: {{ld(\.exe)?}}"
208207
// CHECK-TARGETLIB-SAME: "-Luser"
209208
// CHECK-TARGETLIB-SAME: "-L{{.*}}myroot{{/|\\\\}}target{{/|\\\\}}lib"
210209
// CHECK-TARGETLIB-SAME: "-L."
211-
// CHECK-TARGETLIB-SAME: "{{.*}}myroot{{/|\\\\}}target{{/|\\\\}}lib{{/|\\\\}}crti.o"

0 commit comments

Comments
 (0)