[PATCH] D13870: [ELF2] - Linker script EXTERN implemented.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 19 07:51:02 PDT 2015


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.

The reason of collecting all undefines in vector is that during reading files we already need to have Symtab created. Or like was done in that patch - to put undefines from scripts somewhere to delay Symtab.addUndefinedOpt() call.

Actually the main problem I see here is that currently ELF type is taken from first file. If we could know it earlier (I am not sure, from command line may be ?) then we would not need such solutions.

http://reviews.llvm.org/D13870

Files:
  ELF/Config.h
  ELF/Driver.cpp
  ELF/LinkerScript.cpp
  test/elf2/linkerscript.s

Index: test/elf2/linkerscript.s
===================================================================
--- test/elf2/linkerscript.s
+++ test/elf2/linkerscript.s
@@ -6,6 +6,10 @@
 # RUN: rm -f %t.dir/libxyz.a
 # RUN: llvm-ar rcs %t.dir/libxyz.a %t2.o
 
+# RUN: echo "EXTERN( undef undef2 )" > %t.script
+# RUN: ld.lld2 %t -o %t2 %t.script
+# RUN: llvm-readobj %t2 > /dev/null
+
 # RUN: echo "GROUP(" %t ")" > %t.script
 # RUN: ld.lld2 -o %t2 %t.script
 # RUN: llvm-readobj %t2 > /dev/null
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -43,6 +43,7 @@
 
   void readAsNeeded();
   void readEntry();
+  void readExtern();
   void readGroup();
   void readInclude();
   void readOutput();
@@ -63,6 +64,8 @@
       continue;
     if (Tok == "ENTRY") {
       readEntry();
+    } else if (Tok == "EXTERN") {
+      readExtern();
     } else if (Tok == "GROUP" || Tok == "INPUT") {
       readGroup();
     } else if (Tok == "INCLUDE") {
@@ -181,6 +184,16 @@
   expect(")");
 }
 
+void LinkerScript::readExtern() {
+  expect("(");
+  for (;;) {
+    StringRef Tok = next();
+    if (Tok == ")")
+      return;
+    Config->Undefined.push_back(Tok);
+  }
+}
+
 void LinkerScript::readGroup() {
   expect("(");
   for (;;) {
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -189,6 +189,9 @@
     }
   }
 
+  for (auto *Arg : Args.filtered(OPT_undefined))
+    Config->Undefined.push_back(Arg->getValue());
+
   if (Files.empty())
     error("no input files.");
 }
@@ -225,8 +228,8 @@
   for (std::unique_ptr<InputFile> &F : Files)
     Symtab.addFile(std::move(F));
 
-  for (auto *Arg : Args.filtered(OPT_undefined))
-    Symtab.addUndefinedOpt(Arg->getValue());
+  for (auto &U : Config->Undefined)
+    Symtab.addUndefinedOpt(U);
 
   if (Config->OutputFile.empty())
     Config->OutputFile = "a.out";
Index: ELF/Config.h
===================================================================
--- ELF/Config.h
+++ ELF/Config.h
@@ -42,6 +42,7 @@
   llvm::StringRef Sysroot;
   std::string RPath;
   std::vector<llvm::StringRef> SearchPaths;
+  std::vector<llvm::StringRef> Undefined;
   bool AllowMultipleDefinition;
   bool AsNeeded = false;
   bool Bsymbolic;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13870.37755.patch
Type: text/x-patch
Size: 2333 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151019/1752ee91/attachment.bin>


More information about the llvm-commits mailing list