[PATCH] D27831: [ELF] - Linkerscript: Fall back to search paths when INCLUDE not found

Alexander Richardson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 16 05:59:01 PST 2016


arichardson updated this revision to Diff 81747.
arichardson marked 2 inline comments as done.
arichardson added a comment.

added test case


https://reviews.llvm.org/D27831

Files:
  ELF/LinkerScript.cpp
  test/ELF/linkerscript/linkerscript.s


Index: test/ELF/linkerscript/linkerscript.s
===================================================================
--- test/ELF/linkerscript/linkerscript.s
+++ test/ELF/linkerscript/linkerscript.s
@@ -33,6 +33,15 @@
 # RUN: ld.lld %t.script1
 # RUN: llvm-readobj %t2 > /dev/null
 
+# RUN: echo "INCLUDE \"foo.script\"" > %t.script
+# RUN: echo "OUTPUT(\"%t.out\")" > %T/foo.script
+# RUN: not ld.lld %t.script > %t.log 2>&1
+# RUN: FileCheck -check-prefix=INCLUDE_ERR %s < %t.log
+# INCLUDE_ERR: error: {{.+}}.script:1: cannot open foo.script
+# INCLUDE_ERR-NEXT: error: {{.+}}.script:1: INCLUDE "foo.script"
+# RUN: ld.lld -L %T %t.script %t
+# RUN: llvm-readobj %t.out > /dev/null
+
 # RUN: echo "FOO(BAR)" > %t.script
 # RUN: not ld.lld -o foo %t.script > %t.log 2>&1
 # RUN: FileCheck -check-prefix=ERR1 %s < %t.log
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -1184,8 +1184,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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27831.81747.patch
Type: text/x-patch
Size: 1573 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161216/b1e5bdc8/attachment.bin>


More information about the llvm-commits mailing list