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



static BCatalog sCatalog;

is used by:

	#if (__GNUC__ < 3)
		asm volatile(".hidden GetCatalog__13BLocaleRoster");
		asm volatile(".hidden _ZN13BLocaleRoster10GetCatalogEv");

	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

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), \

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 by pulkomandy, 3 years ago

Resolution: fixed
Status: newclosed

Made the change in hrev50593.

Note: See TracTickets for help on using tickets.