From 81e18eb3cd61f7b68a8f99b3e6c728f2a4d79221 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Tue, 14 Apr 2015 23:45:08 -0400 Subject: [PATCH] use hidden __tls_get_new for tls/tlsdesc lookup fallback cases previously, the dynamic tlsdesc lookup functions and the i386 special-ABI ___tls_get_addr (3 underscores) function called __tls_get_addr when the slot they wanted was not already setup; __tls_get_addr would then in turn also see that it's not setup and call __tls_get_new. calling __tls_get_new directly is both more efficient and avoids the issue of calling a non-hidden (public API/ABI) function from asm. for the special i386 function, a weak reference to __tls_get_new is used since this function is not defined when static linking (the code path that needs it is unreachable in static-linked programs). --- src/ldso/aarch64/tlsdesc.s | 6 ++++-- src/ldso/i386/tlsdesc.s | 4 +++- src/ldso/x86_64/tlsdesc.s | 4 +++- src/thread/i386/tls.s | 4 +++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/ldso/aarch64/tlsdesc.s b/src/ldso/aarch64/tlsdesc.s index 32064bd7..05ddbab4 100644 --- a/src/ldso/aarch64/tlsdesc.s +++ b/src/ldso/aarch64/tlsdesc.s @@ -8,6 +8,8 @@ __tlsdesc_static: ldr x0,[x0,#8] ret +.hidden __tls_get_new + // long __tlsdesc_dynamic(long *a) // { // struct {size_t modidx,off;} *p = (void*)a[1]; @@ -37,7 +39,7 @@ __tlsdesc_dynamic: ldp x1,x2,[sp],#32 ret - // save all registers __tls_get_addr may clobber + // save all registers __tls_get_new may clobber // ugly because addr offset must be in [-512,509] 1: stp x29,x30,[sp,#-160]! stp x5,x6,[sp,#16] @@ -63,7 +65,7 @@ __tlsdesc_dynamic: stp q26,q27,[sp,#384] stp q28,q29,[sp,#416] stp q30,q31,[sp,#448] - bl __tls_get_addr + bl __tls_get_new mrs x1,tpidr_el0 ldp q4,q5,[sp,#32] ldp q6,q7,[sp,#64] diff --git a/src/ldso/i386/tlsdesc.s b/src/ldso/i386/tlsdesc.s index 3ac61297..00a9fc09 100644 --- a/src/ldso/i386/tlsdesc.s +++ b/src/ldso/i386/tlsdesc.s @@ -5,6 +5,8 @@ __tlsdesc_static: mov 4(%eax),%eax ret +.hidden __tls_get_new + .global __tlsdesc_dynamic .type __tlsdesc_dynamic,@function __tlsdesc_dynamic: @@ -22,6 +24,6 @@ __tlsdesc_dynamic: pop %edx ret 1: push %eax - call __tls_get_addr + call __tls_get_new pop %ecx jmp 2b diff --git a/src/ldso/x86_64/tlsdesc.s b/src/ldso/x86_64/tlsdesc.s index 57b78e0b..eb21b9de 100644 --- a/src/ldso/x86_64/tlsdesc.s +++ b/src/ldso/x86_64/tlsdesc.s @@ -5,6 +5,8 @@ __tlsdesc_static: mov 8(%rax),%rax ret +.hidden __tls_get_new + .global __tlsdesc_dynamic .type __tlsdesc_dynamic,@function __tlsdesc_dynamic: @@ -29,7 +31,7 @@ __tlsdesc_dynamic: push %r10 push %r11 mov %rax,%rdi - call __tls_get_addr + call __tls_get_new pop %r11 pop %r10 pop %r9 diff --git a/src/thread/i386/tls.s b/src/thread/i386/tls.s index 6e01adf2..76d5d462 100644 --- a/src/thread/i386/tls.s +++ b/src/thread/i386/tls.s @@ -10,6 +10,8 @@ ___tls_get_addr: add (%edx,%ecx,4),%eax ret 1: push %eax - call __tls_get_addr +.weak __tls_get_new +.hidden __tls_get_new + call __tls_get_new pop %edx ret -- 2.25.1