gold plugin: create internal replacement with original linkage first.

The call to copyAttributesFrom will copy the visibility, which might assert
if it were to produce something invalid like "internal hidden". We avoid it
by first creating the replacement with the original linkage and then setting
it to internal affter the call to copyAttributesFrom.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219184 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2014-10-07 03:19:55 +00:00
parent 3ddd4fa0dd
commit 4f17a54bfa
3 changed files with 6 additions and 5 deletions

View File

@ -1,7 +1,7 @@
$c2 = comdat any
@v1 = weak_odr global i32 41, comdat $c2
define weak_odr i32 @f1(i8* %this) comdat $c2 {
define weak_odr protected i32 @f1(i8* %this) comdat $c2 {
bb20:
store i8* %this, i8** null
br label %bb21

View File

@ -49,7 +49,7 @@ bb11:
; CHECK: @a23 = alias i32 (i8*)* @f12{{$}}
; CHECK: @a24 = alias bitcast (i32 (i8*)* @f12 to i16*)
; CHECK: define weak_odr i32 @f1(i8*) comdat $c1 {
; CHECK: define weak_odr protected i32 @f1(i8*) comdat $c1 {
; CHECK-NEXT: bb10:
; CHECK-NEXT: br label %bb11{{$}}
; CHECK: bb11:

View File

@ -491,8 +491,8 @@ static GlobalObject *makeInternalReplacement(GlobalObject *GO) {
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();
@ -514,12 +514,13 @@ static GlobalObject *makeInternalReplacement(GlobalObject *GO) {
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;