NetBSD Problem Report #52571

From www@NetBSD.org  Mon Sep 25 16:54:16 2017
Return-Path: <www@NetBSD.org>
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 1A4957A212
	for <gnats-bugs@gnats.NetBSD.org>; Mon, 25 Sep 2017 16:54:16 +0000 (UTC)
Message-Id: <20170925165415.4DB217A297@mollari.NetBSD.org>
Date: Mon, 25 Sep 2017 16:54:15 +0000 (UTC)
From: bruno@clisp.org
Reply-To: bruno@clisp.org
To: gnats-bugs@NetBSD.org
Subject: max_align_t has smaller alignment than double
X-Send-Pr-Version: www-1.0

>Number:         52571
>Category:       standards
>Synopsis:       max_align_t has smaller alignment than double
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    standards-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Sep 25 16:55:00 +0000 2017
>Closed-Date:    Mon Sep 09 11:44:47 +0000 2024
>Last-Modified:  Wed Sep 11 19:25:01 +0000 2024
>Originator:     Bruno Haible
>Release:        netbsd-8 201709170600Z
>Organization:
GNU
>Environment:
NetBSD netbsd8 8.0_BETA NetBSD 8.0_BETA (GENERIC.201709170600Z) i386
>Description:
max_align_t is supposed to have the largest alignment among the standard C types. But here, __alignof__(max_align_t) < __alignof__(double).

This breaks compilation of some GNU packages, because gnulib has a compile-time assertion:
verify(__alignof__ (double) <= __alignof__ (max_align_t));

>How-To-Repeat:
Compile this file:
=============================
#include <stddef.h>
int aaa = __alignof__(double);
int aab = __alignof__(max_align_t);
=============================
gcc -S x.c
You can see that aaa has the value 8, whereas aab has the value 4.

>Fix:

>Release-Note:

>Audit-Trail:
From: Joerg Sonnenberger <joerg@bec.de>
To: gnats-bugs@NetBSD.org
Cc: standards-manager@netbsd.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org
Subject: Re: standards/52571: max_align_t has smaller alignment than double
Date: Tue, 26 Sep 2017 10:57:18 +0200

 On Mon, Sep 25, 2017 at 04:55:00PM +0000, bruno@clisp.org wrote:
 > max_align_t is supposed to have the largest alignment among the
 > standard C types. But here, __alignof__(max_align_t) < __alignof__(double).

 So this one is a nice excercise in GCC extensions and why they sometimes
 don't give you what you think they do. Compare the following test case
 on i386 with and without USE_ALIGNOF:

 #include <stddef.h>

 struct foo {
   double x;
   char t;
 };

 int main() {
 #ifdef USE_ALIGNOF
   return __alignof__(double);
 #else
   return sizeof(struct foo) - offsetof(struct foo, t);
 #endif
 }

 ---

 For the SYSV ABI (not the bastardized version Linux is nowadays using),
 the ABI alignment of double is 32bit, but most compiler use a prefered
 alignment of 64bit. Similar for long double.

 Joerg

State-Changed-From-To: open->closed
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Mon, 09 Sep 2024 11:44:47 +0000
State-Changed-Why:
This is a bizarre quirk of gcc's __alignof__ extension, not NetBSD's
fault.  Use the standard _Alignof instead.  For example, compare the
sizes of symbols from the following definitions:

char gcc_alignof_double[__alignof__(double)];
char gcc_alignof_uniondouble[__alignof__(union { double x; })];
char stdc_alignof_double[_Alignof(double)];
char stdc_alignof_uniondouble[_Alignof(union { double x; })];

When I compile this with i386 gcc -std=c11 and dump the symbols with
`readelf -s', I get:

   Num:    Value  Size Type    Bind   Vis      Ndx Name
...
     2: 00000000     8 OBJECT  GLOBAL DEFAULT    3 gcc_alignof_double
     3: 00000008     4 OBJECT  GLOBAL DEFAULT    3 gcc_alignof_uniondouble
     4: 0000000c     4 OBJECT  GLOBAL DEFAULT    3 stdc_alignof_double
     5: 00000010     4 OBJECT  GLOBAL DEFAULT    3 stdc_alignof_uniondouble

Whatever gcc's __alignof__ gives you is not the required alignment: if
it were, it would have to agree with the plain double and the
union-of-double cases, but it doesn't.


From: =?UTF-8?Q?J=C3=B6rg_Sonnenberger?= <joerg@bec.de>
To: gnats-bugs@netbsd.org, standards-manager@netbsd.org,
 netbsd-bugs@netbsd.org, gnats-admin@netbsd.org, riastradh@NetBSD.org,
 bruno@clisp.org
Cc: 
Subject: Re: standards/52571 (max_align_t has smaller alignment than double)
Date: Wed, 11 Sep 2024 21:24:12 +0200

 GCC has two different alignments. It has a minimal ABI alignment and a 
 preferred alignment. In the SYSV ABI for i386, the biggest alignment is 
 32bit. It is beneficial for certain types to aligned more if it can be 
 done cheaply, that's why a global variable of type double for example is 
 naturally aligned.

 Joerg

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.