https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99456

--- Comment #4 from Nathan Sidwell <nathan at gcc dot gnu.org> ---
It's an ABI issue, because all compilers must agree on which parts of an inline
object are dynamically initialized.  (gcc-11 does not agree with gcc-10).

consider:

inline Type Var = Expr;

That'll be emitted as comdat in every TU that needs it.  Assume some of those
TUs generate a static init and others generate a dynamic init.  Let's say it's
a dynamic one that gets into the executable, but one of the static TUs accesses
Var before that dyn init has run.  Boom, zero-initialized entity observed.

Or, let's say a static one wins, but then a dynmic initializer runs
concurrently to a (static TU's) access.  Oops, we could observe (weird) partial
writes.  (this would require Var to be a function-scope static because global
inits run in a single-thread environment, and it's less likelu to be a
problem).

In case it's not clear, this example shows both the above happening, and poor
code generation with (a) unused inline vars emitting code and (b) guard
variables for inline vars with no dynamic init.

Hope that helps.

Reply via email to