[cfe-dev] [LLVMdev] weak_odr constant versus weak_odr global

Rafael EspĂ­ndola rafael.espindola at gmail.com
Fri Sep 5 11:21:44 PDT 2014


>> Given that this has been broken since forever, waiting a bit more for
>> https://sourceware.org/bugzilla/show_bug.cgi?id=17350 to be fixed and
>> then flipping -enable-structor-comdat might be the best way to fix
>> this. With that done we can add the function and the guard variable in
>> TU2 to the comdat to remove a bit of bloat (see attached patch).
>
>
> Even if this doesn't address the constant vs global crash issues, I think
> adding the .init_array entry to the comdat is a great startup time
> optimization. Everything continues to work as it does today, but less code
> is run during dynamic initialization because all the new TU initializers get
> deduplicated by the linker.

Excellent news: the output from bfd ld was valid. I got confused
because X86_64 uses a Rela relocation and the value in the relocated
location is not used. I reverted the patch disabling the fix and clang
now produces a testcase that doesn't crash  :-)


> However, if we wait until we don't care about old object file compatibility,
> we can transition to linking new TU1 with this new TU2:
> -------
> $var = comdat
> @var = weak_odr constant i32 42, comdat $var
> ; no guard, no initializer, no global_ctors entry
>
> Is that what you're thinking?

Yes, in fact that what we get now. So, what do you think of the patch
attached to the previous email? With it we also put the guard variable
and __cxx_global_var_init in the _ZN1UI1SE1kE comdat, saving a bit of
space in the final binary.

>> What is the discussion list for the itanium abi? Should I propose a patch?
>
>
> cxx-abi-dev at codesourcery.com

Cool, I will try to subscribe to it.

Cheers,
Rafael



More information about the cfe-dev mailing list