#13001: LocaleKit CatalogStub: static initializer order undefined
-----------------------------+------------------------------
Reporter: korli | Owner: pulkomandy
Type: bug | Status: new
Priority: normal | Milestone: Unscheduled
Component: Kits/Locale Kit | Version: R1/Development
Keywords: | Blocked By:
Blocking: | Has a Patch: 0
Platform: All |
-----------------------------+------------------------------
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).
--
Ticket URL: <https://dev.haiku-os.org/ticket/13001>
Haiku <https://dev.haiku-os.org>
Haiku - the operating system.