[lld] r344226 - [ELF] - Set sh_info and sh_link for .rela.plt sections.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 11 01:25:35 PDT 2018
Author: grimar
Date: Thu Oct 11 01:25:35 2018
New Revision: 344226
URL: http://llvm.org/viewvc/llvm-project?rev=344226&view=rev
Log:
[ELF] - Set sh_info and sh_link for .rela.plt sections.
This is https://bugs.llvm.org/show_bug.cgi?id=37538,
Currently, LLD may set both sh_link and sh_info for
.rela.plt section to zero when we have only .rela.iplt section part used.
ELF spec (https://docs.oracle.com/cd/E19683-01/816-1386/chapter6-94076/index.html)
says that for SHT_REL and SHT_RELA, sh_link references the associated symbol table
and sh_info the "section to which the relocation applies."
When we set the sh_link field, for the regular case we use the .dynsym index.
For .rela.iplt sections, it is unclear what is the associated symbol table,
because R_*_RELATIVE relocations do not use symbol names and we might have no
.dynsym section at all so this patch uses .symtab section index.
Differential revision: https://reviews.llvm.org/D52830
Modified:
lld/trunk/ELF/SyntheticSections.cpp
lld/trunk/test/ELF/aarch64-gnu-ifunc.s
lld/trunk/test/ELF/dynamic-reloc.s
lld/trunk/test/ELF/gnu-ifunc-i386.s
lld/trunk/test/ELF/gnu-ifunc.s
Modified: lld/trunk/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SyntheticSections.cpp?rev=344226&r1=344225&r2=344226&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Thu Oct 11 01:25:35 2018
@@ -1493,9 +1493,12 @@ void RelocationBaseSection::addReloc(con
void RelocationBaseSection::finalizeContents() {
// If all relocations are R_*_RELATIVE they don't refer to any
// dynamic symbol and we don't need a dynamic symbol table. If that
- // is the case, just use 0 as the link.
- getParent()->Link =
- In.DynSymTab ? In.DynSymTab->getParent()->SectionIndex : 0;
+ // is the case, just use the index of the regular symbol table section.
+ getParent()->Link = In.DynSymTab ? In.DynSymTab->getParent()->SectionIndex
+ : In.SymTab->getParent()->SectionIndex;
+
+ if (In.RelaIplt == this || In.RelaPlt == this)
+ getParent()->Info = In.GotPlt->getParent()->SectionIndex;
}
RelrBaseSection::RelrBaseSection()
Modified: lld/trunk/test/ELF/aarch64-gnu-ifunc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/aarch64-gnu-ifunc.s?rev=344226&r1=344225&r2=344226&view=diff
==============================================================================
--- lld/trunk/test/ELF/aarch64-gnu-ifunc.s (original)
+++ lld/trunk/test/ELF/aarch64-gnu-ifunc.s Thu Oct 11 01:25:35 2018
@@ -15,8 +15,8 @@
// CHECK-NEXT: Address: [[RELA:.*]]
// CHECK-NEXT: Offset: 0x158
// CHECK-NEXT: Size: 48
-// CHECK-NEXT: Link: 0
-// CHECK-NEXT: Info: 0
+// CHECK-NEXT: Link: 6
+// CHECK-NEXT: Info: 4
// CHECK-NEXT: AddressAlignment: 8
// CHECK-NEXT: EntrySize: 24
// CHECK-NEXT: }
Modified: lld/trunk/test/ELF/dynamic-reloc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/dynamic-reloc.s?rev=344226&r1=344225&r2=344226&view=diff
==============================================================================
--- lld/trunk/test/ELF/dynamic-reloc.s (original)
+++ lld/trunk/test/ELF/dynamic-reloc.s Thu Oct 11 01:25:35 2018
@@ -18,7 +18,7 @@
// CHECK-NEXT: Offset:
// CHECK-NEXT: Size: [[RELASIZE:.*]]
// CHECK-NEXT: Link: 1
-// CHECK-NEXT: Info: 0
+// CHECK-NEXT: Info: 7
// CHECK-NEXT: AddressAlignment: 8
// CHECK-NEXT: EntrySize: 24
Modified: lld/trunk/test/ELF/gnu-ifunc-i386.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gnu-ifunc-i386.s?rev=344226&r1=344225&r2=344226&view=diff
==============================================================================
--- lld/trunk/test/ELF/gnu-ifunc-i386.s (original)
+++ lld/trunk/test/ELF/gnu-ifunc-i386.s Thu Oct 11 01:25:35 2018
@@ -15,8 +15,8 @@
// CHECK-NEXT: Address: [[RELA:.*]]
// CHECK-NEXT: Offset: 0xD4
// CHECK-NEXT: Size: 16
-// CHECK-NEXT: Link: 0
-// CHECK-NEXT: Info: 0
+// CHECK-NEXT: Link: 6
+// CHECK-NEXT: Info: 4
// CHECK-NEXT: AddressAlignment: 4
// CHECK-NEXT: EntrySize: 8
// CHECK-NEXT: }
Modified: lld/trunk/test/ELF/gnu-ifunc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gnu-ifunc.s?rev=344226&r1=344225&r2=344226&view=diff
==============================================================================
--- lld/trunk/test/ELF/gnu-ifunc.s (original)
+++ lld/trunk/test/ELF/gnu-ifunc.s Thu Oct 11 01:25:35 2018
@@ -15,11 +15,16 @@
// CHECK-NEXT: Address: [[RELA:.*]]
// CHECK-NEXT: Offset: 0x158
// CHECK-NEXT: Size: 48
-// CHECK-NEXT: Link: 0
-// CHECK-NEXT: Info: 0
+// CHECK-NEXT: Link: [[SYMTAB:.*]]
+// CHECK-NEXT: Info: [[GOTPLT:.*]]
// CHECK-NEXT: AddressAlignment: 8
// CHECK-NEXT: EntrySize: 24
// CHECK-NEXT: }
+// CHECK: Index: [[GOTPLT]]
+// CHECK-NEXT: Name: .got.plt
+// CHECK: Index: [[SYMTAB]]
+// CHECK-NEXT: Name: .symtab
+// CHECK-NEXT: Type: SHT_SYMTAB
// CHECK: Relocations [
// CHECK-NEXT: Section ({{.*}}) .rela.plt {
// CHECK-NEXT: 0x202000 R_X86_64_IRELATIVE
More information about the llvm-commits
mailing list