From 68b6aaa70d77ba0dfc8298244c10bbe8d3b05bf5 Mon Sep 17 00:00:00 2001 From: Mitchell Horne Date: Wed, 9 Oct 2019 02:02:22 +0000 Subject: [PATCH] RISC-V: Fix an alignment warning in libthr Compiling with clang gives a loss-of-alignment error due the cast to uint8_t *. Since the TLS is always tcb aligned and TP_OFFSET is defined as sizeof(struct tcb) we can guarantee there is no misalignment. Silence the error by moving the offset into the inline assembly. Reviewed by: br MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D21926 --- lib/libthr/arch/riscv/include/pthread_md.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/libthr/arch/riscv/include/pthread_md.h b/lib/libthr/arch/riscv/include/pthread_md.h index 499da5f5a8f8..55d9b7260fd2 100644 --- a/lib/libthr/arch/riscv/include/pthread_md.h +++ b/lib/libthr/arch/riscv/include/pthread_md.h @@ -62,7 +62,7 @@ static __inline void _tcb_set(struct tcb *tcb) { - __asm __volatile("mv tp, %0" :: "r"((uint8_t *)tcb + TP_OFFSET)); + __asm __volatile("addi tp, %0, %1" :: "r"(tcb), "I"(TP_OFFSET)); } /* @@ -71,11 +71,11 @@ _tcb_set(struct tcb *tcb) static __inline struct tcb * _tcb_get(void) { - register uint8_t *_tp; + struct tcb *_tcb; - __asm __volatile("mv %0, tp" : "=r"(_tp)); + __asm __volatile("addi %0, tp, %1" : "=r"(_tcb) : "I"(-TP_OFFSET)); - return ((struct tcb *)(_tp - TP_OFFSET)); + return (_tcb); } static __inline struct pthread *