[lld] r264111 - [LTO] Keep linkonce_odr symbols when appropriate.
Rafael EspĂndola via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 23 05:15:36 PDT 2016
You only need to change the linkage if you are going to keep it. That is,
just before the push_back.
You should also handle linkonce in addition to linkonce_odr.
On the test, please check the bitcode created by save-temps instead.
Cheers,
Rafael
On Mar 22, 2016 6:36 PM, "Davide Italiano via llvm-commits" <
llvm-commits at lists.llvm.org> wrote:
> Author: davide
> Date: Tue Mar 22 17:31:34 2016
> New Revision: 264111
>
> URL: http://llvm.org/viewvc/llvm-project?rev=264111&view=rev
> Log:
> [LTO] Keep linkonce_odr symbols when appropriate.
>
> Ensure we keep the symbol we need to before it reaches
> the Writer (and hit an assertion), changing its linkage
> from linkonce_odr to weak. For a more detailed description
> of the problem, see PR19901 where a similar problem was
> fixed for the gold plugin. Thanks to Rafael for providing
> a testcase.
>
> Added:
> lld/trunk/test/ELF/lto/Inputs/linkonce-odr.ll
> lld/trunk/test/ELF/lto/linkonce-odr.ll
> Modified:
> lld/trunk/ELF/LTO.cpp
>
> Modified: lld/trunk/ELF/LTO.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=264111&r1=264110&r2=264111&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/LTO.cpp (original)
> +++ lld/trunk/ELF/LTO.cpp Tue Mar 22 17:31:34 2016
> @@ -82,10 +82,15 @@ void BitcodeCompiler::add(BitcodeFile &F
> Keep.push_back(GV);
> continue;
> }
> - if (!BitcodeFile::shouldSkip(Sym))
> + if (!BitcodeFile::shouldSkip(Sym)) {
> +
> + if (GV->getLinkage() == llvm::GlobalValue::LinkOnceODRLinkage)
> + GV->setLinkage(GlobalValue::WeakODRLinkage);
> +
> if (SymbolBody *B = Bodies[BodyIndex++])
> if (&B->repl() == B && isa<DefinedBitcode>(B))
> Keep.push_back(GV);
> + }
> }
>
> Mover.move(Obj->takeModule(), Keep,
>
> Added: lld/trunk/test/ELF/lto/Inputs/linkonce-odr.ll
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/Inputs/linkonce-odr.ll?rev=264111&view=auto
>
> ==============================================================================
> --- lld/trunk/test/ELF/lto/Inputs/linkonce-odr.ll (added)
> +++ lld/trunk/test/ELF/lto/Inputs/linkonce-odr.ll Tue Mar 22 17:31:34 2016
> @@ -0,0 +1,6 @@
> +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
> +target triple = "x86_64-unknown-linux-gnu"
> +
> +define linkonce_odr void @f() {
> + ret void
> +}
>
> Added: lld/trunk/test/ELF/lto/linkonce-odr.ll
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/linkonce-odr.ll?rev=264111&view=auto
>
> ==============================================================================
> --- lld/trunk/test/ELF/lto/linkonce-odr.ll (added)
> +++ lld/trunk/test/ELF/lto/linkonce-odr.ll Tue Mar 22 17:31:34 2016
> @@ -0,0 +1,24 @@
> +; REQUIRES: x86
> +; RUN: llvm-as %p/Inputs/linkonce-odr.ll -o %t1.o
> +; RUN: llc %s -o %t2.o -filetype=obj
> +; RUN: ld.lld %t1.o %t2.o -o %t.so -shared
> +; RUN: llvm-readobj -t %t.so | FileCheck %s
> +
> +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
> +target triple = "x86_64-unknown-linux-gnu"
> +declare void @f()
> +
> +define void @g() {
> + call void @f() ret void
> +}
> +
> +; Be sure that the linkonce_odr symbol 'f' is kept.
> +; CHECK: Symbol {
> +; CHECK: Name: f
> +; CHECK: Value: 0x1010
> +; CHECK: Size: 1
> +; CHECK: Binding: Weak
> +; CHECK: Type: Function
> +; CHECK: Other: 0
> +; CHECK: Section: .text
> +; CHECK: }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160323/cabcb714/attachment.html>
More information about the llvm-commits
mailing list