gold plugin: create internal replacement with original linkage first.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 7 Oct 2014 03:19:55 +0000 (03:19 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 7 Oct 2014 03:19:55 +0000 (03:19 +0000)
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
test/tools/gold/comdat.ll
tools/gold/gold-plugin.cpp

index 4767fe78796bc0c1e1568f611b051665477f1ce2..e9e4704cc1ba17130e4915abef5fc076b6f09c19 100644 (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
index 7b1fbd617c0d16e1a3ae69a9475edab3adc58b75..ba3abce91a91d20f102b8741e46c14067c80a3f3 100644 (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:
index eb66ab8b0e81ca5d3b1ac02dbcfdbea1abcd7637..ffee1ff3258b3ab21fe66e2f337c89ef741d6647 100644 (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;