diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp --- a/lld/MachO/UnwindInfoSection.cpp +++ b/lld/MachO/UnwindInfoSection.cpp @@ -432,6 +432,7 @@ // So we check their relocations instead. // FIXME: should we account for an LSDA at an absolute address? ld64 seems // to support it, but it seems unlikely to be used in practice. + fprintf(stderr, "wtf0\n"); Reloc *lsda1 = findLsdaReloc(symbolsVec[*foldBegin].second->compactUnwind); Reloc *lsda2 = findLsdaReloc(symbolsVec[*foldEnd].second->compactUnwind); @@ -439,8 +440,7 @@ continue; if (lsda1 == nullptr || lsda2 == nullptr) break; - if (lsda1->referent.get() != - lsda2->referent.get()) + if (lsda1->referent != lsda2->referent) break; if (lsda1->addend != lsda2->addend) break; @@ -536,9 +536,8 @@ } for (size_t idx : cuIndices) { - const CompactUnwindEntry &cu = cuEntries[idx]; lsdaIndex[idx] = entriesWithLsda.size(); - if (cu.lsda != 0) + if (findLsdaReloc(symbolsVec[idx].second->compactUnwind)) entriesWithLsda.push_back(idx); } @@ -617,8 +616,14 @@ const CompactUnwindEntry &cu = cuEntries[idx]; const Defined *d = symbolsVec[idx].second; if (Reloc *r = findLsdaReloc(d->compactUnwind)) { - auto *isec = r->referent.get(); - lep->lsdaOffset = isec->getVA(r->addend) - in.header->addr; + uint64_t va; + if (auto *isec = r->referent.dyn_cast()) { + va = isec->getVA(r->addend); + } else { + auto *sym = r->referent.get(); + va = sym->getVA() + r->addend; + } + lep->lsdaOffset = va - in.header->addr; } lep->functionOffset = cu.functionAddress - in.header->addr; lep++; diff --git a/lld/test/MachO/compact-unwind-r.s b/lld/test/MachO/compact-unwind-r.s new file mode 100644 --- /dev/null +++ b/lld/test/MachO/compact-unwind-r.s @@ -0,0 +1,244 @@ +# REQUIRES: x86 +# RUN: rm -rf %t; mkdir -p %t +# RUN: yaml2obj %s > %t/test.o +# RUN: %lld -dylib -lc++ %t/test.o -o %t/test +# RUN: llvm-objdump --macho --syms --unwind-info %t/test | FileCheck %s + +# CHECK: SYMBOL TABLE: +# CHECK-DAG: [[#%x,MAIN:]] l F __TEXT,__text _main +# CHECK-DAG: [[#%x,EXCEPT0:]] l O __TEXT,__gcc_except_tab _exception0 + +# CHECK: LSDA descriptors: +# CHECK-NEXT: [0]: function offset=0x[[#%.8x,MAIN]], LSDA offset=0x[[#%.8x,EXCEPT0]] + +## The YAML was generated from compiling the following code and then running it +## through `ld -r`, which converts the functionAddress and LSDA relocations from +## section- to symbol-based ones. This test covers the LSDA symbol relocation; +## the functionAddress relocation is handled in weak-definition-gc.s. +## +## .text +## .p2align 2 +## _main: +## .cfi_startproc +## .cfi_personality 155, ___gxx_personality_v0 +## .cfi_lsda 16, _exception0 +## .cfi_def_cfa_offset 16 +## ret +## .cfi_endproc +## +## .section __TEXT,__gcc_except_tab +## _exception0: +## .space 0 +## +## .subsections_via_symbols + +--- !mach-o +FileHeader: + magic: 0xFEEDFACF + cputype: 0x1000007 + cpusubtype: 0x3 + filetype: 0x1 + ncmds: 2 + sizeofcmds: 464 + flags: 0x0 + reserved: 0x0 +LoadCommands: + - cmd: LC_SEGMENT_64 + cmdsize: 392 + segname: '' + vmaddr: 0 + vmsize: 112 + fileoff: 528 + filesize: 112 + maxprot: 7 + initprot: 7 + nsects: 4 + flags: 0 + Sections: + - sectname: __text + segname: __TEXT + addr: 0x0 + size: 1 + offset: 0x210 + align: 2 + reloff: 0x0 + nreloc: 0 + flags: 0x80000400 + reserved1: 0x0 + reserved2: 0x0 + reserved3: 0x0 + content: C3 + - sectname: __gcc_except_tab + segname: __TEXT + addr: 0x1 + size: 0 + offset: 0x211 + align: 0 + reloff: 0x0 + nreloc: 0 + flags: 0x0 + reserved1: 0x0 + reserved2: 0x0 + reserved3: 0x0 + content: '' + - sectname: __eh_frame + segname: __TEXT + addr: 0x8 + size: 72 + offset: 0x218 + align: 3 + reloff: 0x280 + nreloc: 7 + flags: 0x0 + reserved1: 0x0 + reserved2: 0x0 + reserved3: 0x0 + content: 1C00000000000000017A504C5200017810079B0400000010100C0708900100002400000004000000F8FFFFFFFFFFFFFF010000000000000008E7FFFFFFFFFFFFFF0E100000000000 + relocations: + - address: 0x13 + symbolnum: 4 + pcrel: true + length: 2 + extern: true + type: 4 + scattered: false + value: 0 + - address: 0x24 + symbolnum: 2 + pcrel: false + length: 2 + extern: true + type: 5 + scattered: false + value: 0 + - address: 0x24 + symbolnum: 3 + pcrel: false + length: 2 + extern: true + type: 0 + scattered: false + value: 0 + - address: 0x28 + symbolnum: 3 + pcrel: false + length: 3 + extern: true + type: 5 + scattered: false + value: 0 + - address: 0x28 + symbolnum: 0 + pcrel: false + length: 3 + extern: true + type: 0 + scattered: false + value: 0 + - address: 0x39 + symbolnum: 3 + pcrel: false + length: 3 + extern: true + type: 5 + scattered: false + value: 0 + - address: 0x39 + symbolnum: 1 + pcrel: false + length: 3 + extern: true + type: 0 + scattered: false + value: 0 + - sectname: __compact_unwind + segname: __LD + addr: 0x50 + size: 32 + offset: 0x260 + align: 3 + reloff: 0x2B8 + nreloc: 4 + flags: 0x2000000 + reserved1: 0x0 + reserved2: 0x0 + reserved3: 0x0 + content: '0000000000000000010000000000024200000000000000000000000000000000' + relocations: + - address: 0x0 + symbolnum: 0 + pcrel: false + length: 3 + extern: true + type: 0 + scattered: false + value: 0 + - address: 0x18 + symbolnum: 1 + pcrel: false + length: 3 + extern: true + type: 0 + scattered: false + value: 0 + - address: 0x10 + symbolnum: 4 + pcrel: false + length: 3 + extern: true + type: 0 + scattered: false + value: 0 + - address: 0x18 + symbolnum: 1 + pcrel: false + length: 3 + extern: true + type: 0 + scattered: false + value: 0 + - cmd: LC_SYMTAB + cmdsize: 24 + symoff: 728 + nsyms: 5 + stroff: 808 + strsize: 64 +LinkEditData: + NameList: + - n_strx: 24 + n_type: 0xE + n_sect: 1 + n_desc: 32 + n_value: 0 + - n_strx: 30 + n_type: 0xE + n_sect: 2 + n_desc: 32 + n_value: 1 + - n_strx: 42 + n_type: 0xE + n_sect: 3 + n_desc: 0 + n_value: 8 + - n_strx: 52 + n_type: 0xE + n_sect: 3 + n_desc: 0 + n_value: 40 + - n_strx: 2 + n_type: 0x1 + n_sect: 0 + n_desc: 0 + n_value: 0 + StringTable: + - ' ' + - ___gxx_personality_v0 + - _main + - _exception0 + - EH_Frame1 + - func.eh + - '' + - '' + - '' + - '' +...