mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] Alignment attribute in headers
@ 2024-04-21  3:51 Michael Forney
  2024-04-21  4:54 ` Markus Wichmann
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Michael Forney @ 2024-04-21  3:51 UTC (permalink / raw)
  To: musl

I'm looking at changing headers to use C11 alignment specifiers
when available instead of GNU attributes.

These are used in the following headers:

	arch/loongarch64/bits/signal.h
	arch/powerpc/bits/signal.h
	arch/powerpc/bits/user.h
	arch/powerpc64/bits/signal.h
	arch/powerpc64/bits/user.h
	arch/riscv32/bits/signal.h
	arch/riscv64/bits/signal.h
	arch/x32/bits/shm.h

In some of these cases (powerpc, powerpc64, x32), the attribute is
conditional on __GNUC__, which I think may result in improperly
aligned structs on compilers that don't define this.

For powerpc/powerpc64 user.h, the attribute is applied to a typedef
of a struct, but alignas can't be used with typedef. I think this
could be fixed by moving the attribute/alignment specifier to the
first (and only) struct member instead.

Similarly, x32 shm.h uses an attribute after a struct specifier,
which could be made compatible with an alignment specifier in the
same way.

I also noticed that arch/i386/bits/alltypes.h.in uses _Alignas(8)
for C, __attribute__((__aligned__(8))) for GNU C++, and alignas(8)
for non-GNU C++. Looking through commit history, this seems to be
a work around for a gcc 4.7 bug which claims C++11 support but
doesn't offer alignas.

Do we need to use this same approach for each of the instances above
to handle the three cases (C, GNU C++, non-GNU C++)?

I see that stdalign.h uses _Alignas conditional on C11 support, but
i386 alltypes.h uses it unconditionally on C. Should i386 alltypes.h
use __attribute__ when __STDC_VERSION__ < 201112L?

Something like

#if __STDC_VERSION__ >= 201112L
/* use _Alignas */
#elif defined(__cplusplus) && !defined(__GNUC__)
/* use alignas */
#else
/* use __attribute__((__aligned__(N))) */
#end

?

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2024-04-24  9:49 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-21  3:51 [musl] Alignment attribute in headers 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
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

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).