[PATCH] glibc __builtin_add_overflow problem with GCC < 7
Paul Eggert
eggert@cs.ucla.edu
Fri Dec 18 20:25:24 GMT 2020
Stefan Liebler's recent glibc commit "s390x: Require GCC 7.1 or later to
build glibc" is motivated by a bug with __builtin_add_overflow that he
encountered on s390x. However, it appears that the underlying GCC bug
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98269
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78559
is platform-independent (I am not sure of this, and am being conservative).
In Gnulib, Bruno Haible worked around the bug today by updating intprops.h
so that INT_ADD_WRAPV does not use __builtin_add_overflow in older GCCs.
When Gnulib intprops.h is copied to glibc this should fix glibc modules like
posix/regexec.c and time/mktime.c that are shared with Gnulib and use
intprops.h and INT_ADD_WRAPV etc.
However, several glibc modules (e.g., malloc/malloc.c) are not shared with
Gnulib and use __builtin_add_overflow directly, so they won't benefit from
the intprops.h fix.
A simple workaround would be to change INSTALL to recommend GCC 7.1 or
higher, as in the first attached patch (configure and sysdeps/s390/configure
files would also need to be regenerated). This patch also rejects icc, as
icc 2021.1 pretends to be GCC 10 but doesn't do proper integer overflow
checking.
Alternatively, if requiring GCC 7.1 is too drastic, glibc could change all
direct uses of __builtin_add_overflow etc. to use intprops.h and
INT_ADD_WRAPV etc., as Adhemerval suggested recently
<https://sourceware.org/pipermail/libc-alpha/2020-December/120855.html>. The
first step in this would be to update intprops.h from Gnulib (which should
be routine anyway), as in the second attached patch. We'd also need to
change malloc/malloc.c etc.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Require-GCC-7.1-or-later.patch
Type: text/x-patch
Size: 7052 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20201218/777b70c7/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Sync-intprops.h-from-Gnulib.patch
Type: text/x-patch
Size: 6624 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20201218/777b70c7/attachment-0003.bin>
More information about the Libc-alpha
mailing list