[PATCH] Add comdat key field to llvm.global_ctors and llvm.global_dtors

Reid Kleckner rnk at google.com
Thu May 8 16:05:40 PDT 2014

On Wed, May 7, 2014 at 6:20 PM, Nick Lewycky <nlewycky at google.com> wrote:

> On 6 May 2014 11:24, Reid Kleckner <rnk at google.com> wrote:
>> ping
> + If the third field is present, non-null, and points to a global variable
> + or function, the initializer function will only run if the associated
> + data from the current module is included in the final linked image.
> "included in the final linked image" isn't well-defined at the level of
> LLVM IR. I think you mean "is not discarded", but I'm not certain.

"is not discarded" seems correct.  The only subtlety is that its just the
data from the current module.  If the some other module has a definition
for the same global value and our global is discarded and the other
definition is kept, this initializer is discarded and no initializer is
run.  This lets us aggressively eliminate these initializers in globalopt.

> -      Assert1(STy && STy->getNumElements() == 2 &&
> +      Assert1(STy && (STy->getNumElements() == 2 ||
> +                      STy->getNumElements() == 3) &&
> So you're going to permit old-style and new-style in the IR. What happens
> when I link the two? I think you need to autoupgrade to the new 3-argument
> form.

Right.  I taught us to auto-upgrade this and added a linker test.  Do we
want to force all frontends to switch to the new IR style up front?  I'm
hesitant to do it because it would break a frontend using the C API to emit

> + namespace {
> + struct Structor {
> +   Structor() : Priority(0), Func(0), ComdatKey(0) {}
> +   int Priority;
> +   llvm::Constant *Func;
> +   llvm::GlobalValue *ComdatKey;
> + };
> + } // end namespace
> C++11-ification: nullptr instead of 0, in-class initializers instead of a
> constructor.

I think I actually drafted this before the C++11 switch, and never sent it
out.  :)

> I'd appreciate if someone else reviewed the MC changes.

I'm actually pretty confident about that side of it.  It's pretty simple:
generate COFF with these bits, please.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140508/b1007ecc/attachment.html>

More information about the llvm-commits mailing list