Module *M = GO->getParent();
GlobalObject *Ret;
if (auto *F = dyn_cast<Function>(GO)) {
- auto *NewF = Function::Create(
- F->getFunctionType(), GlobalValue::InternalLinkage, F->getName(), M);
+ auto *NewF = Function::Create(F->getFunctionType(), F->getLinkage(),
+ F->getName(), M);
ValueToValueMapTy VM;
Function::arg_iterator NewI = NewF->arg_begin();
auto *Var = cast<GlobalVariable>(GO);
Ret = new GlobalVariable(
*M, Var->getType()->getElementType(), Var->isConstant(),
- GlobalValue::InternalLinkage, Var->getInitializer(), Var->getName(),
+ Var->getLinkage(), Var->getInitializer(), Var->getName(),
nullptr, Var->getThreadLocalMode(), Var->getType()->getAddressSpace(),
Var->isExternallyInitialized());
Var->setInitializer(nullptr);
}
Ret->copyAttributesFrom(GO);
+ Ret->setLinkage(GlobalValue::InternalLinkage);
Ret->setComdat(GO->getComdat());
return Ret;
keepGlobalValue(*GV, KeptAliases);
break;
- case LDPR_PREEMPTED_REG:
case LDPR_PREEMPTED_IR:
+ // Gold might have selected a linkonce_odr and preempted a weak_odr.
+ // In that case we have to make sure we don't end up internalizing it.
+ if (!GV->isDiscardableIfUnused())
+ Maybe.erase(Sym.name);
+
+ // fall-through
+ case LDPR_PREEMPTED_REG:
Drop.insert(GV);
break;