[PATCH] D30224: [ELF] Insert linkerscript symbols directly into symbol table
    Petr Hosek via Phabricator via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Tue Feb 21 13:58:35 PST 2017
    
    
  
phosek created this revision.
phosek added a project: lld.
This change exposes the symbol table insert method and uses it to  insert the linkerscript defined symbols directly into the symbol table to avoid unnecessarily pulling the object out of an archive.
This change addresses PR32026.
Repository:
  rL LLVM
https://reviews.llvm.org/D30224
Files:
  ELF/LinkerScript.cpp
  ELF/SymbolTable.h
  test/ELF/linkerscript/Inputs/lazy-symbols.s
  test/ELF/linkerscript/lazy-symbols.s
Index: test/ELF/linkerscript/lazy-symbols.s
===================================================================
--- /dev/null
+++ test/ELF/linkerscript/lazy-symbols.s
@@ -0,0 +1,10 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/lazy-symbols.s -o %t1
+# RUN: llvm-ar rcs %tar %t1
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2
+# RUN: echo "foo = 1;" > %t.script
+# RUN: ld.lld %t2 %tar --script %t.script -o %tout
+# RUN: llvm-readobj -symbols %tout | FileCheck %s
+
+# CHECK: Name: foo
+# CHECK-NEXT: Value: 0x1
Index: test/ELF/linkerscript/Inputs/lazy-symbols.s
===================================================================
--- /dev/null
+++ test/ELF/linkerscript/Inputs/lazy-symbols.s
@@ -0,0 +1,7 @@
+.globl foo
+foo:
+ .long .Linfo_string
+
+.section .debug_str,"MS", at progbits,1
+.Linfo_string:
+  .asciz "foo"
Index: ELF/SymbolTable.h
===================================================================
--- ELF/SymbolTable.h
+++ ELF/SymbolTable.h
@@ -77,6 +77,11 @@
                     uint8_t Binding, uint8_t StOther, uint8_t Type,
                     InputFile *File);
 
+  std::pair<Symbol *, bool> insert(StringRef Name);
+  std::pair<Symbol *, bool> insert(StringRef Name, uint8_t Type,
+                                   uint8_t Visibility, bool CanOmitFromDynSym,
+                                   InputFile *File);
+
   void scanUndefinedFlags();
   void scanShlibUndefined();
   void scanVersionScript();
@@ -90,11 +95,6 @@
   std::vector<InputSectionBase<ELFT> *> Sections;
 
 private:
-  std::pair<Symbol *, bool> insert(StringRef Name);
-  std::pair<Symbol *, bool> insert(StringRef Name, uint8_t Type,
-                                   uint8_t Visibility, bool CanOmitFromDynSym,
-                                   InputFile *File);
-
   std::vector<SymbolBody *> findByVersion(SymbolVersion Ver);
   std::vector<SymbolBody *> findAllByVersion(SymbolVersion Ver);
 
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -57,27 +57,27 @@
 ScriptConfiguration *elf::ScriptConfig;
 
 template <class ELFT> static SymbolBody *addRegular(SymbolAssignment *Cmd) {
+  Symbol *Sym;
   uint8_t Visibility = Cmd->Hidden ? STV_HIDDEN : STV_DEFAULT;
-  Symbol *Sym = Symtab<ELFT>::X->addUndefined(
-      Cmd->Name, /*IsLocal=*/false, STB_GLOBAL, Visibility,
-      /*Type*/ 0,
-      /*CanOmitFromDynSym*/ false, /*File*/ nullptr);
-
+  std::tie(Sym, std::ignore) = Symtab<ELFT>::X->insert(
+      Cmd->Name, /*Type*/ 0, Visibility, /*CanOmitFromDynSym*/ false,
+      /*File*/ nullptr);
+  Sym->Binding = STB_GLOBAL;
   replaceBody<DefinedRegular<ELFT>>(Sym, Cmd->Name, /*IsLocal=*/false,
                                     Visibility, STT_NOTYPE, 0, 0, nullptr,
                                     nullptr);
   return Sym->body();
 }
 
 template <class ELFT> static SymbolBody *addSynthetic(SymbolAssignment *Cmd) {
+  Symbol *Sym;
   uint8_t Visibility = Cmd->Hidden ? STV_HIDDEN : STV_DEFAULT;
   const OutputSectionBase *Sec =
       ScriptConfig->HasSections ? nullptr : Cmd->Expression.Section();
-  Symbol *Sym = Symtab<ELFT>::X->addUndefined(
-      Cmd->Name, /*IsLocal=*/false, STB_GLOBAL, Visibility,
-      /*Type*/ 0,
-      /*CanOmitFromDynSym*/ false, /*File*/ nullptr);
-
+  std::tie(Sym, std::ignore) = Symtab<ELFT>::X->insert(
+      Cmd->Name, /*Type*/ 0, Visibility, /*CanOmitFromDynSym*/ false,
+      /*File*/ nullptr);
+  Sym->Binding = STB_GLOBAL;
   replaceBody<DefinedSynthetic>(Sym, Cmd->Name, 0, Sec);
   return Sym->body();
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30224.89275.patch
Type: text/x-patch
Size: 3642 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170221/bc3f40c3/attachment.bin>
    
    
More information about the llvm-commits
mailing list