From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org
Subject: alignasof, stdalign: Fix a compilation error on FreeBSD 12.0
Date: Tue, 24 Jan 2023 14:02:34 +0100 [thread overview]
Message-ID: <2593218.SeglcFtGQu@nimes> (raw)
[-- Attachment #1: Type: text/plain, Size: 2269 bytes --]
On FreeBSD 12.0/i386 I get a compilation error when building a testdir
for module 'rawmemchr'.
On the master branch, the first error is:
In file included from ../../gllib/rawmemchr.c:17:
In file included from ../config.h:1018:
In file included from /usr/include/stddef.h:41:
/usr/include/sys/_types.h:106:35: error: expected expression
long long __max_align1 __aligned(_Alignof(long long));
^
../config.h:964:39: note: expanded from macro '_Alignof'
# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
^
On the stable-202301 branch, the first error is:
In file included from ../../gllib/rawmemchr.c:17:
In file included from ../config.h:925:
In file included from ./stdalign.h:131:
In file included from /usr/include/stddef.h:41:
/usr/include/sys/_types.h:106:35: error: expected expression
long long __max_align1 __aligned(_Alignof(long long));
^
./stdalign.h:70:36: note: expanded from macro '_Alignof'
# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
^
What happens is that
- config.h includes <stdalign.h>, per the patch that I submitted in
<https://lists.gnu.org/archive/html/bug-gnulib/2022-09/msg00144.html>.
- This <stdalign.h> is the gnulib-generated one.
(In <https://lists.gnu.org/archive/html/bug-gnulib/2022-09/msg00144.html>
the purpose of my patch was to avoid including the gnulib-generated
stdalign.h, but it did not achieve that goal since on this platform
HAVE_STDALIGN_H is 1, following these configure findings:
checking for stdalign.h... yes
checking for alignas and alignof... no
. Anyway.)
- At the end of <stdalign.h>, <stddef.h> gets included.
- <stddef.h> includes <sys/_types.h>, which attempts to define max_align_t.
For this it uses _Alignof(long long), which expands to
offsetof (struct { char __a; long long __b; }, __b)
- But at this point offsetof is not yet defined (since <stddef.h> is still
being included).
The following patch fixes it. One in master, a different one for the
stable-202301 branch. (On the stable-202207 branch there is no problem.)
[-- Attachment #2: 0001-master-alignasof-stdalign-Fix-a-compilation-error-on-FreeBS.patch --]
[-- Type: text/x-patch, Size: 1800 bytes --]
From b323b5297757c5c904e6aff63454c777703361ce Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Tue, 24 Jan 2023 13:44:07 +0100
Subject: [PATCH] alignasof, stdalign: Fix a compilation error on FreeBSD 12.0.
* m4/stdalign.m4 (gl_ALIGNASOF): In C mode, prefer __builtin_offsetof
over offsetof when possible, since __builtin_offsetof works also when
<stddef.h> has not been fully included yet.
---
ChangeLog | 7 +++++++
m4/stdalign.m4 | 8 ++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 759310346b..f999f105a5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-01-24 Bruno Haible <bruno@clisp.org>
+
+ alignasof, stdalign: Fix a compilation error on FreeBSD 12.0.
+ * m4/stdalign.m4 (gl_ALIGNASOF): In C mode, prefer __builtin_offsetof
+ over offsetof when possible, since __builtin_offsetof works also when
+ <stddef.h> has not been fully included yet.
+
2023-01-22 Bruno Haible <bruno@clisp.org>
doc: Update list of target platforms.
diff --git a/m4/stdalign.m4 b/m4/stdalign.m4
index 0bb9281f5e..6a0ab2c102 100644
--- a/m4/stdalign.m4
+++ b/m4/stdalign.m4
@@ -112,8 +112,12 @@ AC_DEFUN([gl_ALIGNASOF],
# define _GL_STDALIGN_NEEDS_STDDEF 1
# endif
# else
-# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
-# define _GL_STDALIGN_NEEDS_STDDEF 1
+# if (defined __GNUC__ && 4 <= __GNUC__) || defined __clang__
+# define _Alignof(type) __builtin_offsetof (struct { char __a; type __b; }, __b)
+# else
+# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
+# define _GL_STDALIGN_NEEDS_STDDEF 1
+# endif
# endif
# endif
# if ! (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER))
--
2.34.1
[-- Attachment #3: 0001-stable-stdalign-Fix-a-compilation-error-on-FreeBSD-12.0.patch --]
[-- Type: text/x-patch, Size: 2604 bytes --]
From 1f4fe409ea4379c3e537507822151e135be758d8 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Tue, 24 Jan 2023 13:36:11 +0100
Subject: [PATCH] stdalign: Fix a compilation error on FreeBSD 12.0.
* lib/stdalign.in.h (_Alignof): In C mode, prefer __builtin_offsetof
over offsetof when possible, since __builtin_offsetof works also when
<stddef.h> has not been fully included yet.
* m4/stdalign.m4 (gl_STDALIGN_H): Likewise.
---
ChangeLog | 8 ++++++++
lib/stdalign.in.h | 8 ++++++--
m4/stdalign.m4 | 8 ++++++--
3 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ca8306d1e4..bd7fd9ab5d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-01-24 Bruno Haible <bruno@clisp.org>
+
+ stdalign: Fix a compilation error on FreeBSD 12.0.
+ * lib/stdalign.in.h (_Alignof): In C mode, prefer __builtin_offsetof
+ over offsetof when possible, since __builtin_offsetof works also when
+ <stddef.h> has not been fully included yet.
+ * m4/stdalign.m4 (gl_STDALIGN_H): Likewise.
+
2023-01-22 Paul Eggert <eggert@cs.ucla.edu>
sigsegv, vma-iter: port to Solaris 10
diff --git a/lib/stdalign.in.h b/lib/stdalign.in.h
index 17357810c7..7f9dbb466e 100644
--- a/lib/stdalign.in.h
+++ b/lib/stdalign.in.h
@@ -66,8 +66,12 @@
# define _GL_STDALIGN_NEEDS_STDDEF 1
# endif
# else
-# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
-# define _GL_STDALIGN_NEEDS_STDDEF 1
+# if (defined __GNUC__ && 4 <= __GNUC__) || defined __clang__
+# define _Alignof(type) __builtin_offsetof (struct { char __a; type __b; }, __b)
+# else
+# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
+# define _GL_STDALIGN_NEEDS_STDDEF 1
+# endif
# endif
#endif
#if ! (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER))
diff --git a/m4/stdalign.m4 b/m4/stdalign.m4
index b1438eeace..dc2971753d 100644
--- a/m4/stdalign.m4
+++ b/m4/stdalign.m4
@@ -93,8 +93,12 @@ AC_DEFUN([gl_STDALIGN_H],
# define _GL_STDALIGN_NEEDS_STDDEF 1
# endif
# else
-# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
-# define _GL_STDALIGN_NEEDS_STDDEF 1
+# if (defined __GNUC__ && 4 <= __GNUC__) || defined __clang__
+# define _Alignof(type) __builtin_offsetof (struct { char __a; type __b; }, __b)
+# else
+# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
+# define _GL_STDALIGN_NEEDS_STDDEF 1
+# endif
# endif
# endif
# if ! (defined __cplusplus && (201103 <= __cplusplus || defined _MSC_VER))
--
2.34.1
next reply other threads:[~2023-01-24 13:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-24 13:02 Bruno Haible [this message]
2023-01-24 13:34 ` alignasof, stdalign: Fix a compilation error on FreeBSD 12.0 Bruno Haible
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
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2593218.SeglcFtGQu@nimes \
--to=bruno@clisp.org \
--cc=bug-gnulib@gnu.org \
/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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).