[PATCH] D104894: [ELF] --sysroot: change sysrooted file to not find an outside-sysroot file
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 24 19:27:52 PDT 2021
MaskRay created this revision.
MaskRay added reviewers: grimar, ikudrin, peter.smith.
Herald added subscribers: arichardson, emaste.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Modify the D13209 <https://reviews.llvm.org/D13209> logic: for a script inside the sysroot, if an absolute path
does not exist, report an error instead of falling back to the path without the
sysroot prefix.
This matches GNU ld, which makes sense to me: we don't want to find an arbitrary
file in the host.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D104894
Files:
lld/ELF/ScriptParser.cpp
lld/test/ELF/linkerscript/group.s
Index: lld/test/ELF/linkerscript/group.s
===================================================================
--- lld/test/ELF/linkerscript/group.s
+++ lld/test/ELF/linkerscript/group.s
@@ -37,10 +37,15 @@
# RUN: echo "GROUP(\"%t\" /libxyz.a )" > %t.script
# RUN: echo "GROUP(\"%t\" /libxyz.a )" > %t.dir/xyz.script
-# RUN: not ld.lld -o /dev/null %t.script 2>/dev/null
-# RUN: not ld.lld -o /dev/null %t.script --sysroot=%t.dir 2>/dev/null
-# RUN: ld.lld -o %t2 %t.dir/xyz.script --sysroot=%t.dir
-# RUN: llvm-readobj %t2 > /dev/null
+# RUN: not ld.lld -o /dev/null %t.script 2>&1 | FileCheck %s --check-prefix=CANNOT_OPEN -DFILE=/libxyz.a
+# RUN: not ld.lld -o /dev/null %t.script --sysroot=%t.dir 2>&1 | FileCheck %s --check-prefix=CANNOT_OPEN -DFILE=/libxyz.a
+
+## Since %t.dir/%t does not exist, report an error, instead of falling back to %t
+## without the syroot prefix.
+# RUN: not ld.lld -o /dev/null %t.dir/xyz.script --sysroot=%t.dir 2>&1 | FileCheck %s --check-prefix=CANNOT_FIND_SYSROOT -DTMP=%t
+
+# CANNOT_FIND_SYSROOT: error: {{.*}}xyz.script:1: cannot find [[TMP]] inside [[TMP]].dir
+# CANNOT_FIND_SYSROOT-NEXT: >>> GROUP({{.*}}
# RUN: echo "GROUP(\"%t.script2\")" > %t.script1
# RUN: echo "GROUP(\"%t\")" > %t.script2
@@ -51,6 +56,8 @@
# RUN: ld.lld -o %t2 %t.script
# RUN: llvm-readobj %t2 > /dev/null
+# CANNOT_OPEN: error: cannot open [[FILE]]: {{.*}}
+
.globl _start
_start:
ret
Index: lld/ELF/ScriptParser.cpp
===================================================================
--- lld/ELF/ScriptParser.cpp
+++ lld/ELF/ScriptParser.cpp
@@ -288,10 +288,11 @@
if (isUnderSysroot && s.startswith("/")) {
SmallString<128> pathData;
StringRef path = (config->sysroot + s).toStringRef(pathData);
- if (sys::fs::exists(path)) {
+ if (sys::fs::exists(path))
driver->addFile(saver.save(path), /*withLOption=*/false);
- return;
- }
+ else
+ setError("cannot find " + s + " inside " + config->sysroot);
+ return;
}
if (s.startswith("/")) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104894.354421.patch
Type: text/x-patch
Size: 2030 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210625/9059b028/attachment-0001.bin>
More information about the llvm-commits
mailing list