diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -391,13 +391,35 @@ umbrella = this; dylibName = saver.save(interface->getInstallName()); + auto addSymbol = [&](const Twine &name) -> void { + symbols.push_back(symtab->addDylib(saver.save(name), umbrella, + /*isWeakDef=*/false, + /*isTlv=*/false)); + }; // TODO(compnerd) filter out symbols based on the target platform // TODO: handle weak defs, thread locals - for (const auto symbol : interface->symbols()) - if (symbol->getArchitectures().has(config->arch)) - symbols.push_back(symtab->addDylib(saver.save(symbol->getName()), - umbrella, /*isWeakDef=*/false, - /*isTlv=*/false)); + for (const auto symbol : interface->symbols()) { + if (!symbol->getArchitectures().has(config->arch)) + continue; + + switch (symbol->getKind()) { + case SymbolKind::GlobalSymbol: + addSymbol(symbol->getName()); + break; + case SymbolKind::ObjectiveCClass: + // XXX ld64 only creates these symbols when -ObjC is passed in. We may + // want to emulate that. + addSymbol("_OBJC_CLASS_$_" + symbol->getName()); + addSymbol("_OBJC_METACLASS_$_" + symbol->getName()); + break; + case SymbolKind::ObjectiveCClassEHType: + addSymbol("_OBJC_EHTYPE_$_" + symbol->getName()); + break; + case SymbolKind::ObjectiveCInstanceVariable: + addSymbol("_OBJC_IVAR_$_" + symbol->getName()); + break; + } + } // TODO(compnerd) properly represent the hierarchy of the documents as it is // in theory possible to have re-exported dylibs from re-exported dylibs which // should be parent'ed to the child. diff --git a/lld/test/MachO/Inputs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation.tbd b/lld/test/MachO/Inputs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation.tbd --- a/lld/test/MachO/Inputs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation.tbd +++ b/lld/test/MachO/Inputs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation.tbd @@ -6,5 +6,8 @@ current-version: 0001.001.1 compatibility-version: 150 exports: - - archs: [ 'x86_64' ] - symbols: [ '__CFBigNumGetInt128' ] + - archs: [ 'x86_64' ] + symbols: [ '__CFBigNumGetInt128' ] + objc-classes: [ NSObject ] + objc-ivars: [ NSConstantArray._count ] + objc-eh-types: [ NSException ] diff --git a/lld/test/MachO/stub-link.s b/lld/test/MachO/stub-link.s --- a/lld/test/MachO/stub-link.s +++ b/lld/test/MachO/stub-link.s @@ -3,7 +3,7 @@ # RUN: mkdir -p %t # # RUN: llvm-mc -filetype obj -triple x86_64-apple-darwin %s -o %t/test.o -# RUN: lld -flavor darwinnew -o %t/test -Z -L%S/Inputs/MacOSX.sdk/usr/lib -lSystem %t/test.o +# RUN: lld -flavor darwinnew -o %t/test -syslibroot %S/Inputs/MacOSX.sdk -lSystem -framework CoreFoundation %t/test.o # # RUN: llvm-objdump --bind --no-show-raw-insn -d -r %t/test | FileCheck %s @@ -11,7 +11,11 @@ # CHECK: movq {{.*}} # [[ADDR:[0-9a-f]+]] # CHECK: Bind table: -# CHECK: __DATA_CONST __got 0x[[ADDR]] pointer 0 libSystem ___nan +# CHECK-DAG: __DATA_CONST __got 0x[[ADDR]] pointer 0 libSystem ___nan +# CHECK-DAG: __DATA __data {{.*}} pointer 0 CoreFoundation _OBJC_CLASS_$_NSObject +# CHECK-DAG: __DATA __data {{.*}} pointer 0 CoreFoundation _OBJC_METACLASS_$_NSObject +# CHECK-DAG: __DATA __data {{.*}} pointer 0 CoreFoundation _OBJC_IVAR_$_NSConstantArray._count +# CHECK-DAG: __DATA __data {{.*}} pointer 0 CoreFoundation _OBJC_EHTYPE_$_NSException .section __TEXT,__text .global _main @@ -19,3 +23,9 @@ _main: movq ___nan@GOTPCREL(%rip), %rax ret + +.data + .quad _OBJC_CLASS_$_NSObject + .quad _OBJC_METACLASS_$_NSObject + .quad _OBJC_IVAR_$_NSConstantArray._count + .quad _OBJC_EHTYPE_$_NSException