Skip to content

Commit 10641a4

Browse files
committed
Revert "[lld-macho] Support EH frames under arm64"
This reverts commit 977d62c. This change was causing crashes in 2 tests on the buildbots: - https://lab.llvm.org/buildbot/#/builders/58/builds/23914 - https://lab.llvm.org/buildbot/#/builders/36/builds/21771
1 parent 18f0b70 commit 10641a4

File tree

3 files changed

+11
-56
lines changed

3 files changed

+11
-56
lines changed

lld/MachO/InputFiles.cpp

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,37 +1172,16 @@ static CIE parseCIE(const InputSection *isec, const EhReader &reader,
11721172
//
11731173
// Concretely, we expect our relocations to write the value of `PC -
11741174
// target_addr` to `PC`. `PC` itself is denoted by a minuend relocation that
1175-
// points to a symbol plus an addend.
1176-
//
1177-
// It is important that the minuend relocation point to a symbol within the
1178-
// same section as the fixup value, since sections may get moved around.
1179-
//
1180-
// For example, for arm64, llvm-mc emits relocations for the target function
1181-
// address like so:
1182-
//
1183-
// ltmp:
1184-
// <CIE start>
1185-
// ...
1186-
// <CIE end>
1187-
// ... multiple FDEs ...
1188-
// <FDE start>
1189-
// <target function address - (ltmp + pcrel offset)>
1190-
// ...
1191-
//
1192-
// If any of the FDEs in `multiple FDEs` get dead-stripped, then `FDE start`
1193-
// will move to an earlier address, and `ltmp + pcrel offset` will no longer
1194-
// reflect an accurate pcrel value. To avoid this problem, we "canonicalize"
1195-
// our relocation by adding an `EH_Frame` symbol at `FDE start`, and updating
1196-
// the reloc to be `target function address - (EH_Frame + new pcrel offset)`.
1175+
// points to a symbol or section plus an addend.
11971176
//
11981177
// If `Invert` is set, then we instead expect `target_addr - PC` to be written
11991178
// to `PC`.
12001179
template <bool Invert = false>
12011180
Defined *
1202-
targetSymFromCanonicalSubtractor(const InputSection *isec,
1203-
std::vector<macho::Reloc>::iterator relocIt) {
1204-
macho::Reloc &subtrahend = *relocIt;
1205-
macho::Reloc &minuend = *std::next(relocIt);
1181+
getTargetSymbolFromSubtraction(const InputSection *isec,
1182+
std::vector<macho::Reloc>::iterator relocIt) {
1183+
const macho::Reloc &subtrahend = *relocIt;
1184+
const macho::Reloc &minuend = *std::next(relocIt);
12061185
assert(target->hasAttr(subtrahend.type, RelocAttrBits::SUBTRAHEND));
12071186
assert(target->hasAttr(minuend.type, RelocAttrBits::UNSIGNED));
12081187
// Note: pcSym may *not* be exactly at the PC; there's usually a non-zero
@@ -1217,21 +1196,9 @@ targetSymFromCanonicalSubtractor(const InputSection *isec,
12171196
}
12181197
if (Invert)
12191198
std::swap(pcSym, target);
1220-
if (pcSym->isec == isec) {
1221-
if (pcSym->value - (Invert ? -1 : 1) * minuend.addend != subtrahend.offset)
1222-
fatal("invalid FDE relocation in __eh_frame");
1223-
} else {
1224-
// Ensure the pcReloc points to a symbol within the current EH frame.
1225-
// HACK: we should really verify that the original relocation's semantics
1226-
// are preserved. In particular, we should have
1227-
// `oldSym->value + oldOffset == newSym + newOffset`. However, we don't
1228-
// have an easy way to access the offsets from this point in the code; some
1229-
// refactoring is needed for that.
1230-
macho::Reloc &pcReloc = Invert ? minuend : subtrahend;
1231-
pcReloc.referent = isec->symbols[0];
1232-
assert(isec->symbols[0]->value == 0);
1233-
minuend.addend = pcReloc.offset * (Invert ? 1LL : -1LL);
1234-
}
1199+
if (pcSym->isec != isec ||
1200+
pcSym->value - (Invert ? -1 : 1) * minuend.addend != subtrahend.offset)
1201+
fatal("invalid FDE relocation in __eh_frame");
12351202
return target;
12361203
}
12371204

@@ -1288,7 +1255,7 @@ void ObjFile::registerEhFrames(Section &ehFrameSection) {
12881255
if (cieOffRelocIt != isec->relocs.end()) {
12891256
// We already have an explicit relocation for the CIE offset.
12901257
cieIsec =
1291-
targetSymFromCanonicalSubtractor</*Invert=*/true>(isec, cieOffRelocIt)
1258+
getTargetSymbolFromSubtraction</*Invert=*/true>(isec, cieOffRelocIt)
12921259
->isec;
12931260
dataOff += sizeof(uint32_t);
12941261
} else {
@@ -1343,7 +1310,7 @@ void ObjFile::registerEhFrames(Section &ehFrameSection) {
13431310

13441311
Defined *funcSym;
13451312
if (funcAddrRelocIt != isec->relocs.end()) {
1346-
funcSym = targetSymFromCanonicalSubtractor(isec, funcAddrRelocIt);
1313+
funcSym = getTargetSymbolFromSubtraction(isec, funcAddrRelocIt);
13471314
} else {
13481315
funcSym = findSymbolAtAddress(sections, funcAddr);
13491316
ehRelocator.makePcRel(funcAddrOff, funcSym, target->p2WordSize);
@@ -1358,7 +1325,7 @@ void ObjFile::registerEhFrames(Section &ehFrameSection) {
13581325

13591326
InputSection *lsdaIsec = nullptr;
13601327
if (lsdaAddrRelocIt != isec->relocs.end()) {
1361-
lsdaIsec = targetSymFromCanonicalSubtractor(isec, lsdaAddrRelocIt)->isec;
1328+
lsdaIsec = getTargetSymbolFromSubtraction(isec, lsdaAddrRelocIt)->isec;
13621329
} else if (lsdaAddrOpt) {
13631330
uint64_t lsdaAddr = *lsdaAddrOpt;
13641331
Section *sec = findContainingSection(sections, &lsdaAddr);
-1.38 KB
Binary file not shown.

lld/test/MachO/eh-frame.s

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@
2020
# RUN: llvm-nm -m %t/eh-frame-x86_64-r | FileCheck %s --check-prefix NO-EH-SYMS
2121
# RUN: llvm-readobj --section-headers %t/eh-frame-x86_64-r | FileCheck %s --check-prefix=ALIGN -D#ALIGN=3
2222

23-
# RUN: llvm-mc -filetype=obj -triple=arm64-apple-macos11.0 %s -o %t/eh-frame-arm64.o
24-
# RUN: %lld -arch arm64 -lSystem -lc++ %t/eh-frame-arm64.o -o %t/eh-frame-arm64
25-
# RUN: llvm-objdump --macho --syms --indirect-symbols --unwind-info \
26-
# RUN: --dwarf=frames %t/eh-frame-arm64 | FileCheck %s -D#BASE=0x100000000 -D#DWARF_ENC=3
27-
# RUN: llvm-nm -m %t/eh-frame-arm64 | FileCheck %s --check-prefix NO-EH-SYMS
28-
29-
# COM: ld -r %t/eh-frame-arm64.o -o %S/Inputs/eh-frame-arm64-r.o
30-
# RUN: %lld -arch arm64 -lSystem -lc++ %S/Inputs/eh-frame-arm64-r.o -o %t/eh-frame-arm64-r
31-
# RUN: llvm-objdump --macho --syms --indirect-symbols --unwind-info \
32-
# RUN: --dwarf=frames %t/eh-frame-arm64-r | FileCheck %s -D#BASE=0x100000000 -D#DWARF_ENC=3
33-
# RUN: llvm-nm -m %t/eh-frame-arm64-r | FileCheck %s --check-prefix NO-EH-SYMS
34-
3523
# ALIGN: Name: __eh_frame
3624
# ALIGN-NEXT: Segment: __TEXT
3725
# ALIGN-NEXT: Address:

0 commit comments

Comments
 (0)