rtld - Support static TLS bindings for late-loaded shared libraries
authorMatthew Dillon <dillon@apollo.backplane.com>
Fri, 9 Aug 2019 22:22:18 +0000 (15:22 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Fri, 9 Aug 2019 22:31:44 +0000 (15:31 -0700)
commiteeb6957159b8d414a4ad6de31c473c8cd565972b
tree331ece1c7609ed87c2e204f43d83b17609bbe884
parent21a17da112b446e6863309007b58ea0c263b6ef4
rtld - Support static TLS bindings for late-loaded shared libraries

* Allow late (manual) dlopen()s to load shared libraries which
  use static TLS variables, as long as there is space.  Do proper
  late-binding and initialize the area for all threads.

* rtld will cache a symbol lookup on first-need for:
  "_pthread_distribute_static_tls" and then call it as needed to
  initialize late-bound static TLS space.

  This symbol is weakly bounded to __libc_distribute_static_tls in libc,
  and strongly overridden by _libthread_distribute_static_tls in
  libthread_xu.

* Fixes mesa glx-tls and others.

* Test code from FreeBSD.  Also tested with other combinations
  including a pthread_create() and -static compilation.

https://github.com/dumbbell/test-tls-initial-exec
include/dlfcn.h
lib/libc/gen/Symbol.map
lib/libc/gen/elf_utils.c
lib/libc/include/libc_private.h
lib/libthread_xu/pthread.map
lib/libthread_xu/thread/Makefile.inc
lib/libthread_xu/thread/thr_distribute.c [new file with mode: 0644]
libexec/rtld-elf/rtld.c
libexec/rtld-elf/rtld.h