]> granicus.if.org Git - llvm/commitdiff
[ThinLTO] Use original alias visibility when importing
authorTeresa Johnson <tejohnson@google.com>
Wed, 29 May 2019 16:50:46 +0000 (16:50 +0000)
committerTeresa Johnson <tejohnson@google.com>
Wed, 29 May 2019 16:50:46 +0000 (16:50 +0000)
Summary:
When we import an alias, we do so by making a clone of the aliasee. Just
as this clone uses the original alias name and linkage, it should also
use the same visibility (not the aliasee's visibility). Otherwise,
linker behavior is affected (e.g. if the aliasee was hidden, but the
alias is not, the resulting imported clone should not be hidden,
otherwise the linker will make the final symbol hidden which is
incorrect).

Reviewers: wmi

Subscribers: mehdi_amini, inglorion, eraman, steven_wu, dexonsmith, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D62535

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361989 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/FunctionImport.cpp
test/ThinLTO/X86/Inputs/alias_import.ll
test/ThinLTO/X86/alias_import.ll

index 71a76a6a67ca77a0b6c4deca869b9b2d2afd9bc9..9207f5fe0ef3f2254dcc1f295dbe0da4ac028659 100644 (file)
@@ -1053,9 +1053,10 @@ static Function *replaceAliasWithAliasee(Module *SrcModule, GlobalAlias *GA) {
 
   ValueToValueMapTy VMap;
   Function *NewFn = CloneFunction(Fn, VMap);
-  // Clone should use the original alias's linkage and name, and we ensure
-  // all uses of alias instead use the new clone (casted if necessary).
+  // Clone should use the original alias's linkage, visibility and name, and we
+  // ensure all uses of alias instead use the new clone (casted if necessary).
   NewFn->setLinkage(GA->getLinkage());
+  NewFn->setVisibility(GA->getVisibility());
   GA->replaceAllUsesWith(ConstantExpr::getBitCast(NewFn, GA->getType()));
   NewFn->takeName(GA);
   return NewFn;
index 7425f23fd3f51c6e79729c675a50a5c7fde1ceb4..740ab4baa35828b53fb7105c635d298acfc39767 100644 (file)
@@ -5,7 +5,7 @@ target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
 @globalfuncLinkonceAlias = linkonce alias void (...), bitcast (void ()* @globalfunc to void (...)*)
 @globalfuncWeakODRAlias = weak_odr alias void (...), bitcast (void ()* @globalfunc to void (...)*)
 @globalfuncLinkonceODRAlias = linkonce_odr alias void (...), bitcast (void ()* @globalfunc to void (...)*)
-define void @globalfunc() {
+define hidden void @globalfunc() {
 entry:
   ret void
 }
index af131e145bb58e3cec2d85ada6eaae5a1c7de208..6c6716a958de5924865147d7ea25ac62dbab62a1 100644 (file)
@@ -38,7 +38,7 @@
 ; PROMOTE-DAG: @linkonceODRfuncLinkonceAlias = weak alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*)
 ; PROMOTE-DAG: @linkonceODRfuncLinkonceODRAlias = weak_odr alias void (...), bitcast (void ()* @linkonceODRfunc to void (...)*)
 
-; PROMOTE-DAG: define void @globalfunc()
+; PROMOTE-DAG: define hidden void @globalfunc()
 ; PROMOTE-DAG: define internal void @internalfunc()
 ; PROMOTE-DAG: define weak_odr void @linkonceODRfunc()
 ; PROMOTE-DAG: define weak_odr void @weakODRfunc()
 ; IMPORT-DAG: define available_externally void @linkonceODRfuncAlias
 ; IMPORT-DAG: define available_externally void @linkonceODRfuncWeakODRAlias
 ; IMPORT-DAG: define available_externally void @linkonceODRfuncLinkonceODRAlias
-; IMPORT-DAG: define available_externally void @globalfuncAlias()
+; IMPORT-DAG: define available_externally dso_local void @globalfuncAlias()
 ; IMPORT-DAG: declare void @globalfuncWeakAlias()
 ; IMPORT-DAG: declare void @globalfuncLinkonceAlias()
-; IMPORT-DAG: define available_externally void @globalfuncWeakODRAlias()
-; IMPORT-DAG: define available_externally void @globalfuncLinkonceODRAlias()
+; IMPORT-DAG: define available_externally dso_local void @globalfuncWeakODRAlias()
+; IMPORT-DAG: define available_externally dso_local void @globalfuncLinkonceODRAlias()
 ; IMPORT-DAG: define available_externally dso_local void @internalfuncAlias()
 ; IMPORT-DAG: declare void @internalfuncWeakAlias()
 ; IMPORT-DAG: declare void @internalfuncLinkonceAlias()