diff options
author | George Rimar <grimar@accesssoftek.com> | 2016-06-06 08:04:53 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2016-06-06 08:04:53 +0000 |
commit | 232cce9a26cdb5b6e515b7a9f832598db3a0e9ea (patch) | |
tree | 7757f8fbd0ea22a8356bddf2ea89c891a63f5cef | |
parent | 98c8d976ff408ef240953cdac69ee7f5862cad40 (diff) |
[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
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@271874 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | ELF/OutputSections.cpp | 3 | ||||
-rw-r--r-- | test/ELF/verneed.s | 20 |
2 files changed, 21 insertions, 2 deletions
diff --git a/ELF/OutputSections.cpp b/ELF/OutputSections.cpp index ae15bcc73..96808d34e 100644 --- a/ELF/OutputSections.cpp +++ b/ELF/OutputSections.cpp @@ -1418,6 +1418,9 @@ template <class ELFT> void VersionTableSection<ELFT>::finalize() { 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) { diff --git a/test/ELF/verneed.s b/test/ELF/verneed.s index 85af58dee..931c90352 100644 --- a/test/ELF/verneed.s +++ b/test/ELF/verneed.s @@ -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 |