[PATCH] D43130: [ThinLTO] Teach ThinLTO about auto hide symbols

Steven Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 9 10:12:34 PST 2018


steven_wu created this revision.
steven_wu added reviewers: tejohnson, mehdi_amini.
Herald added subscribers: eraman, inglorion.

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.


Repository:
  rL LLVM

https://reviews.llvm.org/D43130

Files:
  lib/Transforms/IPO/FunctionImport.cpp
  test/ThinLTO/X86/linkonce_odr_unnamed_addr.ll
  test/ThinLTO/X86/linkonce_resolution_comdat.ll


Index: test/ThinLTO/X86/linkonce_resolution_comdat.ll
===================================================================
--- test/ThinLTO/X86/linkonce_resolution_comdat.ll
+++ test/ThinLTO/X86/linkonce_resolution_comdat.ll
@@ -10,7 +10,7 @@
 ; Copy from first module is prevailing and converted to weak_odr, copy
 ; from second module is preempted and converted to available_externally and
 ; removed from comdat.
-; IMPORT1: define weak_odr i32 @f(i8*) unnamed_addr comdat($c1) {
+; IMPORT1: define weak_odr hidden i32 @f(i8*) unnamed_addr comdat($c1) {
 ; IMPORT2: define available_externally i32 @f(i8*) unnamed_addr {
 
 ; RUN: llvm-nm -o - < %t1.bc.thinlto.o | FileCheck %s --check-prefix=NM1
Index: test/ThinLTO/X86/linkonce_odr_unnamed_addr.ll
===================================================================
--- /dev/null
+++ test/ThinLTO/X86/linkonce_odr_unnamed_addr.ll
@@ -0,0 +1,10 @@
+; This test ensures that when linkonce_odr + unnamed_addr symbols promoted to
+; weak symbols, it preserves the auto hide property.
+
+; RUN: opt -module-summary %s -o %t.bc
+; RUN: opt -module-summary %s -o %t2.bc
+; RUN: llvm-lto -thinlto-action=thinlink -o %t3.bc %t.bc %t2.bc
+; RUN: llvm-lto -thinlto-action=promote %t.bc -thinlto-index=%t3.bc -o - | llvm-dis -o - | FileCheck %s
+
+; CHECK: @linkonceodrunnamed = weak_odr hidden unnamed_addr constant i32 0
+ at linkonceodrunnamed = linkonce_odr unnamed_addr constant i32 0
Index: lib/Transforms/IPO/FunctionImport.cpp
===================================================================
--- lib/Transforms/IPO/FunctionImport.cpp
+++ lib/Transforms/IPO/FunctionImport.cpp
@@ -656,6 +656,13 @@
     if (NewLinkage == GV.getLinkage())
       return;
 
+    // If the original symbols has global unnamed addr and linkonce_odr linkage,
+    // it should be an auto hide symbol. Add hidden visibility to the symbol to
+    // preserve the property.
+    if (GV.hasLinkOnceODRLinkage() && GV.hasGlobalUnnamedAddr() &&
+        NewLinkage == GlobalValue::WeakODRLinkage)
+      GV.setVisibility(GlobalValue::HiddenVisibility);
+
     // Switch the linkage to weakany if asked for, e.g. we do this for
     // linker redefined symbols (via --wrap or --defsym).
     // We record that the visibility should be changed here in `addThinLTO`


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43130.133641.patch
Type: text/x-patch
Size: 2284 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180209/55465caf/attachment.bin>


More information about the llvm-commits mailing list