[PATCH v3 2/7] malloc/obstack.h: Assume GCC supports __extension__
Alejandro Colomar
alx@kernel.org
Mon Nov 10 23:31:47 GMT 2025
Hi Joseph,
On Mon, Nov 10, 2025 at 06:32:38PM +0000, Joseph Myers wrote:
> On Mon, 10 Nov 2025, Alejandro Colomar wrote:
>
> > GCC supports __extension__ since at least GCC 2.8.
>
> This is a file shared with gnulib, but __extension__ is generally only
> relevant with -pedantic; there's no problem with supporting its absence
> with non-GCC compilers, so no real advantage in removing this code.
>
> In fact, GCC 2.7 (the oldest version supporting ELF for any target
> supported now by glibc) *does* support __extension__, so the more
> interesting question about such a condition is whether there are specific
> sub-cases of __extension__ that are used in installed headers and are the
> reason for the 2.8 version here.
git-blame(1) in gnulib points to this:
commit 6421fd46004655f39afca254ad02b72ab97f5ecb
Author: Paul Eggert <eggert@cs.ucla.edu>
Date: Thu Mar 27 13:38:41 2014 -0700
obstack: Remove ancient NeXTSTEP gcc support conditional
This change will ease merging with glibc. The "#if ... __NEXT__"
causes a warning with -Wundef which glibc now enables by default.
Problem reported by Will Newton in
<http://lists.gnu.org/archive/html/bug-gnulib/2014-03/msg00032.html>.
glibc <sys/cdefs.h> now uses __extension__ for GCC 2.8 or later,
so go with that.
* lib/obstack.h (__extension__):
[...]
diff --git a/lib/obstack.h b/lib/obstack.h
index f847a53706..f92492fc68 100644
--- a/lib/obstack.h
+++ b/lib/obstack.h
@@ -258,10 +258,7 @@ extern int obstack_exit_failure;
#define obstack_memory_used(h) _obstack_memory_used (h)
#if defined __GNUC__
-/* NextStep 2.0 cc is really gcc 1.93 but it defines __GNUC__ = 2 and
- does not implement __extension__. But that compiler doesn't define
- __GNUC_MINOR__. */
-# if __GNUC__ < 2 || (__NeXT__ && !__GNUC_MINOR__)
+# if ! (2 < __GNUC__ + (8 <= __GNUC_MINOR__))
# define __extension__
# endif
That commit message probably refers to this in glibc:
$ cat ./misc/sys/cdefs.h | grep -C2 __extension__
/* It is possible to compile containing GCC extensions even if GCC is
run in pedantic mode if the uses are carefully marked using the
`__extension__' keyword. But this is not generally available before
version 2.8. */
#if !(__GNUC_PREREQ (2,8) || defined __clang__)
# define __extension__ /* Ignore */
#endif
However, it seems to ignore this:
commit bc244b778ac3e17089454050ac86662ad51f7fd0
Author: Jim Meyering <jim@meyering.net>
Date: Fri Nov 4 16:50:15 1994 +0000
merge with 3.9u1
[...]
diff --git a/lib/obstack.h b/lib/obstack.h
index 01767195da..840a63baaa 100644
--- a/lib/obstack.h
+++ b/lib/obstack.h
[...]
@@ -269,7 +269,10 @@ int obstack_chunk_size (struct obstack *obstack);
#define obstack_blank_fast(h,n) ((h)->next_free += (n))
^L
#if defined (__GNUC__) && defined (__STDC__)
-#if __GNUC__ < 2
+/* NextStep 2.0 cc is really gcc 1.93 but it defines __GNUC__ = 2 and
+ does not implement __extension__. But that compiler doesn't define
+ __GNUC_MINOR__. */
+#if __GNUC__ < 2 || !__GNUC_MINOR__
#define __extension__
#endif
Which claims that GCC 2 is fine with __extension__.
The commit that added the 2.8 check in <sys/cdefs.h> is
8325d82cf391 (1998-10-05; "Update."), whose ChangeLog only says:
1998-10-05 Ulrich Drepper <drepper@cygnus.com>
* misc/sys/cdefs.h (__extension__): Define as empty if no gcc or
gcc before 2.8 is used.
so, I don't really know why Ulrich did that. There's some possibility
that he was wrong. Or maybe it was really not widely available on some
GCC forks that claimed different __GNUC__ and __GNUC_MINOR__ values.
Who knows.
Have a lovely night!
Alex
--
<https://www.alejandro-colomar.es>
Use port 80 (that is, <...:80/>).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20251111/9bf5065f/attachment.sig>
More information about the Libc-alpha
mailing list