fix nl_langinfo with static linking (BZ #16915)

For static linking the locale code avoids linking code and data for
unused categories. However for nl_langinfo we know only at runtime which
categories are used, so direct reference to every nl_current_CATEGORY
symbol should be done.

This was broken by commit bc3e1c1273 where
nl_langinfo_l and nl_langinfo have been merged and some code has been
lost in the process.

In order to detect locales issues with static linking, compile a version
of tst-langinfo with static linking.

Note: this is Debian bug#747103 reported by Raphael <raphael.astier@eliot-sa.com>
This commit is contained in:
Aurelien Jarno 2014-05-16 00:06:54 +02:00
parent de9d8f2098
commit ae75a883f2
6 changed files with 42 additions and 6 deletions

View File

@ -1,3 +1,16 @@
2014-05-20 Aurelien Jarno <aurelien@aurel32.net>
[BZ #16915]
* locale/nl_langinfo_l.c: Make direct reference to every
_nl_current_CATEGORY symbol.
* localedata/Makefile (test-srcs): Add tst-langinfo-static.
(tests-static): Add tst-langinfo-static.
(tests-special): Add tst-langinfo-static.out.
($(objpfx)tst-langinfo.out): Redirect output.
($(objpfx)tst-langinfo-static.out): New.
* localedata/tst-langinfo.sh: Send output to stdout.
* localedata/tst-langinfo-static.c: New file.
2014-05-20 Richard Henderson <rth@redhat.com> 2014-05-20 Richard Henderson <rth@redhat.com>
[BZ #16967] [BZ #16967]

3
NEWS
View File

@ -17,7 +17,8 @@ Version 2.20
16712, 16713, 16714, 16731, 16739, 16740, 16743, 16754, 16758, 16759, 16712, 16713, 16714, 16731, 16739, 16740, 16743, 16754, 16758, 16759,
16760, 16770, 16786, 16789, 16791, 16799, 16800, 16815, 16823, 16824, 16760, 16770, 16786, 16789, 16791, 16799, 16800, 16815, 16823, 16824,
16831, 16838, 16849, 16854, 16876, 16877, 16885, 16888, 16890, 16912, 16831, 16838, 16849, 16854, 16876, 16877, 16885, 16888, 16890, 16912,
16916, 16917, 16922, 16927, 16928, 16932, 16943, 16958, 16966, 16967. 16915, 16916, 16917, 16922, 16927, 16928, 16932, 16943, 16958, 16966,
16967.
* The minimum Linux kernel version that this version of the GNU C Library * The minimum Linux kernel version that this version of the GNU C Library
can be used with is 2.6.32. can be used with is 2.6.32.

View File

@ -20,6 +20,7 @@
#include <locale.h> #include <locale.h>
#include <errno.h> #include <errno.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h>
#include "localeinfo.h" #include "localeinfo.h"
@ -43,7 +44,21 @@ __nl_langinfo_l (item, l)
if (index == _NL_ITEM_INDEX (_NL_LOCALE_NAME (category))) if (index == _NL_ITEM_INDEX (_NL_LOCALE_NAME (category)))
return (char *) l->__names[category]; return (char *) l->__names[category];
#if defined NL_CURRENT_INDIRECT
/* Make direct reference to every _nl_current_CATEGORY symbol,
since we know only at runtime which categories are used. */
switch (category)
{
# define DEFINE_CATEGORY(category, category_name, items, a) \
case category: data = *_nl_current_##category; break;
# include "categories.def"
# undef DEFINE_CATEGORY
default: /* Should be impossible. */
abort();
}
#else
data = l->__locales[category]; data = l->__locales[category];
#endif
if (index >= data->nstrings) if (index >= data->nstrings)
/* Bogus index for this category: bogus item. */ /* Bogus index for this category: bogus item. */

View File

@ -35,7 +35,7 @@ vpath %.h tests-mbwc
test-srcs := collate-test xfrm-test tst-fmon tst-rpmatch tst-trans \ test-srcs := collate-test xfrm-test tst-fmon tst-rpmatch tst-trans \
tst-mbswcs1 tst-mbswcs2 tst-mbswcs3 tst-mbswcs4 tst-mbswcs5 \ tst-mbswcs1 tst-mbswcs2 tst-mbswcs3 tst-mbswcs4 tst-mbswcs5 \
tst-ctype tst-wctype tst-langinfo tst-numeric tst-ctype tst-wctype tst-langinfo tst-langinfo-static tst-numeric
test-input := de_DE.ISO-8859-1 en_US.ISO-8859-1 da_DK.ISO-8859-1 \ test-input := de_DE.ISO-8859-1 en_US.ISO-8859-1 da_DK.ISO-8859-1 \
hr_HR.ISO-8859-2 sv_SE.ISO-8859-1 tr_TR.UTF-8 fr_FR.UTF-8 \ hr_HR.ISO-8859-2 sv_SE.ISO-8859-1 tr_TR.UTF-8 fr_FR.UTF-8 \
si_LK.UTF-8 si_LK.UTF-8
@ -95,7 +95,9 @@ tests-special += $(objpfx)sort-test.out $(objpfx)tst-fmon.out \
$(objpfx)tst-locale.out $(objpfx)tst-rpmatch.out \ $(objpfx)tst-locale.out $(objpfx)tst-rpmatch.out \
$(objpfx)tst-trans.out $(objpfx)tst-mbswcs.out \ $(objpfx)tst-trans.out $(objpfx)tst-mbswcs.out \
$(objpfx)tst-ctype.out $(objpfx)tst-wctype.out \ $(objpfx)tst-ctype.out $(objpfx)tst-wctype.out \
$(objpfx)tst-langinfo.out $(objpfx)tst-numeric.out $(objpfx)tst-langinfo.out $(objpfx)tst-langinfo-static.out \
$(objpfx)tst-numeric.out
tests-static += tst-langinfo-static
ifeq ($(run-built-tests),yes) ifeq ($(run-built-tests),yes)
# We have to generate locales # We have to generate locales
@ -197,7 +199,12 @@ $(objpfx)tst-wctype.out: tst-wctype.sh $(objpfx)tst-wctype \
$(objpfx)tst-langinfo.out: tst-langinfo.sh $(objpfx)tst-langinfo \ $(objpfx)tst-langinfo.out: tst-langinfo.sh $(objpfx)tst-langinfo \
$(objpfx)sort-test.out \ $(objpfx)sort-test.out \
$(addprefix $(objpfx),$(CTYPE_FILES)) $(addprefix $(objpfx),$(CTYPE_FILES))
$(SHELL) $< $(common-objpfx) '$(test-program-cmd)'; \ $(SHELL) $< $(common-objpfx) '$(test-program-cmd)' > $@; \
$(evaluate-test)
$(objpfx)tst-langinfo-static.out: tst-langinfo.sh $(objpfx)tst-langinfo-static \
$(objpfx)sort-test.out \
$(addprefix $(objpfx),$(CTYPE_FILES))
$(SHELL) $< $(common-objpfx) '$(test-program-cmd)' > $@; \
$(evaluate-test) $(evaluate-test)
$(objpfx)tst-digits.out: $(objpfx)tst-locale.out $(objpfx)tst-digits.out: $(objpfx)tst-locale.out
$(objpfx)tst-mbswcs6.out: $(addprefix $(objpfx),$(CTYPE_FILES)) $(objpfx)tst-mbswcs6.out: $(addprefix $(objpfx),$(CTYPE_FILES))

View File

@ -0,0 +1 @@
#include "tst-langinfo.c"

View File

@ -340,7 +340,6 @@ ja_JP.EUC-JP NOEXPR ^([nN
ja_JP.EUC-JP CODESET EUC-JP ja_JP.EUC-JP CODESET EUC-JP
EOF EOF
LOCPATH=${common_objpfx}localedata GCONV_PATH=${common_objpfx}iconvdata \ LOCPATH=${common_objpfx}localedata GCONV_PATH=${common_objpfx}iconvdata \
LC_ALL=tt_TT ${tst_langinfo} \ LC_ALL=tt_TT ${tst_langinfo}
> ${common_objpfx}localedata/tst-langinfo.out
exit $? exit $?