GNU Tools Cauldron 2025

GNU Tools Cauldron 2025

New TLS allactors for glibc
2025-09-26 , Auditorium B032 (80)

This presentation covers a design of a new thread-local storage (TLS) allocator for the GNU C Library (glibc). The goal of this project is to unify the allocation algorithm for initial-exec TLS, global-dynamic TLS, and POSIX thread-specific data (as created by pthread_key_create). It unifies ideas that have been circulated within the glibc community for many years.


In glibc, we currently have two different algorithms for initial-exec TLS allocation, depending on the TCB layout. Global-dynamic TLS uses a completely different, lazy allocation approach. POSIX TSD (pthread_key_create) is based on yet another separate algorithm with its own data structures. The proposal is for a new allocator that explicitly keeps track of the gaps between allocations, and use that everywhere. TCB differences will be handled by presenting the gaps available for allocation to the allocator, based on architecture-specific details. Global-dynamic TLS and pthread_key_create can use part of the initial-exec TLS area, but will eventually switch to separate slices of TLS memory. These slices follow an exponential growth policy, so only a small number of them will ever be needed, and pointers to these slices can be kept in a fixed-size array directly in the TCB.

The changes will eliminate lazy TLS memory allocation and slow paths from TLS accessor functions. Memory allocation failures will be reported upfront (at dlopen or pthread_create), and no longer via process termination. A previous attempt to make similar changes had to be reverted because Address Sanitizer was broken by it, and could not be fixed in time for the release. For this new effort, it should be possible to achieve Address Sanitizer compatibility by using its malloc to allocate TLS memory (after detecting that Address Sanitizer is active).

See also:

Florian is a long-time contributor to the GNU toolchain, particularly glibc. He currently serves as the glibc tech lead on the Red Hat Platform Tools team.

This speaker also appears in: