threads/161344: Failure to init TLS variables with func ptr inside shared lib

Alex Dupre ale at FreeBSD.org
Thu Oct 6 21:00:19 UTC 2011


>Number:         161344
>Category:       threads
>Synopsis:       Failure to init TLS variables with func ptr inside shared lib
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-threads
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Oct 06 21:00:18 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Alex Dupre
>Release:        FreeBSD 8.2-STABLE i386
>Organization:
>Environment:
System: FreeBSD freefall.freebsd.org 8.2-STABLE FreeBSD 8.2-STABLE #4 r220774: Mon Apr 18 13:56:14 UTC 2011 simon at freefall.freebsd.org:/usr/obj/usr/src/sys/FREEFALL i386


	
>Description:
Initialisation of Thread Local Storage variables to some values
which are function address doesn't work inside a shared library.
	
>How-To-Repeat:
	
t1.c:

int f(int x) {
  return x;
}
struct s_t {
  int (*func)(int);
};
struct s_t __thread x = { f };

Build it as:
cc -shared -o t1.so -fPIC t1.c

t2.c:

struct s_t {
  int (*func)(int);
};
extern struct s_t __thread x;
int main(int argc, const char *argv[]) {
  return (*x.func)(argc);
}

Build it as:
cc t2.c t1.so

export LD_LIBRARY_PATH=.
./a.out
Segmentation fault
>Fix:

	


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-threads mailing list