This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug dynamic-link/14216] New: weak unresolved __thread symbols behave surprisingly
- From: "ppluzhnikov at google dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: Sat, 09 Jun 2012 22:48:54 +0000
- Subject: [Bug dynamic-link/14216] New: weak unresolved __thread symbols behave surprisingly
- Auto-submitted: auto-generated
http://sourceware.org/bugzilla/show_bug.cgi?id=14216
Bug #: 14216
Summary: weak unresolved __thread symbols behave surprisingly
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: dynamic-link
AssignedTo: unassigned@sourceware.org
ReportedBy: ppluzhnikov@google.com
Classification: Unclassified
I can't find a definitive source on what *should* happen for the test case
below, but I find the current behavior very surprising.
cat t.c
#include <pthread.h>
#include <stdio.h>
extern __thread int foo __attribute__((weak));
extern void *thfn2 (void *);
void *
thfn (void *p)
{
printf ("in thfn: %p\n", &foo);
return thfn2 (p);
}
int
main ()
{
pthread_t tid;
printf ("in main: %p\n", &foo);
pthread_create (&tid, NULL, thfn, NULL);
pthread_join (tid, NULL);
return 0;
}
cat t_so.c
#include <pthread.h>
#include <stdio.h>
extern __thread int foo __attribute__((weak));
void *
thfn2 (void *p)
{
printf ("in thfn2: %p\n", &foo);
return p;
}
gcc -pthread -fPIC -shared -o t_so.so t_so.c
gcc -pthread t.c ./t_so.so
nm -A a.out t_so.so | grep foo
a.out: w foo
t_so.so: w foo
Note that foo is never defined. I would therefore expect both printf
to print NULL. Instead:
in main: 0x7fd2ce84f700
in thfn: 0x7fd2cdeaf700
in thfn2: 0x1
The first two addresses correspond to the libpthread-private thread-descriptor.
Giving this address back to the user is an invitation for the user to corrupt
libpthread-internal state.
And when used in a shared library, we get a complete WTF address.
--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.