[lld] a499898 - [lld-macho] Generate ObjC symbols from .tbd files
Jez Ng via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 12 19:51:03 PDT 2020
Author: Jez Ng
Date: 2020-08-12T19:50:10-07:00
New Revision: a499898e86ec322ed47b43aaabdd3fedbf58840a
URL: https://github.com/llvm/llvm-project/commit/a499898e86ec322ed47b43aaabdd3fedbf58840a
DIFF: https://github.com/llvm/llvm-project/commit/a499898e86ec322ed47b43aaabdd3fedbf58840a.diff
LOG: [lld-macho] Generate ObjC symbols from .tbd files
I followed similar logic in TapiFile.cpp.
Reviewed By: #lld-macho, smeenai
Differential Revision: https://reviews.llvm.org/D85255
Added:
Modified:
lld/MachO/InputFiles.cpp
lld/test/MachO/Inputs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation.tbd
lld/test/MachO/stub-link.s
Removed:
################################################################################
diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 5df42b358203..03573868146e 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -403,13 +403,35 @@ DylibFile::DylibFile(std::shared_ptr<llvm::MachO::InterfaceFile> interface,
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
index d9c6245b8033..ef122e667281 100644
--- 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 @@ install-name: '/System/Library/Frameworks/CoreFoundation.framework/CoreFound
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
index 1bf65c46a787..0d6b7fec3f2a 100644
--- 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 at GOTPCREL(%rip), %rax
ret
+
+.data
+ .quad _OBJC_CLASS_$_NSObject
+ .quad _OBJC_METACLASS_$_NSObject
+ .quad _OBJC_IVAR_$_NSConstantArray._count
+ .quad _OBJC_EHTYPE_$_NSException
More information about the llvm-commits
mailing list