From 2197311c31ced1aff8d965294e190aaae1ac729b Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 20 Jul 2016 20:19:58 +0000 Subject: [PATCH] Delete EhInputSection::getOffset. We no longer need it for relocations in .eh_frame. The only relocations that point to .eh_frame are the ones trying to find the output .eh_frame. This actually fixes a bug in the symbol value code. It was not handling -1 as an indicator for a piece not being included in the output. llvm-svn: 276175 --- lld/ELF/InputSection.cpp | 20 ++++---------------- lld/ELF/InputSection.h | 4 ---- lld/ELF/Relocations.cpp | 1 - lld/test/ELF/eh-frame-marker.s | 12 ++++++++++++ 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 1cb1137..23c4f3d 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -68,7 +68,10 @@ typename ELFT::uint InputSectionBase::getOffset(uintX_t Offset) const { case Regular: return cast>(this)->OutSecOff + Offset; case EHFrame: - return cast>(this)->getOffset(Offset); + // The file crtbeginT.o has relocations pointing to the start of an empty + // .eh_frame that is known to be the first in the link. It does that to + // identify the start of the output .eh_frame. + return Offset; case Merge: return cast>(this)->getOffset(Offset); case MipsReginfo: @@ -461,21 +464,6 @@ void EhInputSection::split() { } } -template -typename ELFT::uint EhInputSection::getOffset(uintX_t Offset) const { - // The file crtbeginT.o has relocations pointing to the start of an empty - // .eh_frame that is known to be the first in the link. It does that to - // identify the start of the output .eh_frame. Handle this special case. - if (this->getSectionHdr()->sh_size == 0) - return Offset; - const SectionPiece *Piece = this->getSectionPiece(Offset); - if (Piece->OutputOff == size_t(-1)) - return -1; // Not in the output - - uintX_t Addend = Offset - Piece->InputOff; - return Piece->OutputOff + Addend; -} - static size_t findNull(ArrayRef A, size_t EntSize) { // Optimize the common case. StringRef S((const char *)A.data(), A.size()); diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index eabe5fb..107aa03 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -171,10 +171,6 @@ public: static bool classof(const InputSectionBase *S); void split(); - // Translate an offset in the input section to an offset in the output - // section. - uintX_t getOffset(uintX_t Offset) const; - // Relocation section that refer to this one. const Elf_Shdr *RelocSection = nullptr; }; diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 106cc7c..f0a2d17 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -557,7 +557,6 @@ static void scanRelocs(InputSectionBase &C, ArrayRef Rels) { if (PieceI->OutputOff == (uintX_t)-1) continue; Offset = PieceI->OutputOff + RI.r_offset - PieceI->InputOff; - assert(Offset == C.getOffset(RI.r_offset)); } else { Offset = C.getOffset(RI.r_offset); } diff --git a/lld/test/ELF/eh-frame-marker.s b/lld/test/ELF/eh-frame-marker.s index a5de2a7..8c39515 100644 --- a/lld/test/ELF/eh-frame-marker.s +++ b/lld/test/ELF/eh-frame-marker.s @@ -1,6 +1,18 @@ // RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux // RUN: ld.lld --eh-frame-hdr %t.o -o %t.so -shared +// RUN: llvm-readobj -t -s %t.so | FileCheck %s // We used to crash on this. + +// CHECK: Name: .eh_frame +// CHECK-NEXT: Type: SHT_PROGBITS +// CHECK-NEXT: Flags [ +// CHECK-NEXT: SHF_ALLOC +// CHECK-NEXT: ] +// CHECK-NEXT: Address: 0x200 + +// CHECK: Name: foo +// CHECK-NEXT: Value: 0x200 + .section .eh_frame foo: .long 0 -- 2.7.4