@@ -56,16 +56,28 @@ using namespace llvm::yaml;
56
56
using StringSet = llvm::StringSet<>;
57
57
using SymbolKind = llvm::MachO::SymbolKind;
58
58
59
+ static constexpr StringLiteral ObjC2ClassNamePrefix = " _OBJC_CLASS_$_" ;
60
+ static constexpr StringLiteral ObjC2MetaClassNamePrefix = " _OBJC_METACLASS_$_" ;
61
+
59
62
static bool isGlobalOrStaticVar (VarDecl *VD) {
60
63
return VD->isStatic () || VD->getDeclContext ()->isModuleScopeContext ();
61
64
}
62
65
66
+ // If a symbol is implied, we don't need to emit it explictly into the tbd file.
67
+ // e.g. When a symbol is in the `objc-classes` section in a tbd file, a additional
68
+ // symbol with `_OBJC_CLASS_$_` is implied.
69
+ static bool isSymbolImplied (StringRef name) {
70
+ return name.startswith (ObjC2ClassNamePrefix) ||
71
+ name.startswith (ObjC2MetaClassNamePrefix);
72
+ }
73
+
63
74
void TBDGenVisitor::addSymbolInternal (StringRef name,
64
75
llvm::MachO::SymbolKind kind,
65
76
bool isLinkerDirective) {
66
77
if (!isLinkerDirective && Opts.LinkerDirectivesOnly )
67
78
return ;
68
- Symbols.addSymbol (kind, name, Targets);
79
+ if (!isSymbolImplied (name))
80
+ Symbols.addSymbol (kind, name, Targets);
69
81
if (StringSymbols && kind == SymbolKind::GlobalSymbol) {
70
82
auto isNewValue = StringSymbols->insert (name).second ;
71
83
(void )isNewValue;
0 commit comments