git: 4c2f5bfbfa48 - main - libc: Fix the alignment of the TCB to match rtld for several architectures.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Thu, 09 Dec 2021 21:23:43 UTC
The branch main has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=4c2f5bfbfa48b33b11912e7308ebd6f98fb6e647

commit 4c2f5bfbfa48b33b11912e7308ebd6f98fb6e647
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2021-12-09 21:16:57 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2021-12-09 21:16:57 +0000

    libc: Fix the alignment of the TCB to match rtld for several architectures.
    
    - Use 16 byte alignment rather than 8 for aarch64, powerpc64, and RISC-V.
    
    - Use 8 byte alignment rather than 4 for 32-bit arm, mips, and powerpc.
    
    I suspect that mips64 should be using 16 byte alignment, but both libc
    and rtld currently use 8 byte alignment.
    
    Reviewed by:    kib, jrtc27
    Sponsored by:   The University of Cambridge, Google Inc.
    Differential Revision:  https://reviews.freebsd.org/D33350
---
 lib/libc/gen/tls.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/lib/libc/gen/tls.c b/lib/libc/gen/tls.c
index d90aac028b88..5995cf605ed3 100644
--- a/lib/libc/gen/tls.c
+++ b/lib/libc/gen/tls.c
@@ -72,11 +72,14 @@ void _rtld_free_tls(void *tls, size_t tcbsize, size_t tcbalign);
 void *__libc_allocate_tls(void *oldtls, size_t tcbsize, size_t tcbalign);
 void __libc_free_tls(void *tls, size_t tcbsize, size_t tcbalign);
 
-#if defined(__amd64__)
+#if defined(__amd64__) || defined(__aarch64__) || defined(__riscv)
 #define TLS_TCB_ALIGN 16
-#elif defined(__aarch64__) || defined(__arm__) || defined(__i386__) || \
-    defined(__mips__) || defined(__powerpc__) || defined(__riscv)
-#define TLS_TCB_ALIGN sizeof(void *)
+#elif defined(__arm__) || defined(__mips__)
+#define TLS_TCB_ALIGN 8
+#elif defined(__powerpc__)
+#define TLS_TCB_ALIGN TLS_TCB_SIZE
+#elif defined(__i386__)
+#define TLS_TCB_ALIGN 4
 #else
 #error TLS_TCB_ALIGN undefined for target architecture
 #endif