bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FYI: s390x: Require GCC 7.1 or later to build glibc due to __builtin


From: Bruno Haible
Subject: Re: FYI: s390x: Require GCC 7.1 or later to build glibc due to __builtin_add_overflow
Date: Fri, 18 Dec 2020 13:14:20 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-197-generic; KDE/5.18.0; x86_64; ; )

Stefan Liebler wrote:
> just as information, I've committed the glibc patch
> 
> "s390x: Require GCC 7.1 or later to build glibc."
> http://sourceware.org/git/?p=glibc.git;a=commit;h=844b4d8b4b937fe6943d2c0c80ce7d871cdb1eb5
> 
> as if build with gcc 6.5.0, __builtin_add_overflow incorrectly detects
> overflow on s390x.
> 
> Please find the link to gcc-Bug on the discussion on libc-alpha:
> ...
> >> (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98269)
> > 
> > In any case, it would be good to alert gnulib developers about this
> > potential issue.

Thanks for the heads-up. Indeed, what I understand from this bug report is that
the condition code handling (required by __builtin_add_overflow on many
platforms) was unreliable before 2017-01-27, i.e. in GCC versions < 7.
So, gnulib shouldn't make use of it in these GCC versions.


2020-12-18  Bruno Haible  <bruno@clisp.org>

        intprops: Avoid potentially buggy __builtin_add_overflow in GCC 5, 6.
        Reported by Stefan Liebler <stli@linux.ibm.com> in
        <https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00152.html>.
        * lib/intprops.h (_GL_HAS_BUILTIN_ADD_OVERFLOW): Don't define for
        GCC 5.x and 6.x.
        * lib/glob.c (size_add_wrapv): Don't use __builtin_add_overflow for
        GCC 5.x and 6.x.

diff --git a/lib/intprops.h b/lib/intprops.h
index 8cc8138..2472962 100644
--- a/lib/intprops.h
+++ b/lib/intprops.h
@@ -226,7 +226,9 @@
 
 /* True if __builtin_add_overflow (A, B, P) and __builtin_sub_overflow
    (A, B, P) work when P is non-null.  */
-#if 5 <= __GNUC__ && !defined __ICC
+/* __builtin_{add,sub}_overflow exists but is not reliable in GCC 5.x and 6.x,
+   see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98269>.  */
+#if 7 <= __GNUC__ && !defined __ICC
 # define _GL_HAS_BUILTIN_ADD_OVERFLOW 1
 #elif defined __has_builtin
 # define _GL_HAS_BUILTIN_ADD_OVERFLOW __has_builtin (__builtin_add_overflow)
diff --git a/lib/glob.c b/lib/glob.c
index 32e2e11..3c444d3 100644
--- a/lib/glob.c
+++ b/lib/glob.c
@@ -227,7 +227,7 @@ glob_lstat (glob_t *pglob, int flags, const char *fullname)
 static bool
 size_add_wrapv (size_t a, size_t b, size_t *r)
 {
-#if 5 <= __GNUC__ && !defined __ICC
+#if 7 <= __GNUC__ && !defined __ICC
   return __builtin_add_overflow (a, b, r);
 #else
   *r = a + b;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]