Page MenuHomePhabricator

Fix Darwin 'constinit thread_local' variables.

Authored by jyknight on May 21 2020, 4:33 PM.



Unlike other platforms using ItaniumCXXABI, Darwin does not allow the
creation of a thread-wrapper function for a variable in the TU of
users. Because of this, it can set the linkage of the thread-local
symbol to internal, with the assumption that no TUs other than the one
defining the variable will need it.

However, constinit thread_local variables do not require the use of
the thread-wrapper call, so users reference the variable
directly. Thus, it must not be converted to internal.

Diff Detail

Event Timeline

jyknight created this revision.May 21 2020, 4:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 21 2020, 4:33 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
rjmccall added inline comments.May 22 2020, 6:58 PM

Is this a good idea? It seems to be making constinit part of the interface of a declaration, when it seems like it should strictly part of the implementation.

hubert.reinterpretcast added inline comments.

@rsmith, fyi. My understanding is that constinit is as much part of the interface as __thread or _Thread_local.

rjmccall accepted this revision.May 22 2020, 8:31 PM



Oh, heh. My impression had been an informal one, that it was purely a matter of enforcing static initialization, but I see that the committee did indeed sneak in the thread-local optimization. I guess all it means is that you can never take away constinit from an extern declaration once you've added it if you need a stable ABI.

Anyway, nevermind.

This revision is now accepted and ready to land.May 22 2020, 8:31 PM
This revision was automatically updated to reflect the committed changes.
jyknight marked an inline comment as done.