diff options
author | Roland McGrath <roland@gnu.org> | 2002-08-28 10:39:23 +0000 |
---|---|---|
committer | Roland McGrath <roland@gnu.org> | 2002-08-28 10:39:23 +0000 |
commit | 1a0d874ed44e1fe59470497d65af8822a1b3abb8 (patch) | |
tree | e182578150b4cc6ad70d2e39fba0baeea4e1ad49 /locale/localeinfo.h | |
parent | d10c64301e56bd9cb77f5f480ba62df683ddbc5f (diff) | |
download | glibc-1a0d874ed44e1fe59470497d65af8822a1b3abb8.zip glibc-1a0d874ed44e1fe59470497d65af8822a1b3abb8.tar.gz glibc-1a0d874ed44e1fe59470497d65af8822a1b3abb8.tar.bz2 |
Make uselocale support static linking.
* locale/xlocale.c: Revert changes putting _nl_global_locale here.
This file again just defines _nl_C_locobj.
(_nl_C_locobj): Use a categories.def iterator in the initializer.
* locale/global-locale.c: New file. Define _nl_global_locale here,
using all weak references in the initializer.
* locale/Makefile (aux): Add global-locale.
* locale/localeinfo.h (_nl_global_locale, _NL_CURRENT_LOCALE): Make
these unconditional, along with the tsd decl.
[!SHARED && HAVE___THREAD && HAVE_WEAK_SYMBOLS] (NL_CURRENT_INDIRECT):
Define it under these conditions.
[NL_CURRENT_INDIRECT]: Test this instead of [! SHARED].
Don't declare _nl_current. Declare _nl_current_LC_FOO as
`extern __thread struct locale_data *const *'.
[NL_CURRENT_INDIRECT]
(_NL_CURRENT_DATA, _NL_CURRENT, _NL_CURRENT_WSTR): Add indirection.
[NL_CURRENT_INDIRECT] (_NL_CURRENT_DEFINE): Rewritten. Define
the thread variable _nl_current_LC_FOO and also a special absolute
symbol _nl_current_LC_FOO_used.
* locale/uselocale.c (__uselocale) [NL_CURRENT_INDIRECT]:
Set each _nl_current_LC_FOO symbol to point into the new locale,
using weak references to test if _nl_current_LC_FOO_used was linked in.
* locale/setlocale.c [! SHARED]: Replace this conditional ...
[NL_CURRENT_INDIRECT]: ... with this one.
(_nl_current, _nl_C): Variables removed.
[NL_CURRENT_INDIRECT] (_nl_current_used): New variable, table of
weak references to _nl_current_LC_FOO_used.
[NL_CURRENT_INDIRECT] (CATEGORY_USED): Define using that table.
(free_category): New function, broken out of ...
(free_mem): ... here. Call that.
(free_mem) [NL_CURRENT_INDIRECT]: Use a categories.def iterator
instead of a loop.
__USING_NAMESPACE_C99 depending on _GLIBCPP_USE_NAMESPACES.
Diffstat (limited to 'locale/localeinfo.h')
-rw-r--r-- | locale/localeinfo.h | 73 |
1 files changed, 50 insertions, 23 deletions
diff --git a/locale/localeinfo.h b/locale/localeinfo.h index 44a10e1..4e8c86e 100644 --- a/locale/localeinfo.h +++ b/locale/localeinfo.h @@ -155,54 +155,81 @@ extern const char _nl_C_codeset[] attribute_hidden; Each is malloc'd unless it is _nl_C_name. */ extern const char *_nl_current_names[] attribute_hidden; +/* This is the internal locale_t object that holds the global locale + controlled by calls to setlocale. A thread's TSD locale pointer + points to this when `uselocale (LC_GLOBAL_LOCALE)' is in effect. */ +extern struct __locale_struct _nl_global_locale attribute_hidden; + +/* This fetches the thread-local locale_t pointer, either one set with + uselocale or &_nl_global_locale. */ +#define _NL_CURRENT_LOCALE ((__locale_t) __libc_tsd_get (LOCALE)) +#include <bits/libc-tsd.h> +__libc_tsd_define (extern, LOCALE) -#ifndef SHARED -/* For each category declare the variable for the current locale data. */ -/* XXX _nl_current_LC_CTYPE and _nl_current_LC_COLLATE were exported - but where are they used? */ +/* For static linking it is desireable to avoid always linking in the code + and data for every category when we can tell at link time that they are + unused. We can manage this playing some tricks with weak references. + But with thread-local locale settings, it becomes quite ungainly unless + we can use __thread variables. So only in that case do we attempt this. */ +#if !defined SHARED && defined HAVE___THREAD && defined HAVE_WEAK_SYMBOLS +# include <tls.h> +# if USE_TLS +# define NL_CURRENT_INDIRECT 1 +# endif +#endif + +#ifdef NL_CURRENT_INDIRECT + +/* For each category declare the thread-local variable for the current + locale data. This has an extra indirection so it points at the + __locales[CATEGORY] element in either _nl_global_locale or the current + locale object set by uselocale, which points at the actual data. The + reason for having these variables is so that references to particular + categories will link in the lc-CATEGORY.c module to define this symbol, + and we arrange that linking that module is what brings in all the code + associated with this category. */ #define DEFINE_CATEGORY(category, category_name, items, a) \ -extern struct locale_data *_nl_current_##category attribute_hidden; +extern __thread struct locale_data *const *_nl_current_##category \ + attribute_hidden; #include "categories.def" #undef DEFINE_CATEGORY -extern struct locale_data * *const _nl_current[__LC_LAST] attribute_hidden; /* Return a pointer to the current `struct locale_data' for CATEGORY. */ -#define _NL_CURRENT_DATA(category) _nl_current_##category -/* Hackety hack, don't talk back. */ -#define _nl_current_category (*_nl_current[category]) +#define _NL_CURRENT_DATA(category) (*_nl_current_##category) /* Extract the current CATEGORY locale's string for ITEM. */ #define _NL_CURRENT(category, item) \ - (_nl_current_##category->values[_NL_ITEM_INDEX (item)].string) + ((*_nl_current_##category)->values[_NL_ITEM_INDEX (item)].string) /* Extract the current CATEGORY locale's string for ITEM. */ #define _NL_CURRENT_WSTR(category, item) \ - ((wchar_t *) _nl_current_##category->values[_NL_ITEM_INDEX (item)].wstr) + ((wchar_t *) (*_nl_current_##category)->values[_NL_ITEM_INDEX (item)].wstr) /* Extract the current CATEGORY locale's word for ITEM. */ #define _NL_CURRENT_WORD(category, item) \ - (_nl_current_##category->values[_NL_ITEM_INDEX (item)].word) + ((*_nl_current_##category)->values[_NL_ITEM_INDEX (item)].word) /* This is used in lc-CATEGORY.c to define _nl_current_CATEGORY. */ #define _NL_CURRENT_DEFINE(category) \ - extern struct locale_data _nl_C_##category attribute_hidden; \ - struct locale_data *_nl_current_##category = &_nl_C_##category + __thread struct locale_data *const *_nl_current_##category \ + attribute_hidden = &_nl_global_locale.__locales[category]; \ + asm (_NL_CURRENT_DEFINE_STRINGIFY (ASM_GLOBAL_DIRECTIVE) \ + " " __SYMBOL_PREFIX "_nl_current_" #category "_used\n" \ + _NL_CURRENT_DEFINE_ABS (_nl_current_##category##_used, 1)); +#define _NL_CURRENT_DEFINE_STRINGIFY(x) _NL_CURRENT_DEFINE_STRINGIFY_1 (x) +#define _NL_CURRENT_DEFINE_STRINGIFY_1(x) #x +#ifdef HAVE_ASM_SET_DIRECTIVE +# define _NL_CURRENT_DEFINE_ABS(sym, val) ".set " #sym ", " #val +#else +# define _NL_CURRENT_DEFINE_ABS(sym, val) #sym " = " #val +#endif #else /* All categories are always loaded in the shared library, so there is no point in having lots of separate symbols for linking. */ -# include <bits/libc-tsd.h> - -__libc_tsd_define (extern, LOCALE) - -extern struct __locale_struct _nl_global_locale attribute_hidden; - -# define _NL_CURRENT_LOCALE \ - ((__locale_t) __libc_tsd_get (LOCALE)) - /* Return a pointer to the current `struct locale_data' for CATEGORY. */ # define _NL_CURRENT_DATA(category) \ (_NL_CURRENT_LOCALE->__locales[category]) |