From: Alexander Monakov <amonakov@ispras.ru>
To: musl@lists.openwall.com
Subject: Re: [musl] Alignment attribute in headers
Date: Sun, 21 Apr 2024 19:44:12 +0300 (MSK) [thread overview]
Message-ID: <53dd583b-06b2-3503-7343-222c46c6ab64@ispras.ru> (raw)
In-Reply-To: <Pine.BSM.4.64L.2404211547150.25471@herc.mirbsd.org>
[-- Attachment #1: Type: text/plain, Size: 1399 bytes --]
On Sun, 21 Apr 2024, Thorsten Glaser wrote:
> Michael Forney dixit:
>
> >Something like
> >
> >#if __STDC_VERSION__ >= 201112L
> >/* use _Alignas */
> >#elif defined(__cplusplus) && !defined(__GNUC__)
> >/* use alignas */
> >#else
> >/* use __attribute__((__aligned__(N))) */
> >#end
>
> Something I noticed recently while doing m68k alignment work:
>
> The C++ alignas is UB if the specified alignment is smaller
> than what the structure would normally have, so adding cautious
> alignments can explode in one’s face. ☹ Not only is this really
> stupid, but makes it not generally usable, too.
>
> GCC’s attribute, in contrast, (without __packed__) just gets
> ignored for those cases.
This is inaccurate: you can use the attribute to decrease alignment
of scalar types (but you do need __packed__ when attaching the attribute
to a struct). As I recall, GCC documentation used to be misleading
or wrong about this, but the current wording is fairly clear to me:
When used on a struct, or struct member, the aligned attribute can
only increase the alignment; in order to decrease it, the packed
attribute must be specified as well. When used as part of a typedef,
the aligned attribute can both increase and decrease alignment, and
specifying the packed attribute generates a warning.
https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html
Alexander
next prev parent reply other threads:[~2024-04-21 16:44 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-21 3:51 Michael Forney
2024-04-21 4:54 ` Markus Wichmann
2024-04-21 7:16 ` Jₑₙₛ Gustedt
2024-04-21 7:38 ` Markus Wichmann
2024-04-21 10:23 ` Jₑₙₛ Gustedt
2024-04-21 10:31 ` Sam James
2024-04-21 17:40 ` Markus Wichmann
2024-04-21 15:50 ` Thorsten Glaser
2024-04-21 16:44 ` Alexander Monakov [this message]
2024-04-21 17:20 ` Markus Wichmann
2024-04-21 18:23 ` Thorsten Glaser
2024-04-21 19:04 ` Michael Forney
2024-04-21 23:48 ` Rich Felker
2024-04-24 0:45 ` Michael Forney
2024-04-24 2:54 ` Markus Wichmann
2024-04-24 7:39 ` Jon Chesterfield
2024-04-24 7:55 ` Jeffrey Walton
2024-04-24 9:49 ` Jon Chesterfield
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53dd583b-06b2-3503-7343-222c46c6ab64@ispras.ru \
--to=amonakov@ispras.ru \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).