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

Commit 4f17a54

Browse files
committed
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
1 parent 3ddd4fa commit 4f17a54

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

test/tools/gold/Inputs/comdat.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
$c2 = comdat any
22

33
@v1 = weak_odr global i32 41, comdat $c2
4-
define weak_odr i32 @f1(i8* %this) comdat $c2 {
4+
define weak_odr protected i32 @f1(i8* %this) comdat $c2 {
55
bb20:
66
store i8* %this, i8** null
77
br label %bb21

test/tools/gold/comdat.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ bb11:
4949
; CHECK: @a23 = alias i32 (i8*)* @f12{{$}}
5050
; CHECK: @a24 = alias bitcast (i32 (i8*)* @f12 to i16*)
5151

52-
; CHECK: define weak_odr i32 @f1(i8*) comdat $c1 {
52+
; CHECK: define weak_odr protected i32 @f1(i8*) comdat $c1 {
5353
; CHECK-NEXT: bb10:
5454
; CHECK-NEXT: br label %bb11{{$}}
5555
; CHECK: bb11:

tools/gold/gold-plugin.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ static GlobalObject *makeInternalReplacement(GlobalObject *GO) {
491491
Module *M = GO->getParent();
492492
GlobalObject *Ret;
493493
if (auto *F = dyn_cast<Function>(GO)) {
494-
auto *NewF = Function::Create(
495-
F->getFunctionType(), GlobalValue::InternalLinkage, F->getName(), M);
494+
auto *NewF = Function::Create(F->getFunctionType(), F->getLinkage(),
495+
F->getName(), M);
496496

497497
ValueToValueMapTy VM;
498498
Function::arg_iterator NewI = NewF->arg_begin();
@@ -514,12 +514,13 @@ static GlobalObject *makeInternalReplacement(GlobalObject *GO) {
514514
auto *Var = cast<GlobalVariable>(GO);
515515
Ret = new GlobalVariable(
516516
*M, Var->getType()->getElementType(), Var->isConstant(),
517-
GlobalValue::InternalLinkage, Var->getInitializer(), Var->getName(),
517+
Var->getLinkage(), Var->getInitializer(), Var->getName(),
518518
nullptr, Var->getThreadLocalMode(), Var->getType()->getAddressSpace(),
519519
Var->isExternallyInitialized());
520520
Var->setInitializer(nullptr);
521521
}
522522
Ret->copyAttributesFrom(GO);
523+
Ret->setLinkage(GlobalValue::InternalLinkage);
523524
Ret->setComdat(GO->getComdat());
524525

525526
return Ret;

0 commit comments

Comments
 (0)