[llvm] r324757 - [ThinLTO] Teach ThinLTO about auto hide symbols

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 9 11:33:32 PST 2018


BTW, I don't think you have to wait until LTO to handle a global
unnamed_addr + linkonce_odr.

I will open a bug about it.

Cheers,
Rafael

Steven Wu via llvm-commits <llvm-commits at lists.llvm.org> writes:

> Author: steven_wu
> Date: Fri Feb  9 10:34:08 2018
> New Revision: 324757
>
> URL: http://llvm.org/viewvc/llvm-project?rev=324757&view=rev
> Log:
> [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
>
> Added:
>     llvm/trunk/test/ThinLTO/X86/linkonce_odr_unnamed_addr.ll
> Modified:
>     llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp
>     llvm/trunk/test/ThinLTO/X86/linkonce_resolution_comdat.ll
>
> Modified: llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp?rev=324757&r1=324756&r2=324757&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp (original)
> +++ llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp Fri Feb  9 10:34:08 2018
> @@ -683,6 +683,13 @@ void llvm::thinLTOResolveWeakForLinkerMo
>          // changed to enable this for aliases.
>          llvm_unreachable("Expected GV to be converted");
>      } else {
> +      // 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);
> +
>        DEBUG(dbgs() << "ODR fixing up linkage for `" << GV.getName() << "` from "
>                     << GV.getLinkage() << " to " << NewLinkage << "\n");
>        GV.setLinkage(NewLinkage);
>
> Added: llvm/trunk/test/ThinLTO/X86/linkonce_odr_unnamed_addr.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/linkonce_odr_unnamed_addr.ll?rev=324757&view=auto
> ==============================================================================
> --- llvm/trunk/test/ThinLTO/X86/linkonce_odr_unnamed_addr.ll (added)
> +++ llvm/trunk/test/ThinLTO/X86/linkonce_odr_unnamed_addr.ll Fri Feb  9 10:34:08 2018
> @@ -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
>
> Modified: llvm/trunk/test/ThinLTO/X86/linkonce_resolution_comdat.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/linkonce_resolution_comdat.ll?rev=324757&r1=324756&r2=324757&view=diff
> ==============================================================================
> --- llvm/trunk/test/ThinLTO/X86/linkonce_resolution_comdat.ll (original)
> +++ llvm/trunk/test/ThinLTO/X86/linkonce_resolution_comdat.ll Fri Feb  9 10:34:08 2018
> @@ -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
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list