Put more stuff in the comdat used for variables with static init

David Majnemer david.majnemer at gmail.com
Tue Sep 16 09:28:18 PDT 2014


I think we should have clang omit comdats, it would be confusing to
silently ignore comdats in llvm.

On Tuesday, September 16, 2014, Rafael EspĂ­ndola <rafael.espindola at gmail.com>
wrote:

> Clang can already handle
>
> -------------------------------------------
> struct S {
>   static const int x;
> };
> template<typename T> struct U {
>   static const int k;
> };
> template<typename T> const int U<T>::k = T::x;
>
> #ifdef TU1
> const int S::x = 42;
> extern const int *f();
> const int *g() { return &U<S>::k; }
> int main() {
>   return *f() + U<S>::k;
> }
> #endif
>
> #ifdef TU2
> const int *f() { return &U<S>::k; }
> #endif
> -------------------------------------------
>
> since r217264 which puts the .inint_array section in the same COMDAT
> as the variable.
>
> The attached patch allows the linker to more easily delete some dead
> code and data by putting the guard variable and init function in the
> same COMDAT.
>
> One thing we have to decide is what to do about MachO. Should we omit
> the comdats from the IR for MachO or have llvm ignore it?
>
> Cheers,
> Rafael
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140916/7867f483/attachment.html>


More information about the cfe-commits mailing list