Skip to content

IRGen: weak linkage is not supported on COFF, avoid it #20822

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

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion include/swift/IRGen/Linking.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class UniversalLinkageInfo {
public:
bool IsELFObject;
bool UseDLLStorage;
bool SupportsWeakLinkage;

/// True iff are multiple llvm modules.
bool HasMultipleIGMs;
Expand Down Expand Up @@ -1001,7 +1002,7 @@ class LinkEntity {
}

/// Determine whether this entity will be weak-imported.
bool isWeakImported(ModuleDecl *module) const;
bool isWeakImported(ModuleDecl *module, const UniversalLinkageInfo &LI) const;

/// Return the source file whose codegen should trigger emission of this
/// link entity, if one can be identified.
Expand Down
9 changes: 5 additions & 4 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1509,8 +1509,8 @@ void irgen::updateLinkageForDefinition(IRGenModule &IGM,
// entire linkage computation.
UniversalLinkageInfo linkInfo(IGM);
auto IRL =
getIRLinkage(linkInfo, entity.getLinkage(ForDefinition),
ForDefinition, entity.isWeakImported(IGM.getSwiftModule()));
getIRLinkage(linkInfo, entity.getLinkage(ForDefinition), ForDefinition,
entity.isWeakImported(IGM.getSwiftModule(), linkInfo));
ApplyIRLinkage(IRL).to(global);

// Everything externally visible is considered used in Swift.
Expand Down Expand Up @@ -1545,8 +1545,9 @@ LinkInfo LinkInfo::get(const UniversalLinkageInfo &linkInfo,
ForDefinition_t(swiftModule->isStdlibModule() || isDefinition);

entity.mangle(result.Name);
result.IRL = getIRLinkage(linkInfo, entity.getLinkage(isStdlibOrDefinition),
isDefinition, entity.isWeakImported(swiftModule));
result.IRL =
getIRLinkage(linkInfo, entity.getLinkage(isStdlibOrDefinition),
isDefinition, entity.isWeakImported(swiftModule, linkInfo));
result.ForDefinition = isDefinition;
return result;
}
Expand Down
10 changes: 8 additions & 2 deletions lib/IRGen/Linking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ UniversalLinkageInfo::UniversalLinkageInfo(const llvm::Triple &triple,
bool hasMultipleIGMs,
bool isWholeModule)
: IsELFObject(triple.isOSBinFormatELF()),
UseDLLStorage(useDllStorage(triple)), HasMultipleIGMs(hasMultipleIGMs),
UseDLLStorage(useDllStorage(triple)),
SupportsWeakLinkage(!triple.isOSBinFormatCOFF()),
HasMultipleIGMs(hasMultipleIGMs),
IsWholeModule(isWholeModule) {}

/// Mangle this entity into the given buffer.
Expand Down Expand Up @@ -854,7 +856,11 @@ Alignment LinkEntity::getAlignment(IRGenModule &IGM) const {
}
}

bool LinkEntity::isWeakImported(ModuleDecl *module) const {
bool LinkEntity::isWeakImported(ModuleDecl *module,
const UniversalLinkageInfo &LI) const {
if (!LI.SupportsWeakLinkage)
return false;

switch (getKind()) {
case Kind::SILGlobalVariable:
if (getSILGlobalVariable()->getDecl())
Expand Down