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

Rafael EspĂ­ndola rafael.espindola at gmail.com
Wed Jun 4 13:21:31 PDT 2014


> Add comdat key field to llvm.global_ctors and llvm.global_dtors
>
> This allows us to put dynamic initializers for weak data into the same
> comdat group as the data being initialized.  This is necessary for MSVC
> ABI compatibility.  Once we have comdats for guard variables, we can use
> the combination to help GlobalOpt fire more often for weak data with
> guarded initialization on other platforms.

So having

  %ini { i32 65535, void ()* @b_global_ctor, i8* bitcast (i32* @b to i8*) }

in @llvm.global_ctors is effectively a way of declaring that
b_global_cto should have the same comdat as @b?

Is this a short term solution? How will this interact with sections
having an explicit comdat in the future?

BTW, the itanium abi wording is a bit strange, but I don't think we
can change the comdat of the function. What we can (and should) do is
put the guard in the same comdat as the variable:

----------------------------------------------
Some objects with static storage duration have associated guard
variables used to ensure that they are initialized only once (see
3.3.2). If the object is emitted using a COMDAT group, the guard
variable must be too. It is suggested that it be emitted in the same
COMDAT group as the associated data object, but it may be emitted in
its own COMDAT group, identified by its name. In either case, it must
be weak.
----------------------------------------------

Cheers,
Rafael



More information about the llvm-commits mailing list