[PATCH] D14916: ELF2: LinkerScript: lookup absolute paths under sysroot

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 24 14:19:14 PST 2015


This revision was automatically updated to reflect the committed changes.
Closed by commit rL254031: ELF2: LinkerScript: lookup absolute paths under sysroot (authored by atanasyan).

Changed prior to commit:
  http://reviews.llvm.org/D14916?vs=41008&id=41087#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D14916

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

Index: lld/trunk/test/ELF/linkerscript.s
===================================================================
--- lld/trunk/test/ELF/linkerscript.s
+++ lld/trunk/test/ELF/linkerscript.s
@@ -38,6 +38,13 @@
 # RUN: ld.lld -o %t2 %t.script -L%t.dir
 # RUN: llvm-readobj %t2 > /dev/null
 
+# RUN: echo "GROUP(" %t /libxyz.a ")" > %t.script
+# RUN: echo "GROUP(" %t /libxyz.a ")" > %t.dir/xyz.script
+# RUN: not ld.lld -o %t2 %t.script
+# RUN: not ld.lld -o %t2 %t.script --sysroot=%t.dir
+# RUN: ld.lld -o %t2 %t.dir/xyz.script --sysroot=%t.dir
+# RUN: llvm-readobj %t2 > /dev/null
+
 # RUN: echo "GROUP(" %t.script2 ")" > %t.script1
 # RUN: echo "GROUP(" %t ")" > %t.script2
 # RUN: ld.lld -o %t2 %t.script1
Index: lld/trunk/ELF/LinkerScript.cpp
===================================================================
--- lld/trunk/ELF/LinkerScript.cpp
+++ lld/trunk/ELF/LinkerScript.cpp
@@ -28,8 +28,8 @@
 namespace {
 class LinkerScript {
 public:
-  LinkerScript(BumpPtrAllocator *A, StringRef S)
-      : Saver(*A), Tokens(tokenize(S)) {}
+  LinkerScript(BumpPtrAllocator *A, StringRef S, bool B)
+      : Saver(*A), Tokens(tokenize(S)), IsUnderSysroot(B) {}
   void run();
 
 private:
@@ -58,6 +58,7 @@
   StringSaver Saver;
   std::vector<StringRef> Tokens;
   size_t Pos = 0;
+  bool IsUnderSysroot;
 };
 }
 
@@ -161,6 +162,12 @@
 
 void LinkerScript::addFile(StringRef S) {
   if (sys::path::is_absolute(S)) {
+    if (IsUnderSysroot) {
+      SmallString<128> Path;
+      (Config->Sysroot + S).toStringRef(Path);
+      if (sys::fs::exists(Path))
+        S = Saver.save(Path.str());
+    }
     Driver->addFile(S);
   } else if (S.startswith("=")) {
     if (Config->Sysroot.empty())
@@ -292,5 +299,12 @@
 
 // Entry point. The other functions or classes are private to this file.
 void lld::elf2::readLinkerScript(BumpPtrAllocator *A, MemoryBufferRef MB) {
-  LinkerScript(A, MB.getBuffer()).run();
+  StringRef Path = MB.getBufferIdentifier();
+  if (!Config->Sysroot.empty())
+    for (; !Path.empty(); Path = sys::path::parent_path(Path))
+      if (sys::fs::equivalent(Config->Sysroot, Path)) {
+        LinkerScript(A, MB.getBuffer(), true).run();
+        return;
+      }
+  LinkerScript(A, MB.getBuffer(), false).run();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14916.41087.patch
Type: text/x-patch
Size: 2235 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151124/213e5b85/attachment.bin>


More information about the llvm-commits mailing list