Skip to content

Commit 33ba93c

Browse files
committedFeb 9, 2018
[ThinLTO] Teach ThinLTO about auto hide symbols
Summary: For symbols that has linkonce_odr linkage and unnamed_addr, it can be auto hide by linker to avoid weak external symbols. Teach ThinLTO to perform auto hide so it can safely promote linkonce_odr to weak symbols without breaking this nice property. Reviewers: tejohnson, mehdi_amini Reviewed By: tejohnson Subscribers: inglorion, eraman, rnk, pcc, llvm-commits Differential Revision: https://reviews.llvm.org/D43130 llvm-svn: 324757
1 parent 37a9889 commit 33ba93c

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed
 

‎llvm/lib/Transforms/IPO/FunctionImport.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,13 @@ void llvm::thinLTOResolveWeakForLinkerModule(
683683
// changed to enable this for aliases.
684684
llvm_unreachable("Expected GV to be converted");
685685
} else {
686+
// If the original symbols has global unnamed addr and linkonce_odr linkage,
687+
// it should be an auto hide symbol. Add hidden visibility to the symbol to
688+
// preserve the property.
689+
if (GV.hasLinkOnceODRLinkage() && GV.hasGlobalUnnamedAddr() &&
690+
NewLinkage == GlobalValue::WeakODRLinkage)
691+
GV.setVisibility(GlobalValue::HiddenVisibility);
692+
686693
DEBUG(dbgs() << "ODR fixing up linkage for `" << GV.getName() << "` from "
687694
<< GV.getLinkage() << " to " << NewLinkage << "\n");
688695
GV.setLinkage(NewLinkage);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; This test ensures that when linkonce_odr + unnamed_addr symbols promoted to
2+
; weak symbols, it preserves the auto hide property.
3+
4+
; RUN: opt -module-summary %s -o %t.bc
5+
; RUN: opt -module-summary %s -o %t2.bc
6+
; RUN: llvm-lto -thinlto-action=thinlink -o %t3.bc %t.bc %t2.bc
7+
; RUN: llvm-lto -thinlto-action=promote %t.bc -thinlto-index=%t3.bc -o - | llvm-dis -o - | FileCheck %s
8+
9+
; CHECK: @linkonceodrunnamed = weak_odr hidden unnamed_addr constant i32 0
10+
@linkonceodrunnamed = linkonce_odr unnamed_addr constant i32 0

‎llvm/test/ThinLTO/X86/linkonce_resolution_comdat.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
; Copy from first module is prevailing and converted to weak_odr, copy
1111
; from second module is preempted and converted to available_externally and
1212
; removed from comdat.
13-
; IMPORT1: define weak_odr i32 @f(i8*) unnamed_addr comdat($c1) {
13+
; IMPORT1: define weak_odr hidden i32 @f(i8*) unnamed_addr comdat($c1) {
1414
; IMPORT2: define available_externally i32 @f(i8*) unnamed_addr {
1515

1616
; RUN: llvm-nm -o - < %t1.bc.thinlto.o | FileCheck %s --check-prefix=NM1

0 commit comments

Comments
 (0)
Please sign in to comment.