rewrite __aeabi_read_tp in asm

Submitted by Szabolcs Nagy on Aug. 25, 2018, 12:06 a.m.

Details

Message ID 20180825000658.GG4418@port70.net
State New
Series "fix tls access on arm targets before armv6k"
Headers show

Commit Message

Szabolcs Nagy Aug. 25, 2018, 12:06 a.m.
* Szabolcs Nagy <nsz@port70.net> [2018-08-24 23:56:21 +0200]:
> * Rich Felker <dalias@libc.org> [2018-08-24 16:17:36 -0400]:
> > On Fri, Aug 24, 2018 at 09:27:50PM +0200, Szabolcs Nagy wrote:
> > > rewrote it in asm to fix a runtime-abi issue.
> > 
> > I've already queued the previous fix. I could replace it since it's
> > not pushed, but I'd kinda prefer to make this change independent from
> > the bugfix since it's already been done in 2 steps anyway; normally I
> > don't like to mix bugfixes with refactoring except when it would be
> > hard to do the bugfix independently first.

attached it as a separate patch.

Patch hide | download patch | download mbox

From 9fcc75f35b9d7bb5af60c6d0f5ff32f11ca00802 Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
Date: Fri, 24 Aug 2018 23:11:59 +0000
Subject: [PATCH] rewrite __aeabi_read_tp in asm

__aeabi_read_tp used to call c code, but that was incorrect as the
arm runtime abi specifies special pcs for this function: it is only
allowed to clobber r0, ip, lr and cpsr.
---
 src/thread/arm/__aeabi_read_tp.s   | 10 ++++++----
 src/thread/arm/__aeabi_read_tp_c.c |  8 --------
 2 files changed, 6 insertions(+), 12 deletions(-)
 delete mode 100644 src/thread/arm/__aeabi_read_tp_c.c

diff --git a/src/thread/arm/__aeabi_read_tp.s b/src/thread/arm/__aeabi_read_tp.s
index 9d0cd311..2585620c 100644
--- a/src/thread/arm/__aeabi_read_tp.s
+++ b/src/thread/arm/__aeabi_read_tp.s
@@ -2,7 +2,9 @@ 
 .global __aeabi_read_tp
 .type __aeabi_read_tp,%function
 __aeabi_read_tp:
-	push {r1,r2,r3,lr}
-	bl __aeabi_read_tp_c
-	pop {r1,r2,r3,lr}
-	bx lr
+	ldr r0,1f
+	add r0,r0,pc
+	ldr r0,[r0]
+2:	bx r0
+	.align 2
+1:	.word __a_gettp_ptr - 2b
diff --git a/src/thread/arm/__aeabi_read_tp_c.c b/src/thread/arm/__aeabi_read_tp_c.c
deleted file mode 100644
index 0c56d613..00000000
--- a/src/thread/arm/__aeabi_read_tp_c.c
+++ /dev/null
@@ -1,8 +0,0 @@ 
-#include "pthread_impl.h"
-#include <stdint.h>
-
-__attribute__((__visibility__("hidden")))
-void *__aeabi_read_tp_c(void)
-{
-	return TP_ADJ(__pthread_self());
-}
-- 
2.18.0