From 4f17a54bfaafb639cd74250917cad5974b04d69a Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 7 Oct 2014 03:19:55 +0000 Subject: [PATCH] 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 --- test/tools/gold/Inputs/comdat.ll | 2 +- test/tools/gold/comdat.ll | 2 +- tools/gold/gold-plugin.cpp | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/test/tools/gold/Inputs/comdat.ll b/test/tools/gold/Inputs/comdat.ll index 4767fe78796b..e9e4704cc1ba 100644 --- a/test/tools/gold/Inputs/comdat.ll +++ b/test/tools/gold/Inputs/comdat.ll @@ -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 diff --git a/test/tools/gold/comdat.ll b/test/tools/gold/comdat.ll index 7b1fbd617c0d..ba3abce91a91 100644 --- a/test/tools/gold/comdat.ll +++ b/test/tools/gold/comdat.ll @@ -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: diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp index eb66ab8b0e81..ffee1ff3258b 100644 --- a/tools/gold/gold-plugin.cpp +++ b/tools/gold/gold-plugin.cpp @@ -491,8 +491,8 @@ static GlobalObject *makeInternalReplacement(GlobalObject *GO) { Module *M = GO->getParent(); GlobalObject *Ret; if (auto *F = dyn_cast(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(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;