Index: lld/trunk/ELF/Driver.h =================================================================== --- lld/trunk/ELF/Driver.h +++ lld/trunk/ELF/Driver.h @@ -67,7 +67,7 @@ std::string createResponseFile(const llvm::opt::InputArgList &Args); llvm::Optional findFromSearchPaths(StringRef Path); -llvm::Optional searchLinkerScript(StringRef Path); +llvm::Optional searchScript(StringRef Path); llvm::Optional searchLibrary(StringRef Path); } // namespace elf Index: lld/trunk/ELF/Driver.cpp =================================================================== --- lld/trunk/ELF/Driver.cpp +++ lld/trunk/ELF/Driver.cpp @@ -939,8 +939,12 @@ Config->Undefined.push_back(Arg->getValue()); for (auto *Arg : Args.filtered(OPT_version_script)) - if (Optional Buffer = readFile(Arg->getValue())) - readVersionScript(*Buffer); + if (Optional Path = searchScript(Arg->getValue())) { + if (Optional 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 @@ break; } case OPT_script: - if (Optional Path = searchLinkerScript(Arg->getValue())) { + if (Optional Path = searchScript(Arg->getValue())) { if (Optional MB = readFile(*Path)) readLinkerScript(*MB); break; Index: lld/trunk/ELF/DriverUtils.cpp =================================================================== --- lld/trunk/ELF/DriverUtils.cpp +++ lld/trunk/ELF/DriverUtils.cpp @@ -227,10 +227,10 @@ 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 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 elf::searchScript(StringRef Name) { if (fs::exists(Name)) return Name.str(); return findFromSearchPaths(Name); Index: lld/trunk/ELF/ScriptParser.cpp =================================================================== --- lld/trunk/ELF/ScriptParser.cpp +++ lld/trunk/ELF/ScriptParser.cpp @@ -344,7 +344,7 @@ return; } - if (Optional Path = searchLinkerScript(Tok)) { + if (Optional Path = searchScript(Tok)) { if (Optional MB = readFile(*Path)) tokenize(*MB); return; Index: lld/trunk/test/ELF/version-script-in-search-path.s =================================================================== --- lld/trunk/test/ELF/version-script-in-search-path.s +++ lld/trunk/test/ELF/version-script-in-search-path.s @@ -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