Opened 8 years ago
Closed 8 years ago
#13001 closed bug (fixed)
LocaleKit CatalogStub: static initializer order undefined
Reported by: | korli | Owned by: | pulkomandy |
---|---|---|---|
Priority: | normal | Milestone: | Unscheduled |
Component: | Kits/Locale Kit | Version: | R1/Development |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
in http://cgit.haiku-os.org/haiku/tree/src/kits/locale/CatalogStub.cpp#n13
static BCatalog sCatalog;
is used by:
BCatalog* BLocaleRoster::GetCatalog() { #if (__GNUC__ < 3) asm volatile(".hidden GetCatalog__13BLocaleRoster"); #else asm volatile(".hidden _ZN13BLocaleRoster10GetCatalogEv"); #endif return _GetCatalog(&sCatalog, &sCatalogInitOnce); }
The BCatalog constructor might be called after the constructor of other compilation units, whose globals happen to use BLocaleRoster::GetCatalog(), for instance http://cgit.haiku-os.org/haiku/tree/src/kits/textencoding/character_sets.cpp#n26
static const BCharacterSet unicode(0,106, B_TRANSLATE("Unicode"), "UTF-8", "UTF-8",unicodeAliases);
For reference
#define B_TRANSLATE(string) \ BLocaleRoster::Default()->GetCatalog()->GetString((string), \ B_TRANSLATION_CONTEXT)
One solution: move "static BCatalog sCatalog;" in BLocaleRoster::GetCatalog(), this becomes a local static variable, the constructor will be called one time on first call.
Reproduced with binutils 2.26.1 configured with --enable-initfini-array, or binutils 2.27 (which defaults to --enable-initfini-array).
Made the change in hrev50593.