@@ -2167,14 +2167,20 @@ void IRGenerator::emitEntryPointInfo() {
2167
2167
}
2168
2168
2169
2169
static 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 ) {
2173
2173
#define RESULT (LINKAGE, VISIBILITY, DLL_STORAGE ) \
2174
2174
IRLinkage{llvm::GlobalValue::LINKAGE##Linkage, \
2175
2175
llvm::GlobalValue::VISIBILITY##Visibility, \
2176
2176
llvm::GlobalValue::DLL_STORAGE##StorageClass}
2177
2177
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
+
2178
2184
// Use protected visibility for public symbols we define on ELF. ld.so
2179
2185
// doesn't support relative relocations at load time, which interferes with
2180
2186
// our metadata formats. Default visibility should suffice for other object
@@ -2208,7 +2214,7 @@ getIRLinkage(const UniversalLinkageInfo &info, SILLinkage linkage,
2208
2214
2209
2215
case SILLinkage::Private: {
2210
2216
if (info.forcePublicDecls () && !isDefinition)
2211
- return getIRLinkage (info, SILLinkage::PublicExternal, isDefinition,
2217
+ return getIRLinkage (name, info, SILLinkage::PublicExternal, isDefinition,
2212
2218
isWeakImported, isKnownLocal);
2213
2219
2214
2220
auto linkage = info.needLinkerToMergeDuplicateSymbols ()
@@ -2262,8 +2268,9 @@ void irgen::updateLinkageForDefinition(IRGenModule &IGM,
2262
2268
isKnownLocal = IGM.getSwiftModule () == MD || MD->isStaticLibrary ();
2263
2269
2264
2270
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);
2267
2274
ApplyIRLinkage (IRL).to (global);
2268
2275
2269
2276
LinkInfo link = LinkInfo::get (IGM, entity, ForDefinition);
@@ -2297,8 +2304,9 @@ LinkInfo LinkInfo::get(const UniversalLinkageInfo &linkInfo,
2297
2304
}
2298
2305
2299
2306
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);
2302
2310
result.ForDefinition = isDefinition;
2303
2311
return result;
2304
2312
}
@@ -2308,8 +2316,8 @@ LinkInfo LinkInfo::get(const UniversalLinkageInfo &linkInfo, StringRef name,
2308
2316
bool isWeakImported) {
2309
2317
LinkInfo result;
2310
2318
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 );
2313
2321
result.ForDefinition = isDefinition;
2314
2322
return result;
2315
2323
}
0 commit comments