This is an archive of the discontinued LLVM Phabricator instance.

PR48030: Fix COMDAT-related linking problem with C++ thread_local static data members.
ClosedPublic

Authored by rsmith on Aug 24 2021, 6:40 PM.

Details

Summary

Previously when emitting a C++ guarded initializer, we tried to work out what
the enclosing function would be used for and added it to the COMDAT containing
the variable if we thought that doing so would be correct. But this was done
from a context in which we didn't -- and realistically couldn't -- correctly
infer how the enclosing function would be used.

Instead, add the initialization function to a COMDAT from the code that
creates it, in the case where it makes sense to do so: when we know that
the one and only reference to the initialization function is in
@llvm.global.ctors and that reference is in the same COMDAT.

Diff Detail

Event Timeline

rsmith requested review of this revision.Aug 24 2021, 6:40 PM
rsmith created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptAug 24 2021, 6:40 PM

Note that there's a potential ABI impact here: because we accidentally put the __cxx_global_init function into a COMDAT with the variable, that meant that the _ZTH symbol (which is an alias to __cxx_global_init) also pointed into that same COMDAT. I'm not sure how much that matters given that the old behavior was broken.

This revision is now accepted and ready to land.Aug 24 2021, 7:32 PM