Index: lld/MachO/Driver.cpp =================================================================== --- lld/MachO/Driver.cpp +++ lld/MachO/Driver.cpp @@ -224,7 +224,7 @@ return CHECK(parseCachePruningPolicy(ltoPolicy), "invalid LTO cache policy"); } -static DenseMap loadedArchives; +static DenseMap loadedArchives; static InputFile *addFile(StringRef path, bool forceLoadArchive, bool isExplicit = true, bool isBundleLoader = false) { @@ -234,6 +234,7 @@ MemoryBufferRef mbref = *buffer; InputFile *newFile = nullptr; + hash_code hashedPath = hash_value(path); file_magic magic = identify_magic(mbref.getBuffer()); switch (magic) { case file_magic::archive: { @@ -243,7 +244,7 @@ // We don't take a reference to cachedFile here because the // loadArchiveMember() call below may recursively call addFile() and // invalidate this reference. - if (ArchiveFile *cachedFile = loadedArchives[path]) + if (ArchiveFile *cachedFile = loadedArchives[hashedPath]) return cachedFile; std::unique_ptr archive = CHECK( @@ -290,7 +291,7 @@ } file->addLazySymbols(); - newFile = loadedArchives[path] = file; + newFile = loadedArchives[hashedPath] = file; break; } case file_magic::macho_object: Index: lld/test/MachO/Inputs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation.tbd =================================================================== --- lld/test/MachO/Inputs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation.tbd +++ lld/test/MachO/Inputs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation.tbd @@ -7,7 +7,7 @@ compatibility-version: 150 exports: - archs: [ 'x86_64' ] - symbols: [ __CFBigNumGetInt128, ___CFConstantStringClassReference ] + symbols: [ __CFBigNumGetInt128, ___CFConstantStringClassReference, __objc_empty_cache ] objc-classes: [ NSObject ] objc-ivars: [ NSConstantArray._count ] objc-eh-types: [ NSException ] Index: lld/test/MachO/multi-loaded-archive.yaml =================================================================== --- /dev/null +++ lld/test/MachO/multi-loaded-archive.yaml @@ -0,0 +1,407 @@ +# REQUIRES: x86 +# RUN: rm -rf %t; split-file %s %t +# RUN: yaml2obj %t/objFile1.yaml > %t/objFile1.o +# RUN: yaml2obj %t/objFile2.yaml > %t/objFile2.o +# RUN: yaml2obj %t/foo.yaml > %t/foo.o +# RUN: yaml2obj %t/main.yaml > %t/main.o +# RUN: mkdir -p %t/Foo.framework/Versions/A +# RUN: llvm-ar rcs %t/Foo.framework/Versions/A/Foo %t/foo.o +# RUN: ln -sf A %t/Foo.framework/Versions/Current +# RUN: ln -sf Versions/Current/Foo %t/Foo.framework/Foo +# RUN: %lld -demangle -ObjC -syslibroot %S/Inputs/MacOSX.sdk -o main.out %t/main.o %t/objFile1.o %t/objFile2.o -framework foo -F%t -framework CoreFoundation + +#--- objFile1.yaml +--- !mach-o +FileHeader: + magic: 0xFEEDFACF + cputype: 0x1000007 + cpusubtype: 0x3 + filetype: 0x1 + ncmds: 2 + sizeofcmds: 280 + flags: 0x2000 + reserved: 0x0 +LoadCommands: + - cmd: LC_SEGMENT_64 + cmdsize: 152 + segname: '' + vmaddr: 0 + vmsize: 21 + fileoff: 312 + filesize: 21 + maxprot: 7 + initprot: 7 + nsects: 0 + flags: 0 + - cmd: LC_LINKER_OPTION + cmdsize: 32 + count: 2 + PayloadBytes: [ 0x2D, 0x66, 0x72, 0x61, 0x6D, 0x65, 0x77, 0x6F, + 0x72, 0x6B, 0x0, 0x66, 0x6f, 0x6f, 0x0 ] +... + +#--- objFile2.yaml +--- !mach-o +FileHeader: + magic: 0xFEEDFACF + cputype: 0x1000007 + cpusubtype: 0x3 + filetype: 0x1 + ncmds: 2 + sizeofcmds: 280 + flags: 0x2000 + reserved: 0x0 +LoadCommands: + - cmd: LC_SEGMENT_64 + cmdsize: 152 + segname: '' + vmaddr: 0 + vmsize: 21 + fileoff: 312 + filesize: 21 + maxprot: 7 + initprot: 7 + nsects: 0 + flags: 0 + - cmd: LC_LINKER_OPTION + cmdsize: 32 + count: 2 + PayloadBytes: [ 0x2D, 0x66, 0x72, 0x61, 0x6D, 0x65, 0x77, 0x6F, + 0x72, 0x6B, 0x0, 0x66, 0x6f, 0x6f, 0x0 ] +... + +#--- main.yaml +--- !mach-o +FileHeader: + magic: 0xFEEDFACF + cputype: 0x1000007 + cpusubtype: 0x3 + filetype: 0x1 + ncmds: 2 + sizeofcmds: 976 + flags: 0x2000 + reserved: 0x0 +LoadCommands: + - cmd: LC_SEGMENT_64 + cmdsize: 392 + segname: '' + vmaddr: 0 + vmsize: 112 + fileoff: 1008 + filesize: 112 + maxprot: 7 + initprot: 7 + nsects: 4 + flags: 0 + Sections: + - sectname: __text + segname: __TEXT + addr: 0x0 + size: 8 + offset: 0x3F0 + align: 0 + reloff: 0x0 + nreloc: 0 + flags: 0x80000400 + reserved1: 0x0 + reserved2: 0x0 + reserved3: 0x0 + content: 554889E531C05DC3 + - sectname: __objc_imageinfo + segname: __DATA + addr: 0x8 + size: 8 + offset: 0x3F8 + align: 0 + reloff: 0x0 + nreloc: 0 + flags: 0x10000000 + reserved1: 0x0 + reserved2: 0x0 + reserved3: 0x0 + content: '0000000040000000' + - sectname: __compact_unwind + segname: __LD + addr: 0x10 + size: 32 + offset: 0x400 + align: 3 + reloff: 0x460 + nreloc: 1 + flags: 0x2000000 + reserved1: 0x0 + reserved2: 0x0 + reserved3: 0x0 + content: '0000000000000000080000000000000100000000000000000000000000000000' + relocations: + - address: 0x0 + symbolnum: 1 + pcrel: false + length: 3 + extern: false + type: 0 + scattered: false + value: 0 + - sectname: __eh_frame + segname: __TEXT + addr: 0x30 + size: 64 + offset: 0x420 + align: 3 + reloff: 0x0 + nreloc: 0 + flags: 0x6800000B + reserved1: 0x0 + reserved2: 0x0 + reserved3: 0x0 + content: 1400000000000000017A520001781001100C070890010000240000001C000000B0FFFFFFFFFFFFFF080000000000000000410E108602430D0600000000000000 + - cmd: LC_SYMTAB + cmdsize: 24 + symoff: 1128 + nsyms: 1 + stroff: 1144 + strsize: 8 +LinkEditData: + NameList: + - n_strx: 1 + n_type: 0x1F + n_sect: 1 + n_desc: 0 + n_value: 0 + StringTable: + - '' + - _main + - '' +... + + +#--- foo.yaml +--- !mach-o +FileHeader: + magic: 0xFEEDFACF + cputype: 0x1000007 + cpusubtype: 0x3 + filetype: 0x1 + ncmds: 2 + sizeofcmds: 680 + flags: 0x2000 + reserved: 0x0 +LoadCommands: + - cmd: LC_SEGMENT_64 + cmdsize: 552 + segname: '' + vmaddr: 0 + vmsize: 256 + fileoff: 712 + filesize: 256 + maxprot: 7 + initprot: 7 + nsects: 6 + flags: 0 + Sections: + - sectname: __text + segname: __TEXT + addr: 0x0 + size: 0 + offset: 0x2C8 + align: 0 + reloff: 0x0 + nreloc: 0 + flags: 0x80000000 + reserved1: 0x0 + reserved2: 0x0 + reserved3: 0x0 + content: '' + - sectname: __objc_data + segname: __DATA + addr: 0x0 + size: 80 + offset: 0x2C8 + align: 3 + reloff: 0x3C8 + nreloc: 7 + flags: 0x0 + reserved1: 0x0 + reserved2: 0x0 + reserved3: 0x0 + content: '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' + relocations: + - address: 0x48 + symbolnum: 1 + pcrel: false + length: 3 + extern: true + type: 0 + scattered: false + value: 0 + - address: 0x38 + symbolnum: 4 + pcrel: false + length: 3 + extern: true + type: 0 + scattered: false + value: 0 + - address: 0x30 + symbolnum: 2 + pcrel: false + length: 3 + extern: true + type: 0 + scattered: false + value: 0 + - address: 0x28 + symbolnum: 3 + pcrel: false + length: 3 + extern: true + type: 0 + scattered: false + value: 0 + - address: 0x20 + symbolnum: 0 + 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: 0x0 + symbolnum: 3 + pcrel: false + length: 3 + extern: true + type: 0 + scattered: false + value: 0 + - sectname: __objc_classname + segname: __TEXT + addr: 0x50 + size: 10 + offset: 0x318 + align: 0 + reloff: 0x0 + nreloc: 0 + flags: 0x2 + reserved1: 0x0 + reserved2: 0x0 + reserved3: 0x0 + content: 54657374436C61737300 + - sectname: __objc_const + segname: __DATA + addr: 0x60 + size: 144 + offset: 0x328 + align: 3 + reloff: 0x400 + nreloc: 2 + flags: 0x0 + reserved1: 0x0 + reserved2: 0x0 + reserved3: 0x0 + content: '030000002800000028000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' + relocations: + - address: 0x60 + symbolnum: 3 + pcrel: false + length: 3 + extern: false + type: 0 + scattered: false + value: 0 + - address: 0x18 + symbolnum: 3 + pcrel: false + length: 3 + extern: false + type: 0 + scattered: false + value: 0 + - sectname: __objc_classlist + segname: __DATA + addr: 0xF0 + size: 8 + offset: 0x3B8 + align: 3 + reloff: 0x410 + nreloc: 1 + flags: 0x10000000 + reserved1: 0x0 + reserved2: 0x0 + reserved3: 0x0 + content: '0000000000000000' + relocations: + - address: 0x0 + symbolnum: 2 + pcrel: false + length: 3 + extern: true + type: 0 + scattered: false + value: 0 + - sectname: __objc_imageinfo + segname: __DATA + addr: 0xF8 + size: 8 + offset: 0x3C0 + align: 0 + reloff: 0x0 + nreloc: 0 + flags: 0x10000000 + reserved1: 0x0 + reserved2: 0x0 + reserved3: 0x0 + content: '0000000040000000' + - cmd: LC_SYMTAB + cmdsize: 24 + symoff: 1048 + nsyms: 5 + stroff: 1128 + strsize: 136 +LinkEditData: + NameList: + - n_strx: 53 + n_type: 0xE + n_sect: 4 + n_desc: 0 + n_value: 168 + - n_strx: 81 + n_type: 0xE + n_sect: 4 + n_desc: 0 + n_value: 96 + - n_strx: 1 + n_type: 0xF + n_sect: 2 + n_desc: 0 + n_value: 0 + - n_strx: 25 + n_type: 0xF + n_sect: 2 + n_desc: 0 + n_value: 40 + - n_strx: 113 + n_type: 0x1 + n_sect: 0 + n_desc: 0 + n_value: 0 + StringTable: + - '' + - '_OBJC_CLASS_$_TestClass' + - '_OBJC_METACLASS_$_TestClass' + - '__OBJC_CLASS_RO_$_TestClass' + - '__OBJC_METACLASS_RO_$_TestClass' + - __objc_empty_cache + - '' + - '' + - '' + - '' +...