From 49419bb30322ff00e143cbaad7af98221dd0c008 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 12 Oct 2017 15:05:04 +0000 Subject: [PATCH] Use 0 as sh_link when we don't have a dynamic symbol table. It doesn't make sense to link from an alloc section to a non alloc one as we were doing. This matches the behavior of both gold and bfd. llvm-svn: 315584 --- lld/ELF/SyntheticSections.cpp | 6 ++++-- lld/test/ELF/aarch64-gnu-ifunc.s | 2 +- lld/test/ELF/gnu-ifunc-i386.s | 2 +- lld/test/ELF/gnu-ifunc.s | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 20d815ac216b..fc7971e32002 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -1284,8 +1284,10 @@ template unsigned RelocationSection::getRelocOffset() { } template void RelocationSection::finalizeContents() { - this->Link = InX::DynSymTab ? InX::DynSymTab->getParent()->SectionIndex - : InX::SymTab->getParent()->SectionIndex; + // If all relocations are *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. + this->Link = InX::DynSymTab ? InX::DynSymTab->getParent()->SectionIndex : 0; // Set required output section properties. getParent()->Link = this->Link; diff --git a/lld/test/ELF/aarch64-gnu-ifunc.s b/lld/test/ELF/aarch64-gnu-ifunc.s index 46f4a292d2ea..4e0dc328025d 100644 --- a/lld/test/ELF/aarch64-gnu-ifunc.s +++ b/lld/test/ELF/aarch64-gnu-ifunc.s @@ -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: 0 // CHECK-NEXT: AddressAlignment: 8 // CHECK-NEXT: EntrySize: 24 diff --git a/lld/test/ELF/gnu-ifunc-i386.s b/lld/test/ELF/gnu-ifunc-i386.s index 21f1313a9b05..559e98a3e625 100644 --- a/lld/test/ELF/gnu-ifunc-i386.s +++ b/lld/test/ELF/gnu-ifunc-i386.s @@ -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: 0 // CHECK-NEXT: AddressAlignment: 4 // CHECK-NEXT: EntrySize: 8 diff --git a/lld/test/ELF/gnu-ifunc.s b/lld/test/ELF/gnu-ifunc.s index f86f0300baaf..17883a3209f5 100644 --- a/lld/test/ELF/gnu-ifunc.s +++ b/lld/test/ELF/gnu-ifunc.s @@ -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: 0 // CHECK-NEXT: AddressAlignment: 8 // CHECK-NEXT: EntrySize: 24