[llvm] r262727 - [ThinLTO] Ensure prevailing linkonce emitted as weak in ThinLTO backends

H.J. Lu via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 4 13:08:59 PST 2016


On Fri, Mar 4, 2016 at 9:48 AM, Teresa Johnson via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: tejohnson
> Date: Fri Mar  4 11:48:35 2016
> New Revision: 262727
>
> URL: http://llvm.org/viewvc/llvm-project?rev=262727&view=rev
> Log:
> [ThinLTO] Ensure prevailing linkonce emitted as weak in ThinLTO backends
>
> Summary:
> Since IR files are all compiled into separate independent object files
> in ThinLTO mode, the prevailing linkonce symbols must be emitted in its
> object file even if it is no longer referenced there, e.g. if no
> references remain in the module after inlining, since it may be
> referenced by another ThinLTO compiled object file. This is done by
> changing LDPR_PREVAILING_DEF_IRONLY* symbols to LDPR_PREVAILING_DEF,
> which converts the prevailing linkonce to weak. We also don't need the
> other prevailing IRONLY handling for internalization, which is not
> currently performed for ThinLTO.
>
> Test case included.
>
> Reviewers: davidxl, rafael
>
> Subscribers: rafael, joker.eph, llvm-commits
>
> Differential Revision: http://reviews.llvm.org/D16173
>
> Added:
>     llvm/trunk/test/tools/gold/X86/Inputs/thinlto_linkonceresolution.ll
>     llvm/trunk/test/tools/gold/X86/thinlto_linkonceresolution.ll
> Modified:
>     llvm/trunk/tools/gold/gold-plugin.cpp
>
> Added: llvm/trunk/test/tools/gold/X86/Inputs/thinlto_linkonceresolution.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/X86/Inputs/thinlto_linkonceresolution.ll?rev=262727&view=auto
> ==============================================================================
> --- llvm/trunk/test/tools/gold/X86/Inputs/thinlto_linkonceresolution.ll (added)
> +++ llvm/trunk/test/tools/gold/X86/Inputs/thinlto_linkonceresolution.ll Fri Mar  4 11:48:35 2016
> @@ -0,0 +1,4 @@
> +target triple = "x86_64-unknown-linux-gnu"
> +define linkonce_odr hidden void @f() {
> +  ret void
> +}
>
> Added: llvm/trunk/test/tools/gold/X86/thinlto_linkonceresolution.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/X86/thinlto_linkonceresolution.ll?rev=262727&view=auto
> ==============================================================================
> --- llvm/trunk/test/tools/gold/X86/thinlto_linkonceresolution.ll (added)
> +++ llvm/trunk/test/tools/gold/X86/thinlto_linkonceresolution.ll Fri Mar  4 11:48:35 2016
> @@ -0,0 +1,32 @@
> +; RUN: llvm-as -function-summary %s -o %t.o
> +; RUN: llvm-as -function-summary %p/Inputs/thinlto_linkonceresolution.ll -o %t2.o
> +
> +; Ensure the plugin ensures that for ThinLTO the prevailing copy of a
> +; linkonce symbol is changed to weak to ensure it is not eliminated.
> +; Note that gold picks the first copy of f() as the prevailing one,
> +; so listing %t2.o first is sufficient to ensure that this copy is
> +; preempted. Also, set the import-instr-limit to 0 to prevent f() from
> +; being imported from %t2.o which hides the problem.
> +; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
> +; RUN:     --plugin-opt=thinlto \
> +; RUN:     --plugin-opt=-import-instr-limit=0 \
> +; RUN:     --plugin-opt=save-temps \
> +; RUN:     -o %t3.o %t2.o %t.o
> +; RUN: llvm-nm %t3.o | FileCheck %s
> +; RUN: llvm-dis %t.o.opt.bc -o - | FileCheck --check-prefix=OPT %s
> +; RUN: llvm-dis %t2.o.opt.bc -o - | FileCheck --check-prefix=OPT2 %s
> +
> +; Ensure that f() is defined in resulting object file, and also
> +; confirm the weak linkage directly in the saved opt bitcode files.
> +; CHECK-NOT: U f
> +; OPT: declare extern_weak hidden void @f()
> +; OPT2: define weak_odr hidden void @f()
> +
> +target triple = "x86_64-unknown-linux-gnu"

When you specify target triple, you should pass -m elf_x86_64
to linker since the default linker target may be different.


-- 
H.J.
----
diff --git a/test/tools/gold/X86/thinlto_linkonceresolution.ll
b/test/tools/gold/X86/thinlto_linkonceresolution.ll
index 044087b..e6ed95b 100644
--- a/test/tools/gold/X86/thinlto_linkonceresolution.ll
+++ b/test/tools/gold/X86/thinlto_linkonceresolution.ll
@@ -7,7 +7,7 @@
 ; so listing %t2.o first is sufficient to ensure that this copy is
 ; preempted. Also, set the import-instr-limit to 0 to prevent f() from
 ; being imported from %t2.o which hides the problem.
-; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
+; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \
 ; RUN:     --plugin-opt=thinlto \
 ; RUN:     --plugin-opt=-import-instr-limit=0 \
 ; RUN:     --plugin-opt=save-temps \


More information about the llvm-commits mailing list