[lld] r337969 - [ELF] Use search paths for --version-script=
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 25 14:53:18 PDT 2018
Author: maskray
Date: Wed Jul 25 14:53:18 2018
New Revision: 337969
URL: http://llvm.org/viewvc/llvm-project?rev=337969&view=rev
Log:
[ELF] Use search paths for --version-script=
Summary: This behavior matches ld.bfd -Ld --version-script=t.script a.o
Reviewers: ruiu, espindola
Subscribers: emaste, arichardson, llvm-commits
Differential Revision: https://reviews.llvm.org/D49820
Added:
lld/trunk/test/ELF/version-script-in-search-path.s
Modified:
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/Driver.h
lld/trunk/ELF/DriverUtils.cpp
lld/trunk/ELF/ScriptParser.cpp
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=337969&r1=337968&r2=337969&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed Jul 25 14:53:18 2018
@@ -939,8 +939,12 @@ void LinkerDriver::readConfigs(opt::Inpu
Config->Undefined.push_back(Arg->getValue());
for (auto *Arg : Args.filtered(OPT_version_script))
- if (Optional<MemoryBufferRef> Buffer = readFile(Arg->getValue()))
- readVersionScript(*Buffer);
+ if (Optional<std::string> Path = searchScript(Arg->getValue())) {
+ if (Optional<MemoryBufferRef> Buffer = readFile(*Path))
+ readVersionScript(*Buffer);
+ } else {
+ error(Twine("cannot find version script ") + Arg->getValue());
+ }
}
// Some Config members do not directly correspond to any particular
@@ -1022,7 +1026,7 @@ void LinkerDriver::createFiles(opt::Inpu
break;
}
case OPT_script:
- if (Optional<std::string> Path = searchLinkerScript(Arg->getValue())) {
+ if (Optional<std::string> Path = searchScript(Arg->getValue())) {
if (Optional<MemoryBufferRef> MB = readFile(*Path))
readLinkerScript(*MB);
break;
Modified: lld/trunk/ELF/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.h?rev=337969&r1=337968&r2=337969&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.h (original)
+++ lld/trunk/ELF/Driver.h Wed Jul 25 14:53:18 2018
@@ -67,7 +67,7 @@ void printHelp();
std::string createResponseFile(const llvm::opt::InputArgList &Args);
llvm::Optional<std::string> findFromSearchPaths(StringRef Path);
-llvm::Optional<std::string> searchLinkerScript(StringRef Path);
+llvm::Optional<std::string> searchScript(StringRef Path);
llvm::Optional<std::string> searchLibrary(StringRef Path);
} // namespace elf
Modified: lld/trunk/ELF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DriverUtils.cpp?rev=337969&r1=337968&r2=337969&view=diff
==============================================================================
--- lld/trunk/ELF/DriverUtils.cpp (original)
+++ lld/trunk/ELF/DriverUtils.cpp Wed Jul 25 14:53:18 2018
@@ -227,10 +227,10 @@ Optional<std::string> elf::searchLibrary
return None;
}
-// If a linker script doesn't exist in the current directory, we also look for
-// the script in the '-L' search paths. This matches the behaviour of both '-T'
-// and linker script INPUT() directives in ld.bfd.
-Optional<std::string> elf::searchLinkerScript(StringRef Name) {
+// If a linker/version script doesn't exist in the current directory, we also
+// look for the script in the '-L' search paths. This matches the behaviour of
+// '-T', --version-script=, and linker script INPUT() command in ld.bfd.
+Optional<std::string> elf::searchScript(StringRef Name) {
if (fs::exists(Name))
return Name.str();
return findFromSearchPaths(Name);
Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=337969&r1=337968&r2=337969&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Wed Jul 25 14:53:18 2018
@@ -344,7 +344,7 @@ void ScriptParser::readInclude() {
return;
}
- if (Optional<std::string> Path = searchLinkerScript(Tok)) {
+ if (Optional<std::string> Path = searchScript(Tok)) {
if (Optional<MemoryBufferRef> MB = readFile(*Path))
tokenize(*MB);
return;
Added: lld/trunk/test/ELF/version-script-in-search-path.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/version-script-in-search-path.s?rev=337969&view=auto
==============================================================================
--- lld/trunk/test/ELF/version-script-in-search-path.s (added)
+++ lld/trunk/test/ELF/version-script-in-search-path.s Wed Jul 25 14:53:18 2018
@@ -0,0 +1,10 @@
+# REQUIRES: x86
+# Check that we fall back to search paths if a version script was not found
+# This behaviour matches ld.bfd.
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: mkdir -p %T/searchpath
+# RUN: echo '{};' > %T/searchpath/t.script
+# RUN: ld.lld -L%T/searchpath --version-script=t.script %t.o -o /dev/null
+# RUN: not ld.lld --version-script=t.script %t.o 2>&1 | FileCheck -check-prefix ERROR %s
+# ERROR: error: cannot find version script
More information about the llvm-commits
mailing list