Skip to content

TBDGen: avoid emitting symbols with OBJC_CLASS and OBJC_METACLASS prefixes #30267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/TBDGen/TBDGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,28 @@ using namespace llvm::yaml;
using StringSet = llvm::StringSet<>;
using SymbolKind = llvm::MachO::SymbolKind;

static constexpr StringLiteral ObjC2ClassNamePrefix = "_OBJC_CLASS_$_";
static constexpr StringLiteral ObjC2MetaClassNamePrefix = "_OBJC_METACLASS_$_";

static bool isGlobalOrStaticVar(VarDecl *VD) {
return VD->isStatic() || VD->getDeclContext()->isModuleScopeContext();
}

// If a symbol is implied, we don't need to emit it explictly into the tbd file.
// e.g. When a symbol is in the `objc-classes` section in a tbd file, a additional
// symbol with `_OBJC_CLASS_$_` is implied.
static bool isSymbolImplied(StringRef name) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, please just comment out these two calls elsewhere in this file:

addSymbol(LinkEntity::forObjCClass(CD));
addSymbol(LinkEntity::forObjCMetaclass(CD));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do need them in the symbol sets for verifying against irgen.

return name.startswith(ObjC2ClassNamePrefix) ||
name.startswith(ObjC2MetaClassNamePrefix);
}

void TBDGenVisitor::addSymbolInternal(StringRef name,
llvm::MachO::SymbolKind kind,
bool isLinkerDirective) {
if (!isLinkerDirective && Opts.LinkerDirectivesOnly)
return;
Symbols.addSymbol(kind, name, Targets);
if (!isSymbolImplied(name))
Symbols.addSymbol(kind, name, Targets);
if (StringSymbols && kind == SymbolKind::GlobalSymbol) {
auto isNewValue = StringSymbols->insert(name).second;
(void)isNewValue;
Expand Down
12 changes: 12 additions & 0 deletions test/TBD/implied_objc_symbols.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// REQUIRES: VENDOR=apple
// RUN: %empty-directory(%t)

// RUN: echo "import Foundation" > %t/main.swift
// RUN: echo "@objc public class ObjCOnly {}" >> %t/main.swift
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -import-objc-header %S/Inputs/objc_class_header.h -validate-tbd-against-ir=missing %t/main.swift -disable-objc-attr-requires-foundation-module -emit-tbd -emit-tbd-path %t/main.tbd

// RUN: %FileCheck %s < %t/main.tbd

// CHECK: __TtC4test8ObjCOnly
// CHECK-NOT: _OBJC_CLASS_
// CHECK-NOT: _OBJC_METACLASS_