From ffb17e7ba3a5ba9632cee97330b325072fbe41dd Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Wed, 10 Jun 2020 13:40:40 +0100 Subject: rtld: Avoid using up static TLS surplus for optimizations [BZ #25051] On some targets static TLS surplus area can be used opportunistically for dynamically loaded modules such that the TLS access then becomes faster (TLSDESC and powerpc TLS optimization). However we don't want all surplus TLS to be used for this optimization because dynamically loaded modules with initial-exec model TLS can only use surplus TLS. The new contract for surplus static TLS use is: - libc.so can have up to 192 bytes of IE TLS, - other system libraries together can have up to 144 bytes of IE TLS. - Some "optional" static TLS is available for opportunistic use. The optional TLS is now tunable: rtld.optional_static_tls, so users can directly affect the allocated static TLS size. (Note that module unloading with dlclose does not reclaim static TLS. After the optional TLS runs out, TLS access is no longer optimized to use static TLS.) The default setting of rtld.optional_static_tls is 512 so the surplus TLS is 3*192 + 4*144 + 512 = 1664 by default, the same as before. Fixes BZ #25051. Tested on aarch64-linux-gnu and x86_64-linux-gnu. Reviewed-by: Carlos O'Donell --- csu/libc-tls.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'csu') diff --git a/csu/libc-tls.c b/csu/libc-tls.c index a67cc1dd4f..06e76bd395 100644 --- a/csu/libc-tls.c +++ b/csu/libc-tls.c @@ -56,6 +56,9 @@ size_t _dl_tls_static_align; loaded modules with IE-model TLS or for TLSDESC optimization. See comments in elf/dl-tls.c where it is initialized. */ size_t _dl_tls_static_surplus; +/* Remaining amount of static TLS that may be used for optimizing + dynamic TLS access (e.g. with TLSDESC). */ +size_t _dl_tls_static_optional; /* Generation counter for the dtv. */ size_t _dl_tls_generation; -- cgit 1.4.1