Opened 3 years ago

Closed 3 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:
Has a Patch: no 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).

Change History (1)

comment:1 Changed 3 years ago by pulkomandy

Resolution: fixed
Status: newclosed

Made the change in hrev50593.

Note: See TracTickets for help on using tickets.