[ELF] - Linkerscript: Fall back to search paths when INCLUDE not found
From https://sourceware.org/binutils/docs/ld/File-Commands.html:
The file will be searched for in the current directory, and in any
directory specified with the -L option.
Patch done by Alexander Richardson.
Differential revision: https://reviews.llvm.org/D27831
llvm-svn: 290247
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 7e2aecc..e4b1e55 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -1171,8 +1171,14 @@
}
void ScriptParser::readInclude() {
- StringRef Tok = next();
- auto MBOrErr = MemoryBuffer::getFile(unquote(Tok));
+ StringRef Tok = unquote(next());
+ // https://sourceware.org/binutils/docs/ld/File-Commands.html:
+ // The file will be searched for in the current directory, and in any
+ // directory specified with the -L option.
+ auto MBOrErr = MemoryBuffer::getFile(Tok);
+ if (!MBOrErr)
+ if (Optional<std::string> Path = findFromSearchPaths(Tok))
+ MBOrErr = MemoryBuffer::getFile(*Path);
if (!MBOrErr) {
setError("cannot open " + Tok);
return;