[lld] r265826 - Cleanup the handling of MustBeInDynSym and IsUsedInRegularObj.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 8 11:39:03 PDT 2016


Author: rafael
Date: Fri Apr  8 13:39:03 2016
New Revision: 265826

URL: http://llvm.org/viewvc/llvm-project?rev=265826&view=rev
Log:
Cleanup the handling of MustBeInDynSym and IsUsedInRegularObj.

Now MustBeInDynSym is only true if the symbol really must be in the
dynamic symbol table.

IsUsedInRegularObj is only true if the symbol is used in a .o or -u. Not
a .so or a .bc.

A benefit is that this is now done almost entirilly during symbol
resolution. The only exception is copy relocations because of aliases.

This includes a small fix in that protected symbols in .so don't force
executable symbols to be exported.

This also opens the way for implementing internalize for -shared.

Modified:
    lld/trunk/ELF/LTO.cpp
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/SymbolTable.cpp
    lld/trunk/ELF/Symbols.cpp
    lld/trunk/ELF/Writer.cpp
    lld/trunk/test/ELF/mips-dynamic.s
    lld/trunk/test/ELF/protected-shared.s

Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=265826&r1=265825&r2=265826&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Fri Apr  8 13:39:03 2016
@@ -116,7 +116,8 @@ void BitcodeCompiler::add(BitcodeFile &F
     // Shared libraries need to be handled slightly differently.
     // For now, let's be conservative and just never internalize
     // symbols when creating a shared library.
-    if (!Config->Shared && !Config->ExportDynamic && !B->isUsedInRegularObj())
+    if (!Config->Shared && !Config->ExportDynamic && !B->isUsedInRegularObj() &&
+        !B->MustBeInDynSym)
       if (!Used.count(GV))
         InternalizedSyms.insert(GV->getName());
 

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=265826&r1=265825&r2=265826&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Fri Apr  8 13:39:03 2016
@@ -138,9 +138,6 @@ template <class ELFT> void GotSection<EL
       ++MipsLocalEntries;
       return;
     }
-    // All preemptible symbols with MIPS GOT entries should be represented
-    // in the dynamic symbols table.
-    Sym.MustBeInDynSym = true;
   }
   Sym.GotIndex = Entries.size();
   Entries.push_back(&Sym);
@@ -299,9 +296,6 @@ RelocationSection<ELFT>::RelocationSecti
 
 template <class ELFT>
 void RelocationSection<ELFT>::addReloc(const DynamicReloc<ELFT> &Reloc) {
-  SymbolBody *Sym = Reloc.Sym;
-  if (!Reloc.UseSymVA && Sym)
-    Sym->MustBeInDynSym = true;
   Relocs.push_back(Reloc);
 }
 

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=265826&r1=265825&r2=265826&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Fri Apr  8 13:39:03 2016
@@ -119,10 +119,12 @@ template <class ELFT> void SymbolTable<E
   for (SymbolBody *Body : Obj->getNonLocalSymbols()) {
     Symbol *Sym = insert(Body);
     Sym->Body->setUsedInRegularObj();
-    if (!Sym->Body->isUndefined() && Body->isUndefined())
-      continue;
+    if (Sym->Body->isShared())
+      Sym->Body->MustBeInDynSym = true;
     if (Sym->Body->MustBeInDynSym)
       Body->MustBeInDynSym = true;
+    if (!Sym->Body->isUndefined() && Body->isUndefined())
+      continue;
     Sym->Body = Body;
   }
   ObjectFiles.emplace_back(Obj);

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=265826&r1=265825&r2=265826&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Fri Apr  8 13:39:03 2016
@@ -218,6 +218,18 @@ int SymbolBody::compare(SymbolBody *Othe
   if (L > R)
     return -Other->compare(this);
 
+  if (isShared() != Other->isShared()) {
+    SymbolBody *Shared = isShared() ? this : Other;
+    Shared->MustBeInDynSym = true;
+    if (Shared->getVisibility() == STV_DEFAULT) {
+      // We want to export all symbols that exist in the executable and are
+      // preemptable in DSOs, so that the symbols in the executable can
+      // preempt symbols in the DSO at runtime.
+      SymbolBody *NonShared = isShared() ? Other : this;
+      NonShared->MustBeInDynSym = true;
+    }
+  }
+
   if (!isShared() && !Other->isShared()) {
     uint8_t V = getMinVisibility(getVisibility(), Other->getVisibility());
     setVisibility(V);
@@ -227,15 +239,6 @@ int SymbolBody::compare(SymbolBody *Othe
   if (IsUsedInRegularObj || Other->IsUsedInRegularObj)
     IsUsedInRegularObj = Other->IsUsedInRegularObj = true;
 
-  // We want to export all symbols that exist both in the executable
-  // and in DSOs, so that the symbols in the executable can interrupt
-  // symbols in the DSO at runtime.
-  if (isShared() != Other->isShared())
-    if (isa<Defined>(isShared() ? Other : this)) {
-      IsUsedInRegularObj = Other->IsUsedInRegularObj = true;
-      MustBeInDynSym = Other->MustBeInDynSym = true;
-    }
-
   if (L != R)
     return -1;
   if (!isDefined() || isShared() || isWeak())

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=265826&r1=265825&r2=265826&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Apr  8 13:39:03 2016
@@ -826,12 +826,14 @@ template <class ELFT> static bool includ
 }
 
 static bool includeInDynsym(const SymbolBody &B) {
+  if (B.MustBeInDynSym)
+    return true;
   uint8_t V = B.getVisibility();
   if (V != STV_DEFAULT && V != STV_PROTECTED)
     return false;
   if (Config->ExportDynamic || Config->Shared)
     return true;
-  return B.MustBeInDynSym;
+  return false;
 }
 
 // This class knows how to create an output section for a given

Modified: lld/trunk/test/ELF/mips-dynamic.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-dynamic.s?rev=265826&r1=265825&r2=265826&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-dynamic.s (original)
+++ lld/trunk/test/ELF/mips-dynamic.s Fri Apr  8 13:39:03 2016
@@ -47,8 +47,8 @@
 # EXE-DAG:    0x70000005 MIPS_FLAGS           NOTPOT
 # EXE-DAG:    0x70000006 MIPS_BASE_ADDRESS
 # EXE-DAG:    0x7000000A MIPS_LOCAL_GOTNO     2
-# EXE-DAG:    0x70000011 MIPS_SYMTABNO        2
-# EXE-DAG:    0x70000013 MIPS_GOTSYM          0x2
+# EXE-DAG:    0x70000011 MIPS_SYMTABNO        3
+# EXE-DAG:    0x70000013 MIPS_GOTSYM          0x3
 # EXE-DAG:    0x70000016 MIPS_RLD_MAP         [[RLDMAPADDR]]
 # EXE:      ]
 

Modified: lld/trunk/test/ELF/protected-shared.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/protected-shared.s?rev=265826&r1=265825&r2=265826&view=diff
==============================================================================
--- lld/trunk/test/ELF/protected-shared.s (original)
+++ lld/trunk/test/ELF/protected-shared.s Fri Apr  8 13:39:03 2016
@@ -3,7 +3,7 @@
 // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/protected-shared.s -o %t2.o
 // RUN: ld.lld -shared %t2.o -o %t2.so
 // RUN: ld.lld %t.o %t2.so -o %t
-// RUN: llvm-readobj -t %t | FileCheck %s
+// RUN: llvm-readobj -t --dyn-symbols %t | FileCheck %s
 
         .global  _start
 _start:
@@ -27,3 +27,24 @@ bar:
 // CHECK-NEXT: Type: None
 // CHECK-NEXT: Other: 0
 // CHECK-NEXT: Section: Undefined
+
+// CHECK:      DynamicSymbols [
+// CHECK-NEXT:   Symbol {
+// CHECK-NEXT:     Name: @
+// CHECK-NEXT:     Value: 0x0
+// CHECK-NEXT:     Size: 0
+// CHECK-NEXT:     Binding: Local (0x0)
+// CHECK-NEXT:     Type: None (0x0)
+// CHECK-NEXT:     Other: 0
+// CHECK-NEXT:     Section: Undefined (0x0)
+// CHECK-NEXT:   }
+// CHECK-NEXT:   Symbol {
+// CHECK-NEXT:     Name: foo@
+// CHECK-NEXT:     Value: 0x0
+// CHECK-NEXT:     Size: 0
+// CHECK-NEXT:     Binding: Global
+// CHECK-NEXT:     Type: None
+// CHECK-NEXT:     Other: 0
+// CHECK-NEXT:     Section: Undefined
+// CHECK-NEXT:   }
+// CHECK-NEXT: ]




More information about the llvm-commits mailing list