NetBSD Problem Report #53911

From tnn@nygren.pp.se  Sat Jan 26 00:14:43 2019
Return-Path: <tnn@nygren.pp.se>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id AA8EE7A174
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 26 Jan 2019 00:14:43 +0000 (UTC)
Message-Id: <20190126000138.9544F85AE22@t3610.nygren.pp.se>
Date: Sat, 26 Jan 2019 01:01:38 +0100 (CET)
From: tnn@NetBSD.org
Reply-To: tnn@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: alignment attribute of thread local symbols not respected
X-Send-Pr-Version: 3.95

>Number:         53911
>Category:       toolchain
>Synopsis:       alignment attribute of thread local symbols not respected
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    toolchain-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jan 26 00:15:00 +0000 2019
>Closed-Date:    Tue Nov 05 20:31:13 +0000 2019
>Last-Modified:  Tue Nov 05 20:31:13 +0000 2019
>Originator:     tnn@NetBSD.org
>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:/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.

>Release-Note:

>Audit-Trail:
From: Kamil Rytarowski <n54@gmx.com>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: toolchain/53911: alignment attribute of thread local symbols not
 respected
Date: Sat, 26 Jan 2019 14:35:44 +0100

 Already discussed in "Memory alignment not respected in thread-local
 objects"

 https://mail-index.netbsd.org/tech-toolchain/2018/12/20/msg003356.html

 It's in my opinion it might be a release blocker as this approach is
 becoming a popular optimization technique.

From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: toolchain/53911: alignment attribute of thread local symbols not
 respected
Date: Sat, 26 Jan 2019 15:55:42 +0100

 On Sat, Jan 26, 2019 at 12:15:01AM +0000, tnn@NetBSD.org wrote:
 > Not sure if this should go in toolchain or port-amd64...

 The problem is in ld.elf_so and the (minimalistic) memory allocator it uses.

 Martin

State-Changed-From-To: open->closed
State-Changed-By: tnn@NetBSD.org
State-Changed-When: Tue, 05 Nov 2019 20:31:13 +0000
State-Changed-Why:
I think it's a duplicate of 54093


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.