Skip to content

Commit 48e251b

Browse files
committed
Revert D122459 "[ELF] --emit-relocs: adjust offsets of .rel[a].eh_frame relocations"
This reverts commit 6faba31. It may cause "offset is outside the section".
1 parent 33deaa1 commit 48e251b

File tree

4 files changed

+7
-30
lines changed

4 files changed

+7
-30
lines changed

lld/ELF/InputSection.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,11 @@ uint64_t SectionBase::getOffset(uint64_t offset) const {
160160
case Regular:
161161
case Synthetic:
162162
return cast<InputSection>(this)->outSecOff + offset;
163-
case EHFrame: {
163+
case EHFrame:
164164
// The file crtbeginT.o has relocations pointing to the start of an empty
165165
// .eh_frame that is known to be the first in the link. It does that to
166166
// identify the start of the output .eh_frame.
167-
const EhInputSection *es = cast<EhInputSection>(this);
168-
if (InputSection *isec = es->getParent())
169-
return isec->outSecOff + es->getParentOffset(offset);
170-
return es->getParentOffset(offset);
171-
}
167+
return offset;
172168
case Merge:
173169
const MergeInputSection *ms = cast<MergeInputSection>(this);
174170
if (InputSection *isec = ms->getParent())
@@ -1338,21 +1334,6 @@ void EhInputSection::split(ArrayRef<RelTy> rels) {
13381334
getObjMsg(d.data() - rawData.data()));
13391335
}
13401336

1341-
const EhSectionPiece &EhInputSection::getSectionPiece(uint64_t offset) const {
1342-
if (this->data().size() < offset)
1343-
fatal(toString(this) + ": offset is outside the section");
1344-
return partition_point(
1345-
pieces, [=](EhSectionPiece p) { return p.inputOff <= offset; })[-1];
1346-
}
1347-
1348-
// Return the offset in an output section for a given input offset.
1349-
uint64_t EhInputSection::getParentOffset(uint64_t offset) const {
1350-
const EhSectionPiece &piece = getSectionPiece(offset);
1351-
if (piece.outputOff == -1) // invalid piece
1352-
return offset - piece.inputOff;
1353-
return piece.outputOff + (offset - piece.inputOff);
1354-
}
1355-
13561337
static size_t findNull(StringRef s, size_t entSize) {
13571338
for (unsigned i = 0, n = s.size(); i != n; i += entSize) {
13581339
const char *b = s.begin() + i;

lld/ELF/InputSection.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,6 @@ class EhInputSection : public InputSectionBase {
325325
SmallVector<EhSectionPiece, 0> pieces;
326326

327327
SyntheticSection *getParent() const;
328-
uint64_t getParentOffset(uint64_t offset) const;
329-
330-
// Return the EHSectionPiece at a given input section offset.
331-
const EhSectionPiece &getSectionPiece(uint64_t offset) const;
332328
};
333329

334330
// This is a section that is added directly to an output section

lld/test/ELF/eh-frame-merge.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
# RELOC: Offset Info Type Symbol's Value Symbol's Name + Addend
1818
# RELOC-NEXT: {{0*}}[[#%x,OFF:]] [[#%x,]] R_X86_64_PC32 [[#%x,]] foo + 0
19-
# RELOC-NEXT: {{0*}}[[#%x,OFF+24]] [[#%x,]] R_X86_64_PC32 [[#%x,]] bar + 0
20-
# RELOC-NEXT: {{0*}}[[#OFF+48]] [[#%x,]] R_X86_64_PC32 [[#%x,]] foo + 1
21-
# RELOC-NEXT: {{0*}}[[#%x,OFF-24]] [[#%x,]] R_X86_64_NONE 0{{$}}
19+
# RELOC-NEXT: {{0*}}[[#%x,OFF+20]] [[#%x,]] R_X86_64_PC32 [[#%x,]] bar + 0
20+
# RELOC-NEXT: {{0*}}[[#OFF]] [[#%x,]] R_X86_64_PC32 [[#%x,]] foo + 1
21+
# RELOC-NEXT: {{0*}}[[#OFF+20]] [[#%x,]] R_X86_64_NONE 0{{$}}
2222

2323
# EH: Format: DWARF32
2424
# EH: 00000018 00000014 0000001c FDE cie=00000000 pc={{0*}}[[#%x,FOO:]]...

lld/test/ELF/mips64-eh-abs-reloc.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
# Having an R_MIPS_64 relocation in eh_frame would previously crash LLD
33
# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-freebsd %s -o %t.o
44
# RUN: llvm-readobj -r %t.o | FileCheck %s -check-prefix OBJ
5-
# RUN: ld.lld --eh-frame-hdr -shared -z notext -o %t.so %t.o --no-check-dynamic-relocations
5+
# RUN: ld.lld --eh-frame-hdr -shared -z notext -o %t.so %t.o
66
# RUN: llvm-readobj -r %t.so | FileCheck %s -check-prefix PIC-RELOCS
77

88
# Linking this as a PIE executable would also previously crash
99
# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-freebsd %S/Inputs/archive2.s -o %t-foo.o
1010
# -pie needs -z notext because of the R_MIPS_64 relocation
11-
# RUN: ld.lld --eh-frame-hdr -Bdynamic -pie -z notext -o %t-pie-dynamic.exe %t.o %t-foo.o --no-check-dynamic-relocations
11+
# RUN: ld.lld --eh-frame-hdr -Bdynamic -pie -z notext -o %t-pie-dynamic.exe %t.o %t-foo.o
1212
# RUN: llvm-readobj -r %t-pie-dynamic.exe | FileCheck %s -check-prefix PIC-RELOCS
1313

1414

0 commit comments

Comments
 (0)