rtld - Support static TLS bindings for late-loaded shared libraries

Operating Systems / DragonFlyBSD - Matthew Dillon [apollo.backplane.com] - 9 August 2019 22:31 EDT

- 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

eeb6957159 rtld - Support static TLS bindings for late-loaded shared libraries
include/dlfcn.h | 1 +
lib/libc/gen/Symbol.map | 1 +
lib/libc/gen/elf_utils.c | 18 +++++++
lib/libc/include/libc_private.h | 3 ++
lib/libthread_xu/pthread.map | 1 +
lib/libthread_xu/thread/Makefile.inc | 1 +
lib/libthread_xu/thread/thr_distribute.c | 44 ++++++++++++++++
libexec/rtld-elf/rtld.c | 86 +++++++++++++++++++++++++++-----
libexec/rtld-elf/rtld.h | 2 +
9 files changed, 144 insertions(+), 13 deletions(-)

Upstream: gitweb.dragonflybsd.org


  • Share