[lld] r264790 - [LTO] Teach LTO about @llvm.used global.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 29 14:59:54 PDT 2016


On Tue, Mar 29, 2016 at 2:46 PM, Davide Italiano via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: davide
> Date: Tue Mar 29 16:46:35 2016
> New Revision: 264790
>
> URL: http://llvm.org/viewvc/llvm-project?rev=264790&view=rev
> Log:
> [LTO] Teach LTO about @llvm.used global.
>
> If a symbol appears in @llvm.used, the linker is forced to treat
> the symbol as there's a reference to it.
>
> Added:
>     lld/trunk/test/ELF/lto/internalize-llvmused.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=264790&r1=264789&r2=264790&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/LTO.cpp (original)
> +++ lld/trunk/ELF/LTO.cpp Tue Mar 29 16:46:35 2016
> @@ -21,6 +21,7 @@
>  #include "llvm/Support/TargetRegistry.h"
>  #include "llvm/Target/TargetMachine.h"
>  #include "llvm/Transforms/IPO.h"
> +#include "llvm/Transforms/Utils/ModuleUtils.h"
>  #include "llvm/Transforms/IPO/PassManagerBuilder.h"
>
>  using namespace llvm;
> @@ -76,6 +77,10 @@ void BitcodeCompiler::add(BitcodeFile &F
>    unsigned BodyIndex = 0;
>    ArrayRef<SymbolBody *> Bodies = F.getSymbols();
>
> +  Module &M = Obj->getModule();
> +  SmallPtrSet<GlobalValue *, 8> Used;
> +  collectUsedGlobalVariables(M, Used, /* CompilerUsed */ false);
>

Please add a comment.


> +
>    for (const BasicSymbolRef &Sym : Obj->symbols()) {
>      GlobalValue *GV = Obj->getSymbolGV(Sym.getRawDataRefImpl());
>      assert(GV);
> @@ -108,7 +113,8 @@ void BitcodeCompiler::add(BitcodeFile &F
>      // For now, let's be conservative and just never internalize
>      // symbols when creating a shared library.
>      if (!Config->Shared && !Config->ExportDynamic &&
> !B->isUsedInRegularObj())
> -      InternalizedSyms.insert(GV->getName());
> +      if (!Used.count(GV))
> +        InternalizedSyms.insert(GV->getName());
>
>      Keep.push_back(GV);
>    }
>
> Added: lld/trunk/test/ELF/lto/internalize-llvmused.ll
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/internalize-llvmused.ll?rev=264790&view=auto
>
> ==============================================================================
> --- lld/trunk/test/ELF/lto/internalize-llvmused.ll (added)
> +++ lld/trunk/test/ELF/lto/internalize-llvmused.ll Tue Mar 29 16:46:35 2016
> @@ -0,0 +1,20 @@
> +; REQUIRES: x86
> +; RUN: llvm-as %s -o %t.o
> +; RUN: ld.lld -m elf_x86_64 %t.o -o %t2 -save-temps
> +; RUN: llvm-dis < %t2.lto.bc | FileCheck %s
> +
> +target triple = "x86_64-unknown-linux-gnu"
> +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
> +
> +define void @_start() {
> +  ret void
> +}
> +
> +define hidden void @f() {
> +  ret void
> +}
> +
> + at llvm.used = appending global [1 x i8*] [ i8* bitcast (void ()* @f to
> i8*)]
> +
> +; Check that f is not internalized.
> +; CHECK: define hidden void @f()
>
>
> _______________________________________________
> 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/20160329/72434cc8/attachment.html>


More information about the llvm-commits mailing list