Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
gold plugin: create internal replacement with original linkage first.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
espindola committed Oct 7, 2014
1 parent 3ddd4fa commit 4f17a54
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion test/tools/gold/Inputs/comdat.ll
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/tools/gold/comdat.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions tools/gold/gold-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down

0 comments on commit 4f17a54

Please sign in to comment.