[PATCH] D19102: Always traverse GlobalVariable initializer when computing the export list

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 14 13:19:31 PDT 2016


tejohnson added a comment.

In http://reviews.llvm.org/D19102#401562, @joker.eph wrote:

> In http://reviews.llvm.org/D19102#401545, @tejohnson wrote:
>
> > > We are always importing the initializer for a GlobalVariable.
> >
> >
> > I don't think this is true anymore, or at least I can't find where we are doing this. We used to always import variable defs in the Linker, but now that is being passed a list of globals to import.
>
>
> We do it for every global that is referenced from the IR we import, this is done in `IRLinker::linkGlobalInit(GlobalVariable &Dst, GlobalVariable &Src)`.
>  (I couldn't find a reliable way to avoid this, too many corner cases).


I don't believe that is true that we always link in inits for global variables that are referenced. Yes linkGlobalInit is called for variables unconditionally from linkGlobalValueBody, but then, so is linkFunctionBody for functions from the same place. We invoke linkGlobalValueBody from materializeInitFor, which I believe is unconditionally invoked on references from the ValueMapper. However, materializeInitFor only invokes linkGlobalValueBody only when "ForAlias || shouldLink(New, *Old)".

Looking at when those conditions are true it seems like there are therefore a few conditions under which we would map in a global variable init (although I don't see anything specific to variables here):

1. ForAlias==true: This happens when this value was encountered when mapping an aliasee, which could be a variable
2. New is in ValuesToLink: Not currently true for global variables
3. New hasLocalLinkage(): We should have promoted any locals referenced by an import before this, so shouldn't be true here
4. AddLazyFor returns true: Aha - you are probably catching some variables here due to the issue with addLazyFor currently force importing linkonce!

So I think the issue is not with linkGlobalInit, but rather the current Linker behavior around aliases and linkonce (and I don't think this is specific to variables). Again, correct me if I am missing something though.


http://reviews.llvm.org/D19102





More information about the llvm-commits mailing list