[lld] r249326 - Don't copy STT_SECTION from the inputs.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 5 09:25:43 PDT 2015


Author: rafael
Date: Mon Oct  5 11:25:43 2015
New Revision: 249326

URL: http://llvm.org/viewvc/llvm-project?rev=249326&view=rev
Log:
Don't copy STT_SECTION from the inputs.

This matches the behavior of gold and bfd ld.

Added:
    lld/trunk/test/elf2/section-symbol.s
Modified:
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/OutputSections.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=249326&r1=249325&r2=249326&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Mon Oct  5 11:25:43 2015
@@ -407,7 +407,12 @@ bool lld::elf2::includeInDynamicSymtab(c
   return B.isUsedInDynamicReloc();
 }
 
-bool lld::elf2::shouldKeepInSymtab(StringRef SymName) {
+template <class ELFT>
+bool lld::elf2::shouldKeepInSymtab(StringRef SymName,
+                                   const typename ELFFile<ELFT>::Elf_Sym &Sym) {
+  if (Sym.getType() == STT_SECTION)
+    return false;
+
   if (Config->DiscardNone)
     return true;
 
@@ -451,7 +456,7 @@ void SymbolTableSection<ELFT>::writeLoca
     Elf_Sym_Range Syms = File.getLocalSymbols();
     for (const Elf_Sym &Sym : Syms) {
       ErrorOr<StringRef> SymName = Sym.getName(File.getStringTable());
-      if (SymName && !shouldKeepInSymtab(*SymName))
+      if (SymName && !shouldKeepInSymtab<ELFT>(*SymName, Sym))
         continue;
       auto *ESym = reinterpret_cast<Elf_Sym *>(Buf);
       Buf += sizeof(*ESym);
@@ -630,5 +635,14 @@ template bool includeInSymtab<ELF32LE>(c
 template bool includeInSymtab<ELF32BE>(const SymbolBody &);
 template bool includeInSymtab<ELF64LE>(const SymbolBody &);
 template bool includeInSymtab<ELF64BE>(const SymbolBody &);
+
+template bool shouldKeepInSymtab<ELF32LE>(StringRef,
+                                          const ELFFile<ELF32LE>::Elf_Sym &);
+template bool shouldKeepInSymtab<ELF32BE>(StringRef,
+                                          const ELFFile<ELF32BE>::Elf_Sym &);
+template bool shouldKeepInSymtab<ELF64LE>(StringRef,
+                                          const ELFFile<ELF64LE>::Elf_Sym &);
+template bool shouldKeepInSymtab<ELF64BE>(StringRef,
+                                          const ELFFile<ELF64BE>::Elf_Sym &);
 }
 }

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=249326&r1=249325&r2=249326&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Mon Oct  5 11:25:43 2015
@@ -44,7 +44,10 @@ getLocalSymVA(const typename llvm::objec
 template <class ELFT> bool includeInSymtab(const SymbolBody &B);
 
 bool includeInDynamicSymtab(const SymbolBody &B);
-bool shouldKeepInSymtab(StringRef SymName);
+
+template <class ELFT>
+bool shouldKeepInSymtab(
+    StringRef Name, const typename llvm::object::ELFFile<ELFT>::Elf_Sym &Sym);
 
 // This represents a section in an output file.
 // Different sub classes represent different types of sections. Some contain

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=249326&r1=249325&r2=249326&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Oct  5 11:25:43 2015
@@ -293,7 +293,7 @@ template <class ELFT> void Writer<ELFT>:
       Elf_Sym_Range Syms = File.getLocalSymbols();
       for (const Elf_Sym &Sym : Syms) {
         ErrorOr<StringRef> SymName = Sym.getName(File.getStringTable());
-        if (SymName && shouldKeepInSymtab(*SymName))
+        if (SymName && shouldKeepInSymtab<ELFT>(*SymName, Sym))
           SymTabSec.addSymbol(*SymName, true);
       }
     }

Added: lld/trunk/test/elf2/section-symbol.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/section-symbol.s?rev=249326&view=auto
==============================================================================
--- lld/trunk/test/elf2/section-symbol.s (added)
+++ lld/trunk/test/elf2/section-symbol.s Mon Oct  5 11:25:43 2015
@@ -0,0 +1,29 @@
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t
+// RUN: ld.lld2 %t -o %t.so -shared -discard-none
+// RUN: llvm-readobj -t %t.so | FileCheck %s
+
+// Test that we don't include the section symbols from the .o in the .so
+
+// CHECK:      Symbols [
+// CHECK-NEXT:   Symbol {
+// CHECK-NEXT:     Name:  (0)
+// CHECK-NEXT:     Value: 0x0
+// CHECK-NEXT:     Size: 0
+// CHECK-NEXT:     Binding: Local
+// CHECK-NEXT:     Type: None
+// CHECK-NEXT:     Other: 0
+// CHECK-NEXT:     Section: Undefined
+// CHECK-NEXT:   }
+// CHECK-NEXT:   Symbol {
+// CHECK-NEXT:     Name: foo
+// CHECK-NEXT:     Value:
+// CHECK-NEXT:     Size: 0
+// CHECK-NEXT:     Binding: Local
+// CHECK-NEXT:     Type: None
+// CHECK-NEXT:     Other: 0
+// CHECK-NEXT:     Section: .text
+// CHECK-NEXT:   }
+// CHECK-NEXT: ]
+
+foo:
+        .quad foo




More information about the llvm-commits mailing list