Skip to content
Open
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
10 changes: 10 additions & 0 deletions include/swift/IRGen/Linking.h
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,16 @@ class LinkEntity {
bool isTypeKind() const { return isTypeKind(getKind()); }

bool isAlwaysSharedLinkage() const;

/// Partial apply forwarders always need real private linkage,
/// to ensure the correct implementation is used in case of
/// colliding symbols.
bool privateMeansPrivate() const {
return getKind() == Kind::PartialApplyForwarder ||
getKind() == Kind::PartialApplyForwarderAsyncFunctionPointer ||
getKind() == Kind::PartialApplyForwarderCoroFunctionPointer;
}

#undef LINKENTITY_GET_FIELD
#undef LINKENTITY_SET_FIELD

Expand Down
33 changes: 18 additions & 15 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2242,10 +2242,10 @@ void IRGenerator::emitEntryPointInfo() {
IGM.addUsedGlobal(var);
}

static IRLinkage
getIRLinkage(StringRef name, const UniversalLinkageInfo &info,
SILLinkage linkage, ForDefinition_t isDefinition,
bool isWeakImported, bool isKnownLocal = false) {
static IRLinkage getIRLinkage(StringRef name, const UniversalLinkageInfo &info,
SILLinkage linkage, ForDefinition_t isDefinition,
bool isWeakImported, bool isKnownLocal,
bool privateMeansPrivate) {
#define RESULT(LINKAGE, VISIBILITY, DLL_STORAGE) \
IRLinkage{llvm::GlobalValue::LINKAGE##Linkage, \
llvm::GlobalValue::VISIBILITY##Visibility, \
Expand Down Expand Up @@ -2302,12 +2302,14 @@ getIRLinkage(StringRef name, const UniversalLinkageInfo &info,
case SILLinkage::Private: {
if (info.forcePublicDecls() && !isDefinition)
return getIRLinkage(name, info, SILLinkage::PublicExternal, isDefinition,
isWeakImported, isKnownLocal);

auto linkage = info.needLinkerToMergeDuplicateSymbols()
? llvm::GlobalValue::LinkOnceODRLinkage
: llvm::GlobalValue::InternalLinkage;
auto visibility = info.shouldAllPrivateDeclsBeVisibleFromOtherFiles()
isWeakImported, isKnownLocal, privateMeansPrivate);

auto linkage =
info.needLinkerToMergeDuplicateSymbols() && !privateMeansPrivate
? llvm::GlobalValue::LinkOnceODRLinkage
: llvm::GlobalValue::InternalLinkage;
auto visibility = info.shouldAllPrivateDeclsBeVisibleFromOtherFiles() &&
!privateMeansPrivate
? llvm::GlobalValue::HiddenVisibility
: llvm::GlobalValue::DefaultVisibility;
return {linkage, visibility, llvm::GlobalValue::DefaultStorageClass};
Expand Down Expand Up @@ -2358,7 +2360,7 @@ void irgen::updateLinkageForDefinition(IRGenModule &IGM,
auto IRL =
getIRLinkage(global->hasName() ? global->getName() : StringRef(),
linkInfo, entity.getLinkage(ForDefinition), ForDefinition,
weakImported, isKnownLocal);
weakImported, isKnownLocal, entity.privateMeansPrivate());
ApplyIRLinkage(IRL).to(global);

LinkInfo link = LinkInfo::get(IGM, entity, ForDefinition);
Expand Down Expand Up @@ -2409,9 +2411,9 @@ LinkInfo LinkInfo::get(const UniversalLinkageInfo &linkInfo,
}

bool weakImported = entity.isWeakImported(swiftModule);
result.IRL = getIRLinkage(result.Name, linkInfo,
entity.getLinkage(isDefinition), isDefinition,
weakImported, isKnownLocal);
result.IRL = getIRLinkage(
result.Name, linkInfo, entity.getLinkage(isDefinition), isDefinition,
weakImported, isKnownLocal, entity.privateMeansPrivate());
result.ForDefinition = isDefinition;
return result;
}
Expand All @@ -2422,7 +2424,8 @@ LinkInfo LinkInfo::get(const UniversalLinkageInfo &linkInfo, StringRef name,
LinkInfo result;
result.Name += name;
result.IRL = getIRLinkage(name, linkInfo, linkage, isDefinition,
isWeakImported, linkInfo.Internalize);
isWeakImported, linkInfo.Internalize,
/*privateMeansPrivate=*/false);
result.ForDefinition = isDefinition;
return result;
}
Expand Down
5 changes: 5 additions & 0 deletions test/IRGen/async/partial_apply_forwarder.sil
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ entry(%e : $EmptyType, %b : $WeakBox<τ_0_0>):
unreachable
}

// CHECK-DAG: @"$s7takingQTATu" = internal
// CHECK-DAG: @"$s11takingQAndSTATu" = internal
// CHECK-DAG: @"$s13inner_closureTATu" = internal
// CHECK-DAG: @"$s15returns_closureTATu" = internal

// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swift{{(tail)?}}cc void @bind_polymorphic_param_from_context(
// CHECK-LABEL: define internal swift{{(tail)?}}cc void @"$s7takingQTA"(
sil public @bind_polymorphic_param_from_context : $@async @convention(thin) <τ_0_1>(@in τ_0_1) -> @owned @async @callee_guaranteed () -> () {
Expand Down