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

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


LGTM

On Tue, Mar 29, 2016 at 4:47 PM, Davide Italiano <davide at freebsd.org> wrote:

> On Tue, Mar 29, 2016 at 2:59 PM, Rui Ueyama <ruiu at google.com> wrote:
> > 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.
> >
>
> Does the following look good to you?
>
> diff --git a/ELF/LTO.cpp b/ELF/LTO.cpp
> index 63fb6e3..b1d5d60 100644
> --- a/ELF/LTO.cpp
> +++ b/ELF/LTO.cpp
> @@ -78,6 +78,10 @@ void BitcodeCompiler::add(BitcodeFile &F) {
>    ArrayRef<SymbolBody *> Bodies = F.getSymbols();
>
>    Module &M = Obj->getModule();
> +
> +  // If a symbol appears in @llvm.used, the linker is required
> +  // to treat the symbol as there is a reference to the symbol
> +  // that it cannot see. Therefore, we can't internalize.
>    SmallPtrSet<GlobalValue *, 8> Used;
>    collectUsedGlobalVariables(M, Used, /* CompilerUsed */ false);
>
>
>
> --
> Davide
>
> "There are no solved problems; there are only problems that are more
> or less solved" -- Henri Poincare
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160329/8456ec9e/attachment.html>


More information about the llvm-commits mailing list