@@ -2215,6 +2215,17 @@ static bool hasUseOtherThanLLVMUsed(GlobalAlias &GA, const LLVMUsed &U) {
2215
2215
return !U.usedCount (&GA) && !U.compilerUsedCount (&GA);
2216
2216
}
2217
2217
2218
+ static bool hasMoreThanOneUseOtherThanLLVMUsed (GlobalValue &V,
2219
+ const LLVMUsed &U) {
2220
+ unsigned N = 2 ;
2221
+ assert ((!U.usedCount (&V) || !U.compilerUsedCount (&V)) &&
2222
+ " We should have removed the duplicated "
2223
+ " element from llvm.compiler.used" );
2224
+ if (U.usedCount (&V) || U.compilerUsedCount (&V))
2225
+ ++N;
2226
+ return V.hasNUsesOrMore (N);
2227
+ }
2228
+
2218
2229
static bool mayHaveOtherReferences (GlobalValue &GV, const LLVMUsed &U) {
2219
2230
if (!GV.hasLocalLinkage ())
2220
2231
return true ;
@@ -2224,8 +2235,6 @@ static bool mayHaveOtherReferences(GlobalValue &GV, const LLVMUsed &U) {
2224
2235
2225
2236
static bool hasUsesToReplace (GlobalAlias &GA, const LLVMUsed &U,
2226
2237
bool &RenameTarget) {
2227
- if (GA.isWeakForLinker ())
2228
- return false ;
2229
2238
2230
2239
RenameTarget = false ;
2231
2240
bool Ret = false ;
@@ -2245,6 +2254,13 @@ static bool hasUsesToReplace(GlobalAlias &GA, const LLVMUsed &U,
2245
2254
// define ... @a(...)
2246
2255
Constant *Aliasee = GA.getAliasee ();
2247
2256
GlobalValue *Target = cast<GlobalValue>(Aliasee->stripPointerCasts ());
2257
+ // Do not perform the transform if alias may be replaced at link time while
2258
+ // someone is using the aliasee (e.g., multiple aliases potentially target it
2259
+ // or someone calls it).
2260
+ if (GA.isWeakForLinker ())
2261
+ Ret = false ;
2262
+ if (hasMoreThanOneUseOtherThanLLVMUsed (*Target, U))
2263
+ return Ret;
2248
2264
if (mayHaveOtherReferences (*Target, U))
2249
2265
return Ret;
2250
2266
0 commit comments