[lld] r271874 - [ELF] - Assign sh_link field of SHT_GNU_versym section to DynSymTab section index.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 6 01:04:54 PDT 2016


Author: grimar
Date: Mon Jun  6 03:04:53 2016
New Revision: 271874

URL: http://llvm.org/viewvc/llvm-project?rev=271874&view=rev
Log:
[ELF] - Assign sh_link field of SHT_GNU_versym section to DynSymTab section index.

.gnu.version should have sh_link field initialized with index of DynSymTab section.

GNU documentation looks misses that, but Sun docs mention it, according to
https://docs.oracle.com/cd/E19120-01/open.solaris/819-0690/chapter6-54676/index.html 
versym sh_link is indeed supposed to point to the .dynsym section.

Binutils readelf tool also relies on that:
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=binutils/readelf.c;h=b6454d353279dc57745cd5a2d68b5f3f69f8e17c;hb=5522f910cb539905d6adfdceab208ddfa5e84557#l9988

Both gold/bfd do the same + after this patch I am able to see this section in readelf output, was unable before in my case.

Differential revision: http://reviews.llvm.org/D20956

Modified:
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/test/ELF/verneed.s

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=271874&r1=271873&r2=271874&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Mon Jun  6 03:04:53 2016
@@ -1418,6 +1418,9 @@ template <class ELFT> void VersionTableS
   this->Header.sh_size =
       sizeof(Elf_Versym) * (Out<ELFT>::DynSymTab->getSymbols().size() + 1);
   this->Header.sh_entsize = sizeof(Elf_Versym);
+  // At the moment of june 2016 GNU docs does not mention that sh_link field
+  // should be set, but Sun docs do. Also readelf relies on this field.
+  this->Header.sh_link = Out<ELFT>::DynSymTab->SectionIndex;
 }
 
 template <class ELFT> void VersionTableSection<ELFT>::writeTo(uint8_t *Buf) {

Modified: lld/trunk/test/ELF/verneed.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/verneed.s?rev=271874&r1=271873&r2=271874&view=diff
==============================================================================
--- lld/trunk/test/ELF/verneed.s (original)
+++ lld/trunk/test/ELF/verneed.s Mon Jun  6 03:04:53 2016
@@ -4,7 +4,23 @@
 # RUN: llvm-readobj -sections -dyn-symbols -dynamic-table %t | FileCheck %s
 # RUN: llvm-objdump -s %t | FileCheck --check-prefix=CONTENTS %s
 
-# CHECK:        Index: 2
+# CHECK:        Section {
+# CHECK:         Index: 1
+# CHECK-NEXT:    Name: .dynsym (1)
+# CHECK-NEXT:    Type: SHT_DYNSYM (0xB)
+# CHECK-NEXT:    Flags [ (0x2)
+# CHECK-NEXT:      SHF_ALLOC (0x2)
+# CHECK-NEXT:    ]
+# CHECK-NEXT:    Address: 0x101C8
+# CHECK-NEXT:    Offset: 0x1C8
+# CHECK-NEXT:    Size: 96
+# CHECK-NEXT:    Link: 5
+# CHECK-NEXT:    Info: 1
+# CHECK-NEXT:    AddressAlignment: 8
+# CHECK-NEXT:    EntrySize: 24
+# CHECK-NEXT:   }
+# CHECK-NEXT:   Section {
+# CHECK-NEXT:   Index: 2
 # CHECK-NEXT:   Name: .gnu.version (9)
 # CHECK-NEXT:   Type: SHT_GNU_versym (0x6FFFFFFF)
 # CHECK-NEXT:   Flags [ (0x2)
@@ -13,7 +29,7 @@
 # CHECK-NEXT:   Address: 0x10228
 # CHECK-NEXT:   Offset: 0x228
 # CHECK-NEXT:   Size: 8
-# CHECK-NEXT:   Link: 0
+# CHECK-NEXT:   Link: 1
 # CHECK-NEXT:   Info: 0
 # CHECK-NEXT:   AddressAlignment: 2
 # CHECK-NEXT:   EntrySize: 2




More information about the llvm-commits mailing list