[lld] 2508733 - [ELF] --sysroot: change sysrooted script to not fall back for an absolute path
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 25 12:52:44 PDT 2021
Author: Fangrui Song
Date: 2021-06-25T12:52:39-07:00
New Revision: 2508733e1be28da8c53d36c109007b778225ec7a
URL: https://github.com/llvm/llvm-project/commit/2508733e1be28da8c53d36c109007b778225ec7a
DIFF: https://github.com/llvm/llvm-project/commit/2508733e1be28da8c53d36c109007b778225ec7a.diff
LOG: [ELF] --sysroot: change sysrooted script to not fall back for an absolute path
Modify the 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.
Reviewed By: ikudrin
Differential Revision: https://reviews.llvm.org/D104894
Added:
Modified:
lld/ELF/ScriptParser.cpp
lld/test/ELF/linkerscript/group.s
Removed:
################################################################################
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index 8937bdfe357f9..3d0d720014f25 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -288,10 +288,11 @@ void ScriptParser::addFile(StringRef s) {
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("/")) {
diff --git a/lld/test/ELF/linkerscript/group.s b/lld/test/ELF/linkerscript/group.s
index 54adbdf8eefc6..14d39559de71e 100644
--- a/lld/test/ELF/linkerscript/group.s
+++ b/lld/test/ELF/linkerscript/group.s
@@ -1,4 +1,5 @@
# REQUIRES: x86
+# UNSUPPORTED: system-windows
# RUN: mkdir -p %t.dir
# RUN: rm -f %t.dir/libxyz.a
@@ -37,10 +38,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 +57,8 @@
# RUN: ld.lld -o %t2 %t.script
# RUN: llvm-readobj %t2 > /dev/null
+# CANNOT_OPEN: error: cannot open [[FILE]]: {{.*}}
+
.globl _start
_start:
ret
More information about the llvm-commits
mailing list