diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp --- a/lld/MachO/UnwindInfoSection.cpp +++ b/lld/MachO/UnwindInfoSection.cpp @@ -257,7 +257,6 @@ uint64_t referentVA = TombstoneValue; if (auto *referentSym = r.referent.dyn_cast()) { if (!isa(referentSym)) { - assert(referentSym->isInGot()); if (auto *defined = dyn_cast(referentSym)) checkTextSegment(defined->isec); // At this point in the link, we may not yet know the final address of diff --git a/lld/test/MachO/relocs-syms-not-in-got.s b/lld/test/MachO/relocs-syms-not-in-got.s new file mode 100644 --- /dev/null +++ b/lld/test/MachO/relocs-syms-not-in-got.s @@ -0,0 +1,351 @@ +# REQUIRES: x86 +## FIXME: These yaml files were from an object file produced with 'ld -r', specifically, emulating these steps: +## echo 'int main() {return 0;}' > foo.c +## echo 'int getX() {return 123;}' > bar.c +## +## clang -c -g -o foo.o foo.c +## clang -c -g -o bar_1.o bar.c +## ld -r -o bar.o bar_1.o +## ld64.lld.darwinnew --error-limit=0 -dynamic -arch x86_64 -platform_version macos 11.0.0 14.5 foo.o bar.o + + +# RUN: rm -rf %t; split-file %s %t + +# RUN: yaml2obj %t/foo.yaml -o %t/foo.o +# RUN: yaml2obj %t/bar.yaml -o %t/bar.o +# RUN: %lld -lSystem -dynamic -arch x86_64 -platform_version macos 11.0.0 14.5 -o %t/a.out %t/foo.o %t/bar.o + +#--- foo.yaml +--- !mach-o +FileHeader: + magic: 0xFEEDFACF + cputype: 0x01000007 + cpusubtype: 0x00000003 + filetype: 0x00000001 + ncmds: 3 + sizeofcmds: 440 + flags: 0x00002000 + reserved: 0x00000000 +LoadCommands: + - cmd: LC_SEGMENT_64 + cmdsize: 312 + segname: '' + vmaddr: 0 + vmsize: 112 + fileoff: 472 + filesize: 112 + maxprot: 7 + initprot: 7 + nsects: 2 + flags: 0 + Sections: + - sectname: __text + segname: __TEXT + addr: 0x0000000000000000 + size: 15 + offset: 0x000001D8 + align: 4 + reloff: 0x00000000 + nreloc: 0 + flags: 0x80000400 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + content: 554889E531C0C745FC000000005DC3 + - sectname: __compact_unwind + segname: __LD + addr: 0x0000000000000010 + size: 32 + offset: 0x000001E8 + align: 3 + reloff: 0x00000248 + nreloc: 1 + flags: 0x02000000 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + content: 00000000000000000F0000000000000100000000000000000000000000000000 + relocations: + - address: 0x00000000 + symbolnum: 1 + pcrel: false + length: 3 + extern: false + type: 0 + scattered: false + value: 0 + - cmd: LC_SYMTAB + cmdsize: 24 + symoff: 592 + nsyms: 1 + stroff: 608 + strsize: 8 + - cmd: LC_DYSYMTAB + cmdsize: 80 + ilocalsym: 0 + nlocalsym: 0 + iextdefsym: 0 + nextdefsym: 1 + iundefsym: 1 + nundefsym: 0 + tocoff: 0 + ntoc: 0 + modtaboff: 0 + nmodtab: 0 + extrefsymoff: 0 + nextrefsyms: 0 + indirectsymoff: 0 + nindirectsyms: 0 + extreloff: 0 + nextrel: 0 + locreloff: 0 + nlocrel: 0 +LinkEditData: + NameList: + - n_strx: 1 + n_type: 0x0F + n_sect: 1 + n_desc: 0 + n_value: 0 + StringTable: + - '' + - _main + - '' +... +#--- bar.yaml +--- !mach-o +FileHeader: + magic: 0xFEEDFACF + cputype: 0x01000007 + cpusubtype: 0x00000003 + filetype: 0x00000001 + ncmds: 2 + sizeofcmds: 384 + flags: 0x00002000 + reserved: 0x00000000 +LoadCommands: + - cmd: LC_SEGMENT_64 + cmdsize: 312 + segname: '' + vmaddr: 0 + vmsize: 200 + fileoff: 448 + filesize: 200 + maxprot: 7 + initprot: 7 + nsects: 3 + flags: 0 + Sections: + - sectname: __text + segname: __TEXT + addr: 0x0000000000000000 + size: 27 + offset: 0x000001C0 + align: 4 + reloff: 0x00000000 + nreloc: 0 + flags: 0x80000400 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + content: 554889E5B87B0000005DC30F1F440000554889E5B8EA0000005DC3 + - sectname: __eh_frame + segname: __TEXT + addr: 0x0000000000000020 + size: 104 + offset: 0x000001E0 + align: 3 + reloff: 0x00000288 + nreloc: 8 + flags: 0x00000000 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + content: 1400000000000000017A520001781001100C0708900100002400000004000000F8FFFFFFFFFFFFFF0B0000000000000000410E108602430D06000000000000002400000004000000F8FFFFFFFFFFFFFF0B0000000000000000410E108602430D0600000000000000 + relocations: + - address: 0x0000001C + symbolnum: 0 + pcrel: false + length: 2 + extern: true + type: 5 + scattered: false + value: 0 + - address: 0x0000001C + symbolnum: 1 + pcrel: false + length: 2 + extern: true + type: 0 + scattered: false + value: 0 + - address: 0x00000020 + symbolnum: 1 + pcrel: false + length: 3 + extern: true + type: 5 + scattered: false + value: 0 + - address: 0x00000020 + symbolnum: 15 + pcrel: false + length: 3 + extern: true + type: 0 + scattered: false + value: 0 + - address: 0x00000044 + symbolnum: 0 + pcrel: false + length: 2 + extern: true + type: 5 + scattered: false + value: 0 + - address: 0x00000044 + symbolnum: 2 + pcrel: false + length: 2 + extern: true + type: 0 + scattered: false + value: 0 + - address: 0x00000048 + symbolnum: 2 + pcrel: false + length: 3 + extern: true + type: 5 + scattered: false + value: 0 + - address: 0x00000048 + symbolnum: 16 + pcrel: false + length: 3 + extern: true + type: 0 + scattered: false + value: 0 + - sectname: __compact_unwind + segname: __LD + addr: 0x0000000000000088 + size: 64 + offset: 0x00000248 + align: 3 + reloff: 0x000002C8 + nreloc: 2 + flags: 0x02000000 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + content: 000000000000000010000000000000010000000000000000000000000000000000000000000000000B0000000000000100000000000000000000000000000000 + relocations: + - address: 0x00000000 + symbolnum: 15 + pcrel: false + length: 3 + extern: true + type: 0 + scattered: false + value: 0 + - address: 0x00000020 + symbolnum: 16 + pcrel: false + length: 3 + extern: true + type: 0 + scattered: false + value: 0 + - cmd: LC_SYMTAB + cmdsize: 24 + symoff: 728 + nsyms: 17 + stroff: 1000 + strsize: 160 +LinkEditData: + NameList: + - n_strx: 14 + n_type: 0x0E + n_sect: 2 + n_desc: 0 + n_value: 32 + - n_strx: 24 + n_type: 0x0E + n_sect: 2 + n_desc: 0 + n_value: 56 + - n_strx: 24 + n_type: 0x0E + n_sect: 2 + n_desc: 0 + n_value: 96 + - n_strx: 32 + n_type: 0x64 + n_sect: 0 + n_desc: 0 + n_value: 0 + - n_strx: 81 + n_type: 0x64 + n_sect: 0 + n_desc: 0 + n_value: 0 + - n_strx: 87 + n_type: 0x66 + n_sect: 3 + n_desc: 1 + n_value: 1625795159 + - n_strx: 1 + n_type: 0x2E + n_sect: 1 + n_desc: 0 + n_value: 0 + - n_strx: 147 + n_type: 0x24 + n_sect: 1 + n_desc: 0 + n_value: 0 + - n_strx: 1 + n_type: 0x24 + n_sect: 0 + n_desc: 0 + n_value: 16 + - n_strx: 1 + n_type: 0x4E + n_sect: 1 + n_desc: 0 + n_value: 16 + - n_strx: 1 + n_type: 0x2E + n_sect: 1 + n_desc: 0 + n_value: 16 + - n_strx: 153 + n_type: 0x24 + n_sect: 1 + n_desc: 0 + n_value: 16 + - n_strx: 1 + n_type: 0x24 + n_sect: 0 + n_desc: 0 + n_value: 11 + - n_strx: 1 + n_type: 0x64 + n_sect: 1 + n_desc: 0 + n_value: 0 + - n_strx: 2 + n_type: 0x0F + n_sect: 1 + n_desc: 0 + n_value: 0 + - n_strx: 8 + n_type: 0x0F + n_sect: 1 + n_desc: 0 + n_value: 16 + StringTable: + - ' ' + - _getX +...