[Bug c++/50986] weak static data members with constant initializers emitted in .rodata, leading to segfault on startup
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50986 Andrew Pinski changed: What|Removed |Added Keywords||wrong-code --- Comment #4 from Andrew Pinski --- How clang fixes this is by putting the global initializer for U::k (in TU2) in the same comdat section as the non-readonly case.
[Bug c++/50986] weak static data members with constant initializers emitted in .rodata, leading to segfault on startup
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50986 --- Comment #3 from Rafael Avila de Espindola rafael.espindola at gmail dot com --- In clang this was fixed by putting a .init_array section in the same comdat as the variable it is initializing. That way if the variable is dropped, so is the initialization code.
[Bug c++/50986] weak static data members with constant initializers emitted in .rodata, leading to segfault on startup
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50986 --- Comment #1 from Andrew Pinski pinskia at gcc dot gnu.org 2012-02-01 19:58:12 UTC --- I think you are violating ODR here.
[Bug c++/50986] weak static data members with constant initializers emitted in .rodata, leading to segfault on startup
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50986 --- Comment #2 from Richard Smith richard-gccbugzilla at metafoo dot co.uk 2012-02-01 21:14:35 UTC --- As noted in comment#0, I believe there is no ODR violation here. Each definition of US::k consists of the same sequence of tokens, every name refers to the same entity in both definitions, and none of the other provisions of [basic.def.odr]p5 applies. After some discussion, the proposed approach in clang is (roughly) to always generate a guard variable (initialized to 1 for a statically-initialized variable), and to put the variable and its guard variable in the same COMDAT group. Full details are in this thread: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2011-November/018816.html