@@ -2167,14 +2167,20 @@ void IRGenerator::emitEntryPointInfo() {
21672167}
21682168
21692169static IRLinkage
2170- getIRLinkage (const UniversalLinkageInfo &info, SILLinkage linkage ,
2171- ForDefinition_t isDefinition, bool isWeakImported ,
2172- bool isKnownLocal = false ) {
2170+ getIRLinkage (StringRef name, const UniversalLinkageInfo &info,
2171+ SILLinkage linkage, ForDefinition_t isDefinition ,
2172+ bool isWeakImported, bool isKnownLocal = false ) {
21732173#define RESULT (LINKAGE, VISIBILITY, DLL_STORAGE ) \
21742174 IRLinkage{llvm::GlobalValue::LINKAGE##Linkage, \
21752175 llvm::GlobalValue::VISIBILITY##Visibility, \
21762176 llvm::GlobalValue::DLL_STORAGE##StorageClass}
21772177
2178+ // This is a synthetic symbol that is referenced for `#dsohandle` and is never
2179+ // a definition but needs to be handled as a definition as it will be provided
2180+ // by the linker. This is a MSVC extension that is honoured by lld as well.
2181+ if (info.IsMSVCEnvironment && name == " __ImageBase" )
2182+ return RESULT (External, Default, Default);
2183+
21782184 // Use protected visibility for public symbols we define on ELF. ld.so
21792185 // doesn't support relative relocations at load time, which interferes with
21802186 // our metadata formats. Default visibility should suffice for other object
@@ -2208,7 +2214,7 @@ getIRLinkage(const UniversalLinkageInfo &info, SILLinkage linkage,
22082214
22092215 case SILLinkage::Private: {
22102216 if (info.forcePublicDecls () && !isDefinition)
2211- return getIRLinkage (info, SILLinkage::PublicExternal, isDefinition,
2217+ return getIRLinkage (name, info, SILLinkage::PublicExternal, isDefinition,
22122218 isWeakImported, isKnownLocal);
22132219
22142220 auto linkage = info.needLinkerToMergeDuplicateSymbols ()
@@ -2262,8 +2268,9 @@ void irgen::updateLinkageForDefinition(IRGenModule &IGM,
22622268 isKnownLocal = IGM.getSwiftModule () == MD || MD->isStaticLibrary ();
22632269
22642270 auto IRL =
2265- getIRLinkage (linkInfo, entity.getLinkage (ForDefinition),
2266- ForDefinition, weakImported, isKnownLocal);
2271+ getIRLinkage (global->hasName () ? global->getName () : StringRef (),
2272+ linkInfo, entity.getLinkage (ForDefinition), ForDefinition,
2273+ weakImported, isKnownLocal);
22672274 ApplyIRLinkage (IRL).to (global);
22682275
22692276 LinkInfo link = LinkInfo::get (IGM, entity, ForDefinition);
@@ -2297,8 +2304,9 @@ LinkInfo LinkInfo::get(const UniversalLinkageInfo &linkInfo,
22972304 }
22982305
22992306 bool weakImported = entity.isWeakImported (swiftModule);
2300- result.IRL = getIRLinkage (linkInfo, entity.getLinkage (isDefinition),
2301- isDefinition, weakImported, isKnownLocal);
2307+ result.IRL = getIRLinkage (result.Name , linkInfo,
2308+ entity.getLinkage (isDefinition), isDefinition,
2309+ weakImported, isKnownLocal);
23022310 result.ForDefinition = isDefinition;
23032311 return result;
23042312}
@@ -2308,8 +2316,8 @@ LinkInfo LinkInfo::get(const UniversalLinkageInfo &linkInfo, StringRef name,
23082316 bool isWeakImported) {
23092317 LinkInfo result;
23102318 result.Name += name;
2311- result.IRL = getIRLinkage (linkInfo, linkage, isDefinition, isWeakImported ,
2312- linkInfo.Internalize );
2319+ result.IRL = getIRLinkage (name, linkInfo, linkage, isDefinition,
2320+ isWeakImported, linkInfo.Internalize );
23132321 result.ForDefinition = isDefinition;
23142322 return result;
23152323}
0 commit comments