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
>Originator:     tnn%NetBSD.org@localhost
>Release:        NetBSD 8.99.31
>Organization:
	
>Environment:
	
	
System: NetBSD t3610.rymdfartsverket.se 8.99.31 NetBSD 8.99.31 (GENERIC.t3610) #0: Fri Jan 25 11:42:15 CET 2019 tnn%t3610.rymdfartsverket.se@localhost:/work/obj/sys/arch/amd64/compile/GENERIC.t3610 amd64
Architecture: x86_64
Machine: amd64
>Description:
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.
>How-To-Repeat:
#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
0x73558bb53048
# clang -o test test.c
# ./test
0x774ab1852048
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
>Fix:
Maybe the static TLS segment itself is insufficiently aligned on an 8-byte boundary.

>Unformatted:
 	
 	


Home | Main Index | Thread Index | Old Index