diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp --- a/lld/MachO/Writer.cpp +++ b/lld/MachO/Writer.cpp @@ -672,13 +672,25 @@ if (isec->shouldOmitFromOutput()) continue; + bool skipNext = false; for (auto it = isec->relocs.begin(); it != isec->relocs.end(); ++it) { lld::macho::Reloc &r = *it; + + // Canonicalize the referent so that later accesses in Writer won't + // have to worry about it. Perhaps we should do this for Defined::isec + // too... + if (auto *referentIsec = r.referent.dyn_cast()) + r.referent = referentIsec->canonical(); + + if (skipNext) { + skipNext = false; + continue; + } if (target->hasAttr(r.type, RelocAttrBits::SUBTRAHEND)) { // Skip over the following UNSIGNED relocation -- it's just there as the // minuend, and doesn't have the usual UNSIGNED semantics. We don't want // to emit rebase opcodes for it. - it++; + skipNext = true; continue; } if (auto *sym = r.referent.dyn_cast()) { @@ -688,11 +700,6 @@ if (!isa(sym) && validateSymbolRelocation(sym, isec, r)) prepareSymbolRelocation(sym, isec, r); } else { - // Canonicalize the referent so that later accesses in Writer won't - // have to worry about it. Perhaps we should do this for Defined::isec - // too... - auto *referentIsec = r.referent.get(); - r.referent = referentIsec->canonical(); if (!r.pcrel) { if (config->emitChainedFixups) in.chainedFixups->addRebase(isec, r.offset); diff --git a/lld/test/MachO/fold-dwarf-lsda.s b/lld/test/MachO/fold-dwarf-lsda.s new file mode 100644 --- /dev/null +++ b/lld/test/MachO/fold-dwarf-lsda.s @@ -0,0 +1,69 @@ +# REQUIRES: x86 + +## Use an old version to ensure we do *not* have any compact-unwind. +# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos %s -o %t.o +# RUN: %lld -lSystem -lc++ --icf=all -arch x86_64 -arch x86_64 -platform_version macos 11.0 11.0 %t.o -o %t.out + + .section __TEXT,__text,regular,pure_instructions + .macosx_version_min 10, 4 + .globl _g + .p2align 4, 0x90 +_g: + .cfi_startproc + .cfi_def_cfa_offset 16 + .cfi_offset %rbp, -16 + .cfi_def_cfa_register %rbp + .cfi_endproc + + .globl _f + .p2align 4, 0x90 +_f: + .cfi_startproc + .cfi_personality 155, ___gxx_personality_v0 + .cfi_lsda 16, Lexception0 + .cfi_def_cfa_offset 16 + .cfi_offset %rbp, -16 + .cfi_def_cfa_register %rbp + callq _g + retq + .cfi_endproc + + .section __TEXT,__gcc_except_tab + .p2align 2 +GCC_except_table1: +Lexception0: + .byte 255 + .byte 155 + .p2align 2 + + .section __TEXT,__text,regular,pure_instructions + .globl _f2 + .p2align 4, 0x90 +_f2: + .cfi_startproc + .cfi_personality 155, ___gxx_personality_v0 + .cfi_lsda 16, Lexception1 + .cfi_def_cfa_offset 16 + .cfi_offset %rbp, -16 + .cfi_def_cfa_register %rbp + callq _g + retq + .cfi_endproc + + + .section __TEXT,__gcc_except_tab + .p2align 2 +GCC_except_table2: +Lexception1: + .byte 255 + .byte 155 + .p2align 2 + + .section __TEXT,__text,regular,pure_instructions + .globl _main + .p2align 4, 0x90 +_main: + retq + + +.subsections_via_symbols