Fix crash with -emit-relocs -shared.

The code to handle the input SHT_REL/SHT_RELA sections was getting
confused with the linker generated relocation sections.

llvm-svn: 295322
This commit is contained in:
Rafael Espindola 2017-02-16 14:23:43 +00:00
parent 1540b06ef8
commit 82f00ec4a2
2 changed files with 21 additions and 1 deletions

View File

@ -119,10 +119,14 @@ template <class ELFT> void OutputSection<ELFT>::finalize() {
if (!Config->copyRelocs() || (Type != SHT_RELA && Type != SHT_REL))
return;
InputSection<ELFT> *First = Sections[0];
if (isa<SyntheticSection<ELFT>>(First))
return;
this->Link = In<ELFT>::SymTab->OutSec->SectionIndex;
// sh_info for SHT_REL[A] sections should contain the section header index of
// the section to which the relocation applies.
InputSectionBase<ELFT> *S = Sections[0]->getRelocatedSection();
InputSectionBase<ELFT> *S = First->getRelocatedSection();
this->Info = S->OutSec->SectionIndex;
}

View File

@ -0,0 +1,16 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: ld.lld --emit-relocs %t.o -o %t.so -shared
# RUN: llvm-readobj -r %t.so | FileCheck %s
.data
.quad foo
# CHECK: Relocations [
# CHECK-NEXT: Section (4) .rela.dyn {
# CHECK-NEXT: 0x1000 R_X86_64_64 foo 0x0
# CHECK-NEXT: }
# CHECK-NEXT: Section (8) .rela.data {
# CHECK-NEXT: 0x1000 R_X86_64_64 foo 0x0
# CHECK-NEXT: }
# CHECK-NEXT: ]