NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

toolchain/53911: alignment attribute of thread local symbols not respected

>Number:         53911
>Category:       toolchain
>Synopsis:       alignment attribute of thread local symbols not respected
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jan 26 00:15:00 +0000 2019
>Release:        NetBSD 8.99.31
System: NetBSD 8.99.31 NetBSD 8.99.31 (GENERIC.t3610) #0: Fri Jan 25 11:42:15 CET 2019 amd64
Architecture: x86_64
Machine: amd64
Not sure if this should go in toolchain or port-amd64...

Symbols with 16-byte alignment requirement can get 8-byte alignment at run time if declared as thread local. This makes programs crash if instructions that need 16-byte alignment are executed.
#include <stdio.h>
__thread int dst[4] __attribute__ ((aligned (16)));
int src[4] = {0,0,0,0};
int main(void) {
        printf("%p\n", dst);
        __builtin_memcpy(dst, src, sizeof(dst));
        return 0;

# gcc -o test test.c
# ./test
# clang -o test test.c
# ./test
Memory fault (core dumped)

If the program is compiled with clang it crashes because __builtin_memcpy emits an XMM SSE instruction.

The nm output looks 16-byte aligned.

# nm test |grep dst
0000000000000000 B dst
Maybe the static TLS segment itself is insufficiently aligned on an 8-byte boundary.


Home | Main Index | Thread Index | Old Index