[lld] r295129 - Fix the st_name of section symbols.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 14 16:23:09 PST 2017


Author: rafael
Date: Tue Feb 14 18:23:09 2017
New Revision: 295129

URL: http://llvm.org/viewvc/llvm-project?rev=295129&view=rev
Log:
Fix the st_name of section symbols.

If it is non-zero then objdump will print an empty name when printing
relocations against the section.

Added:
    lld/trunk/test/ELF/relocatable-symbol-name.s
Modified:
    lld/trunk/ELF/SyntheticSections.cpp
    lld/trunk/ELF/SyntheticSections.h
    lld/trunk/test/ELF/relocatable-ehframe.s

Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=295129&r1=295128&r2=295129&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Tue Feb 14 18:23:09 2017
@@ -768,7 +768,10 @@ template <class ELFT>
 StringTableSection<ELFT>::StringTableSection(StringRef Name, bool Dynamic)
     : SyntheticSection<ELFT>(Dynamic ? (uintX_t)SHF_ALLOC : 0, SHT_STRTAB, 1,
                              Name),
-      Dynamic(Dynamic) {}
+      Dynamic(Dynamic) {
+  // ELF string tables start with a NUL byte.
+  addString("");
+}
 
 // Adds a string to the string table. If HashIt is true we hash and check for
 // duplicates. It is optional because the name of global symbols are already
@@ -788,8 +791,6 @@ unsigned StringTableSection<ELFT>::addSt
 }
 
 template <class ELFT> void StringTableSection<ELFT>::writeTo(uint8_t *Buf) {
-  // ELF string tables start with NUL byte, so advance the pointer by one.
-  ++Buf;
   for (StringRef S : Strings) {
     memcpy(Buf, S.data(), S.size());
     Buf += S.size() + 1;

Modified: lld/trunk/ELF/SyntheticSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.h?rev=295129&r1=295128&r2=295129&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.h (original)
+++ lld/trunk/ELF/SyntheticSections.h Tue Feb 14 18:23:09 2017
@@ -266,8 +266,7 @@ public:
 private:
   const bool Dynamic;
 
-  // ELF string tables start with a NUL byte, so 1.
-  uintX_t Size = 1;
+  uintX_t Size = 0;
 
   llvm::DenseMap<StringRef, unsigned> StringMap;
   std::vector<StringRef> Strings;

Modified: lld/trunk/test/ELF/relocatable-ehframe.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocatable-ehframe.s?rev=295129&r1=295128&r2=295129&view=diff
==============================================================================
--- lld/trunk/test/ELF/relocatable-ehframe.s (original)
+++ lld/trunk/test/ELF/relocatable-ehframe.s Tue Feb 14 18:23:09 2017
@@ -10,13 +10,13 @@
 # CHECK-NEXT: ]
 # CHECK-NEXT: Address:
 # CHECK-NEXT: Offset
-# CHECK-NEXT: Size: 9
+# CHECK-NEXT: Size: 8
 # CHECK-NEXT: Link: 0
 # CHECK-NEXT: Info: 0
 # CHECK-NEXT: AddressAlignment: 1
 # CHECK-NEXT: EntrySize: 0
 # CHECK-NEXT: SectionData (
-# CHECK-NEXT:   0000: 00005F73 74617274 00                 |.._start.|
+# CHECK-NEXT:   0000: 005F7374 61727400                 |._start.|
 # CHECK-NEXT: )
 
 # CHECK:      Relocations [

Added: lld/trunk/test/ELF/relocatable-symbol-name.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocatable-symbol-name.s?rev=295129&view=auto
==============================================================================
--- lld/trunk/test/ELF/relocatable-symbol-name.s (added)
+++ lld/trunk/test/ELF/relocatable-symbol-name.s Tue Feb 14 18:23:09 2017
@@ -0,0 +1,28 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld -r %t.o -o %t
+# RUN: llvm-readobj -t %t | FileCheck %s
+
+# Test that the section symbol has st_name equal to zero. GNU objdump
+# requires this to print relocations against the section.
+
+# CHECK:      Symbols [
+# CHECK-NEXT:   Symbol {
+# CHECK-NEXT:     Name:
+# CHECK-NEXT:     Value:
+# CHECK-NEXT:     Size:
+# CHECK-NEXT:     Binding:
+# CHECK-NEXT:     Type:
+# CHECK-NEXT:     Other:
+# CHECK-NEXT:     Section:
+# CHECK-NEXT:   }
+# CHECK-NEXT:   Symbol {
+# CHECK-NEXT:     Name:  (0)
+# CHECK-NEXT:     Value:
+# CHECK-NEXT:     Size:
+# CHECK-NEXT:     Binding:
+# CHECK-NEXT:     Type: Section
+# CHECK-NEXT:     Other:
+# CHECK-NEXT:     Section: .text
+# CHECK-NEXT:   }
+# CHECK-NEXT: ]




More information about the llvm-commits mailing list