From: Francisco Blas Izquierdo Riera (klondike) Subject: [PATCH] Use the no sysenter syscall when initializing TLS The glibc 2.20 uses INTERNAL_SYSCALL instead of some custom assembly to initialize the thread local storage. This is a known chicken and egg problem which Kevin F. Quinn solved for the sbrk call. This patch introduces a similar fix in TLS_INIT_TP to fix the issues caused by commit. Special kudos to blueness for pinpointing commit 9570bc53fcc11d3cfe028989e611266e8d55bd09 This should fix Gentoo bug #528558 This patch is released under the GPLv2 or a higher version license as is the original file as long as the author and the tester are credited. Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=528558 Upstream-status: Not supported Signed-off-by: Francisco Blas Izquierdo Riera (klondike) Reported-by: Toralf Förster Pinpointed-by: Anthony Basile Tested-by: Francisco Blas Izquierdo Riera (klondike) --- sysdeps/i386/nptl/tls.h +++ sysdeps/i386/nptl/tls.h @@ -189,6 +189,15 @@ desc->vals[3] = 0x51; } +/* We have no sysenter until the tls is initialized which is a + problem on PIC. Thus we need to do the right call depending + on the situation. */ +#ifndef INTERNAL_SYSCALL_NOSYSENTER +#define TLS_INIT_SYSCALL INTERNAL_SYSCALL +#else +#define TLS_INIT_SYSCALL INTERNAL_SYSCALL_NOSYSENTER +#endif + /* Code to initially initialize the thread pointer. This might need special attention since 'errno' is not yet available and if the operation can cause a failure 'errno' must not be touched. */ @@ -209,7 +218,7 @@ \ /* Install the TLS. */ \ INTERNAL_SYSCALL_DECL (err); \ - _result = INTERNAL_SYSCALL (set_thread_area, err, 1, &_segdescr.desc); \ + _result = TLS_INIT_SYSCALL (set_thread_area, err, 1, &_segdescr.desc); \ \ if (_result == 0) \ /* We know the index in the GDT, now load the segment register. \