[lld] r345899 - [ELF] Change sh_link of .rel{, a}.plt to make GNU strip happy
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 1 15:28:58 PDT 2018
Author: maskray
Date: Thu Nov 1 15:28:58 2018
New Revision: 345899
URL: http://llvm.org/viewvc/llvm-project?rev=345899&view=rev
Log:
[ELF] Change sh_link of .rel{,a}.plt to make GNU strip happy
Summary:
D52830 sets sh_link to .symtab in static link, which breaks executable stripped by GNU strip.
It may also be odd that .rela.plt (SHF_ALLOC) points to .symtab (non-SHF_ALLOC).
Change the logic on pcc's suggestion.
Before:
% clang -fuse-ld=lld -static -xc =(printf 'int main(){}') # or gcc
% strip a.out; ./a.out
unexpected reloc type in static binary[1] 61634 segmentation fault ./a.out
Reviewers: ruiu, grimar, emaste, espindola
Reviewed By: ruiu
Subscribers: pcc, arichardson, llvm-commits
Differential Revision: https://reviews.llvm.org/D53993
Modified:
lld/trunk/ELF/SyntheticSections.cpp
lld/trunk/test/ELF/aarch64-gnu-ifunc.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=345899&r1=345898&r2=345899&view=diff
==============================================================================
--- lld/trunk/ELF/SyntheticSections.cpp (original)
+++ lld/trunk/ELF/SyntheticSections.cpp Thu Nov 1 15:28:58 2018
@@ -1491,15 +1491,11 @@ void RelocationBaseSection::addReloc(con
}
void RelocationBaseSection::finalizeContents() {
- // If all relocations are R_*_{,I}RELATIVE they don't refer to any dynamic
- // symbol and we don't need a dynamic symbol table. If that is the case, use
- // the index of the regular symbol table section (if exists) or 0.
- if (In.DynSymTab)
- getParent()->Link = In.DynSymTab->getParent()->SectionIndex;
- else if (In.SymTab)
- getParent()->Link = In.SymTab->getParent()->SectionIndex;
- else
- getParent()->Link = 0;
+ // When linking glibc statically, .rel{,a}.plt contains R_*_IRELATIVE
+ // relocations due to IFUNC (e.g. strcpy). sh_link will be set to 0 in that
+ // case.
+ InputSection *SymTab = Config->Relocatable ? In.SymTab : In.DynSymTab;
+ getParent()->Link = SymTab ? SymTab->getParent()->SectionIndex : 0;
if (In.RelaIplt == this || In.RelaPlt == this)
getParent()->Info = In.GotPlt->getParent()->SectionIndex;
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=345899&r1=345898&r2=345899&view=diff
==============================================================================
--- lld/trunk/test/ELF/aarch64-gnu-ifunc.s (original)
+++ lld/trunk/test/ELF/aarch64-gnu-ifunc.s Thu Nov 1 15:28:58 2018
@@ -15,7 +15,7 @@
// CHECK-NEXT: Address: [[RELA:.*]]
// CHECK-NEXT: Offset: 0x158
// CHECK-NEXT: Size: 48
-// CHECK-NEXT: Link: 6
+// CHECK-NEXT: Link: 0
// CHECK-NEXT: Info: 4
// 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=345899&r1=345898&r2=345899&view=diff
==============================================================================
--- lld/trunk/test/ELF/gnu-ifunc-i386.s (original)
+++ lld/trunk/test/ELF/gnu-ifunc-i386.s Thu Nov 1 15:28:58 2018
@@ -15,7 +15,7 @@
// CHECK-NEXT: Address: [[RELA:.*]]
// CHECK-NEXT: Offset: 0xD4
// CHECK-NEXT: Size: 16
-// CHECK-NEXT: Link: 6
+// CHECK-NEXT: Link: 0
// CHECK-NEXT: Info: 4
// CHECK-NEXT: AddressAlignment: 4
// CHECK-NEXT: EntrySize: 8
Modified: lld/trunk/test/ELF/gnu-ifunc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/gnu-ifunc.s?rev=345899&r1=345898&r2=345899&view=diff
==============================================================================
--- lld/trunk/test/ELF/gnu-ifunc.s (original)
+++ lld/trunk/test/ELF/gnu-ifunc.s Thu Nov 1 15:28:58 2018
@@ -15,16 +15,13 @@
// CHECK-NEXT: Address: [[RELA:.*]]
// CHECK-NEXT: Offset: 0x158
// CHECK-NEXT: Size: 48
-// CHECK-NEXT: Link: [[SYMTAB:.*]]
+// CHECK-NEXT: Link: 0
// 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