diff options
author | Teresa Johnson <tejohnson@google.com> | 2015-11-04 16:01:16 +0000 |
---|---|---|
committer | Teresa Johnson <tejohnson@google.com> | 2015-11-04 16:01:16 +0000 |
commit | f1b0a6e37c4d25c321fb7a30917e571f6eb777c8 (patch) | |
tree | cfc7cb8821272827aaa8a9f4879b9368501a0608 | |
parent | ef731a9edc556f26544d3873fe28b58e4e33e61c (diff) | |
download | bcm5719-llvm-f1b0a6e37c4d25c321fb7a30917e571f6eb777c8.tar.gz bcm5719-llvm-f1b0a6e37c4d25c321fb7a30917e571f6eb777c8.zip |
[ThinLTO] Always set linkage type to external when converting alias
When converting an alias to a non-alias when the aliasee is not
imported, ensure that the linkage type is set to external so that it is
a valid linkage type. Added a test case that exposed this issue.
llvm-svn: 252054
-rw-r--r-- | llvm/lib/Linker/LinkModules.cpp | 6 | ||||
-rw-r--r-- | llvm/test/Linker/funcimport.ll | 11 |
2 files changed, 15 insertions, 2 deletions
diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp index b7aab9e9644..a855ec06d17 100644 --- a/llvm/lib/Linker/LinkModules.cpp +++ b/llvm/lib/Linker/LinkModules.cpp @@ -841,10 +841,12 @@ GlobalValue *ModuleLinker::copyGlobalAliasProto(TypeMapTy &TypeMap, assert(F); NewGV = copyFunctionProto(TypeMap, F); } - // Set the linkage to ExternalWeak, see also comments in - // ModuleLinker::getLinkage. + // Set the linkage to External or ExternalWeak (see comments in + // ModuleLinker::getLinkage for why WeakAny is converted to ExternalWeak). if (SGA->hasWeakAnyLinkage()) NewGV->setLinkage(GlobalValue::ExternalWeakLinkage); + else + NewGV->setLinkage(GlobalValue::ExternalLinkage); // Don't attempt to link body, needs to be a declaration. DoNotLinkFromSource.insert(SGA); return NewGV; diff --git a/llvm/test/Linker/funcimport.ll b/llvm/test/Linker/funcimport.ll index 1b9a08694d8..97a34ffd233 100644 --- a/llvm/test/Linker/funcimport.ll +++ b/llvm/test/Linker/funcimport.ll @@ -14,11 +14,16 @@ ; Ensure that both weak alias to an imported function and strong alias to a ; non-imported function are correctly turned into declarations. +; Also ensures that alias to a linkonce function is turned into a declaration +; and that the associated linkonce function is not in the output, as it is +; lazily linked and never referenced/materialized. ; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=globalfunc1:%t.bc -S | FileCheck %s --check-prefix=IMPORTGLOB1 ; IMPORTGLOB1: define available_externally void @globalfunc1 ; IMPORTGLOB1: declare void @globalfunc2 ; IMPORTGLOB1: declare extern_weak void @weakalias ; IMPORTGLOB1: declare void @analias +; IMPORTGLOB1: declare void @linkoncealias +; IMPORTGLOB1-NOT: @linkoncefunc ; Ensure that weak alias to a non-imported function is correctly ; turned into a declaration, but that strong alias to an imported function @@ -91,6 +96,7 @@ @weakalias = weak alias void (...), bitcast (void ()* @globalfunc1 to void (...)*) @analias = alias void (...), bitcast (void ()* @globalfunc2 to void (...)*) +@linkoncealias = alias void (...), bitcast (void ()* @linkoncefunc to void (...)*) define void @globalfunc1() #0 { entry: @@ -102,6 +108,11 @@ entry: ret void } +define linkonce_odr void @linkoncefunc() #0 { +entry: + ret void +} + define i32 @referencestatics(i32 %i) #0 { entry: %i.addr = alloca i32, align 4 |