[PATCH] D20956: [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
Fri Jun 3 04:28:24 PDT 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: grimar, llvm-commits.

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

During my work on versioned symbols I am facing with undocumented stuff about relative sections,
this one is an example. I did not find anywhere in documentation that sh_link of this one should be set to something,
but readelf using it:

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.

Btw, that is not the single miss in documentation about versioned symbols support:
For .gnu.version_d section, sh_info should be set to amount of definitions. This fact is missed in documentation, but confirmed by binutils community:
https://sourceware.org/ml/binutils/2014-11/msg00355.html
But that is unrelated to current patch, here just for information.

http://reviews.llvm.org/D20956

Files:
  ELF/OutputSections.cpp
  test/ELF/verneed.s

Index: test/ELF/verneed.s
===================================================================
--- test/ELF/verneed.s
+++ test/ELF/verneed.s
@@ -4,16 +4,32 @@
 # 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)
 # CHECK-NEXT:     SHF_ALLOC (0x2)
 # CHECK-NEXT:   ]
 # 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
Index: ELF/OutputSections.cpp
===================================================================
--- ELF/OutputSections.cpp
+++ ELF/OutputSections.cpp
@@ -1418,6 +1418,7 @@
   this->Header.sh_size =
       sizeof(Elf_Versym) * (Out<ELFT>::DynSymTab->getSymbols().size() + 1);
   this->Header.sh_entsize = sizeof(Elf_Versym);
+  this->Header.sh_link = Out<ELFT>::DynSymTab->SectionIndex;
 }
 
 template <class ELFT> void VersionTableSection<ELFT>::writeTo(uint8_t *Buf) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20956.59528.patch
Type: text/x-patch
Size: 1716 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160603/37c969ed/attachment.bin>


More information about the llvm-commits mailing list