diff mbox

[5/5] ARC/NPTL: clone to set TP if CLONE_SETTLS

Message ID 1406290148-17601-6-git-send-email-vgupta@synopsys.com
State Accepted
Headers show

Commit Message

Vineet Gupta July 25, 2014, 12:09 p.m. UTC
Typically kernel would set the TP register of newly created thread in
clone syscall with CLONE_SETTLS.

However this implies that:
* kernel knows of the exact TP register (which is already different for
  ARCompact and ARCv2) and is a detail which becomes part of the ABI
* kernel also needs to handle the unlikely but possible case of !TLS
  userspace (e.g. Android libc) case where TP reg is not reserved and
  thus need not be mucked with (using ELF personality based detection)

It is better to confine this detail to userspace runtime and set TP reg
right after clone syscall returns.

Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
---
 libc/sysdeps/linux/arc/clone.S | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/libc/sysdeps/linux/arc/clone.S b/libc/sysdeps/linux/arc/clone.S
index db5000caff96..3c1388ec7861 100644
--- a/libc/sysdeps/linux/arc/clone.S
+++ b/libc/sysdeps/linux/arc/clone.S
@@ -29,6 +29,7 @@ 
 
 #define CLONE_VM		0x00000100
 #define CLONE_THREAD		0x00010000
+#define CLONE_SETTLS		0x00080000
 #define CLONE_THREAD_N_VM	(CLONE_THREAD | CLONE_VM)
 
 ENTRY(clone)
@@ -42,6 +43,7 @@  ENTRY(clone)
 	mov	r10, r0		; @fn
 	mov	r11, r3		; @args
 	mov	r12, r2		; @clone_flags
+	mov	r9,  r5		; @tls
 
 	; adjust libc args for syscall
 
@@ -57,6 +59,14 @@  ENTRY(clone)
 	jnz	[blink]		; Parent returns
 
 	; ----- child starts here ---------
+
+#if defined(__UCLIBC_HAS_TLS__)
+	; Setup TP register (since kernel doesn't do that)
+	and.f	0, r12, CLONE_SETTLS
+	bz	.Lnext_clone_quirk
+	SET_TP	r9
+
+.Lnext_clone_quirk:
 #ifdef RESET_PID
 	mov_s	r2, CLONE_THREAD_N_VM
 	and_s	r2, r2, r12
@@ -70,7 +80,7 @@  ENTRY(clone)
 
 .Lgo_thread:
 #endif
-
+#endif
 	; child jumps off to @fn with @arg as argument, and returns here
 	jl.d	[r10]
 	mov	r0, r11