Bug 22296 - glibc 2.26: signbit build issue with Gcc 5.5.0 on x86_64
Summary: glibc 2.26: signbit build issue with Gcc 5.5.0 on x86_64
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: math (show other bugs)
Version: 2.26
: P2 normal
Target Milestone: 2.27
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-10-14 17:25 UTC by romain.naour
Modified: 2018-03-31 12:41 UTC (History)
3 users (show)

See Also:
Host:
Target: 2.27
Build:
Last reconfirmed:
fweimer: security-


Attachments
gcc config.log (7.22 KB, text/x-log)
2017-10-14 17:25 UTC, romain.naour
Details
libstdc++-v3 config.log (28.58 KB, text/x-log)
2017-10-15 17:58 UTC, romain.naour
Details

Note You need to log in before you can comment on or make changes to this bug.
Description romain.naour 2017-10-14 17:25:21 UTC
Created attachment 10527 [details]
gcc config.log

Hi,

I'm using a toolchain with gcc 5.5.0, glibc-2.26 (latest stable commit) and binutils 2.27.

Mesa fail to build with the following error:

In file included from ../../include/c99_math.h:37:0,
                 from ../../src/gallium/auxiliary/util/u_math.h:44,
                 from ../../src/mesa/main/macros.h:35,
                 from glsl_types.cpp:25:
../../src/mesa/main/macros.h: In the function ‘GLboolean DIFFERENT_SIGNS(GLfloat, GLfloat)’:
../../src/mesa/main/macros.h:794:11: error : expected primary-expression before ‘__typeof’
    return signbit(x) != signbit(y);
           ^
../../src/mesa/main/macros.h:794:11: error : expected primary-expression before ‘float’
    return signbit(x) != signbit(y);
           ^
../../src/mesa/main/macros.h:794:11: error : ‘__builtin_types_compatible_p’ was not declared in this scope
    return signbit(x) != signbit(y);
           ^
../../src/mesa/main/macros.h:794:11: error : expected primary-expression before ‘__typeof’
    return signbit(x) != signbit(y);
           ^
../../src/mesa/main/macros.h:794:11: error : expected primary-expression before ‘double’
    return signbit(x) != signbit(y);
           ^
../../src/mesa/main/macros.h:794:11: error : expected primary-expression before ‘__typeof’
    return signbit(x) != signbit(y);
           ^
../../src/mesa/main/macros.h:794:11: error : expected primary-expression before ‘long’
    return signbit(x) != signbit(y);
           ^
../../src/mesa/main/macros.h:794:11: error : ‘__builtin_choose_expr’ was not declared in this scope
    return signbit(x) != signbit(y);
           ^
../../src/mesa/main/macros.h:794:11: error : ‘__builtin_choose_expr’ was not declared in this scope
    return signbit(x) != signbit(y);
           ^
../../src/mesa/main/macros.h:794:11: error : redeclaration of ‘<typeprefixerror>__builtin_choose_expr’
../../src/mesa/main/macros.h:794:11: note : previous declaration ‘<typeprefixerror>__builtin_choose_expr’
    return signbit(x) != signbit(y);
           ^
../../src/mesa/main/macros.h:794:11: error : ‘__builtin_choose_expr’ was not declared in this scope
    return signbit(x) != signbit(y);
           ^
../../src/mesa/main/macros.h:794:11: error : redeclaration of ‘<typeprefixerror>__builtin_choose_expr’
../../src/mesa/main/macros.h:794:11: note : previous declaration ‘<typeprefixerror>__builtin_choose_expr’
    return signbit(x) != signbit(y);
           ^
../../src/mesa/main/macros.h:794:25: error : expected primary-expression before ‘__typeof’
    return signbit(x) != signbit(y);
                         ^
../../src/mesa/main/macros.h:794:25: error : expected primary-expression before ‘float’
    return signbit(x) != signbit(y);
                         ^
../../src/mesa/main/macros.h:794:25: error : expected primary-expression before ‘__typeof’
    return signbit(x) != signbit(y);
                         ^
../../src/mesa/main/macros.h:794:25: error : expected primary-expression before ‘double’
    return signbit(x) != signbit(y);
                         ^
../../src/mesa/main/macros.h:794:25: error : expected primary-expression before ‘__typeof’
    return signbit(x) != signbit(y);
                         ^
../../src/mesa/main/macros.h:794:25: error : expected primary-expression before ‘long’
    return signbit(x) != signbit(y);
                         ^

It seems related to this code in glibc math/math.h :

/* Return nonzero value if sign of X is negative.  */
# if __GNUC_PREREQ (6,0)
#  define signbit(x) __builtin_signbit (x)
# elif __GNUC_PREREQ (4,0)
#  define signbit(x) __MATH_TG ((x), __builtin_signbit, (x))
# else
#  define signbit(x) __MATH_TG ((x), __signbit, (x))
# endif

The macro __MATH_TG is defined latter in this file:

#ifdef __NO_LONG_DOUBLE_MATH
[...]
#elif __HAVE_DISTINCT_FLOAT128
# if __HAVE_GENERIC_SELECTION
[...]
# else
#  define __MATH_TG(TG_ARG, FUNC, ARGS)					\
     __builtin_choose_expr						\
     (__builtin_types_compatible_p (__typeof (TG_ARG), float),		\
      FUNC ## f ARGS,							\
      __builtin_choose_expr						\
      (__builtin_types_compatible_p (__typeof (TG_ARG), double),	\
       FUNC ARGS,							\
       __builtin_choose_expr						\
       (__builtin_types_compatible_p (__typeof (TG_ARG), long double),	\
	FUNC ## l ARGS,							\
	FUNC ## f128 ARGS)))
# endif
#else
[...]

For some reason, the macros __builtin_choose_expr and __builtin_types_compatible_p are not defined with gcc 5.5.0.
It look like an issue with float128 support.

Best regards,
Romain
Comment 1 romain.naour 2017-10-15 17:58:39 UTC
Created attachment 10530 [details]
libstdc++-v3 config.log

There is the same issue while configuring libstdc++:

configure:16710: checking for ISO C99 support in <math.h>
configure:16779:  /home/naourr/toolchains/x86_64-gcc5.5-glibc-2.26.x/build/host-gcc-final-5.5.0/build/./gcc/xgcc -shared-libgcc -B/home/naourr/toolchains/x86_64-gcc5.5-glibc-2.26.x/build/host-gcc-final-5.5.0/build/./gcc -nostdinc++ -L/home/naourr/toolchains/x86_64-gcc5.5-glibc-2.26.x/build/host-gcc-final-5.5.0/build/x86_64-buildroot-linux-gnu/libstdc++-v3/src -L/home/naourr/toolchains/x86_64-gcc5.5-glibc-2.26.x/build/host-gcc-final-5.5.0/build/x86_64-buildroot-linux-gnu/libstdc++-v3/src/.libs -L/home/naourr/toolchains/x86_64-gcc5.5-glibc-2.26.x/build/host-gcc-final-5.5.0/build/x86_64-buildroot-linux-gnu/libstdc++-v3/libsupc++/.libs -B/home/naourr/toolchains/x86_64-gcc5.5-glibc-2.26.x/host/x86_64-buildroot-linux-gnu/bin/ -B/home/naourr/toolchains/x86_64-gcc5.5-glibc-2.26.x/host/x86_64-buildroot-linux-gnu/lib/ -isystem /home/naourr/toolchains/x86_64-gcc5.5-glibc-2.26.x/host/x86_64-buildroot-linux-gnu/include -isystem /home/naourr/toolchains/x86_64-gcc5.5-glibc-2.26.x/host/x86_64-buildroot-linux-gnu/sys-include    -o conftest -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -Os  -D_GNU_SOURCE -std=c++98 -fno-exceptions   conftest.cpp  -lm >&5
In file included from conftest.cpp:36:0:
conftest.cpp: In function 'int main()':
conftest.cpp:47:11: error: expected primary-expression before '__typeof'
       i = signbit(d1);
           ^
conftest.cpp:47:11: error: expected primary-expression before 'float'
       i = signbit(d1);
           ^
conftest.cpp:47:11: error: '__builtin_types_compatible_p' was not declared in this scope
       i = signbit(d1);
           ^
conftest.cpp:47:11: error: expected primary-expression before '__typeof'
       i = signbit(d1);
           ^
conftest.cpp:47:11: error: expected primary-expression before 'double'
       i = signbit(d1);
           ^
conftest.cpp:47:11: error: expected primary-expression before '__typeof'
       i = signbit(d1);
           ^
conftest.cpp:47:11: error: expected primary-expression before 'long'
       i = signbit(d1);
           ^
conftest.cpp:47:11: error: '__builtin_choose_expr' was not declared in this scope
       i = signbit(d1);
           ^
conftest.cpp:47:11: error: '__builtin_choose_expr' was not declared in this scope
       i = signbit(d1);
           ^
conftest.cpp:47:11: error: redeclaration of '<typeprefixerror>__builtin_choose_expr'
conftest.cpp:47:11: note: previous declaration '<typeprefixerror>__builtin_choose_expr'
       i = signbit(d1);
           ^
conftest.cpp:47:11: error: '__builtin_choose_expr' was not declared in this scope
       i = signbit(d1);
           ^
conftest.cpp:47:11: error: redeclaration of '<typeprefixerror>__builtin_choose_expr'
conftest.cpp:47:11: note: previous declaration '<typeprefixerror>__builtin_choose_expr'
       i = signbit(d1);
           ^
configure:16779: $? = 1
Comment 2 cvs-commit@gcc.gnu.org 2017-10-17 14:13:10 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  386e1c26ac473d6863133ab9cbe3bbda16c15816 (commit)
      from  3d265601358974c9be8264e53dadd8f9aea5690c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=386e1c26ac473d6863133ab9cbe3bbda16c15816

commit 386e1c26ac473d6863133ab9cbe3bbda16c15816
Author: Romain Naour <romain.naour@gmail.com>
Date:   Mon Oct 16 23:21:56 2017 +0200

    Let signbit use the builtin in C++ mode with gcc < 6.x (bug 22296)
    
    When using gcc < 6.x, signbit does not use the type-generic
    __builtin_signbit builtin, instead it uses __MATH_TG.
    However, when library support for float128 is available, __MATH_TG uses
    __builtin_types_compatible_p, which is not available in C++ mode.
    
    On the other hand, libstdc++ undefines (in cmath) many macros from
    math.h, including signbit, so that it can provide its own functions.
    However, during its configure tests, libstdc++ just tests for the
    availability of the macros (it does not undefine them, nor does it
    provide its own functions).
    
    Finally, libstdc++ configure tests include math.h and get the definition
    of signbit that uses __MATH_TG (and __builtin_types_compatible_p).
    Since libstdc++ does not undefine the macros during its configure
    tests, they fail.
    
    This patch lets signbit use the builtin in C++ mode when gcc < 6.x is
    used. This allows the configure test in libstdc++ to work.
    
    Tested for x86_64.
    
    	[BZ #22296]
    	* math/math.h: Let signbit use the builtin in C++ mode with gcc
    	< 6.x
    
    Cc: Gabriel F. T. Gomes <gftg@linux.vnet.ibm.com>
    Cc: Joseph Myers <joseph@codesourcery.com>

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog   |    6 ++++++
 math/math.h |    9 +++++++++
 2 files changed, 15 insertions(+), 0 deletions(-)
Comment 3 joseph@codesourcery.com 2017-10-17 16:38:14 UTC
If the commit fixes the bug, please mark it as FIXED with target milestone 
set to 2.27.
Comment 4 romain.naour 2017-10-17 19:45:53 UTC
Fixed by https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=386e1c26ac473d6863133ab9cbe3bbda16c15816

Change the status to FIXED.
Comment 5 cvs-commit@gcc.gnu.org 2017-10-23 00:51:26 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, release/2.26/master has been updated
       via  b1b8d8aa95a055dc7929259679a995189d444809 (commit)
       via  f8279a4b3cc66d3ec8bfb8519e9987b8f7727f53 (commit)
      from  f82a6fc223cbd890b9de9007cfce63e6cae8f799 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=b1b8d8aa95a055dc7929259679a995189d444809

commit b1b8d8aa95a055dc7929259679a995189d444809
Author: Gabriel F. T. Gomes <gabriel@inconstante.eti.br>
Date:   Fri Oct 20 16:06:19 2017 -0200

    Add missing bug fixes to NEWS

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=f8279a4b3cc66d3ec8bfb8519e9987b8f7727f53

commit f8279a4b3cc66d3ec8bfb8519e9987b8f7727f53
Author: Romain Naour <romain.naour@gmail.com>
Date:   Mon Oct 16 23:21:56 2017 +0200

    Let signbit use the builtin in C++ mode with gcc < 6.x (bug 22296)
    
    When using gcc < 6.x, signbit does not use the type-generic
    __builtin_signbit builtin, instead it uses __MATH_TG.
    However, when library support for float128 is available, __MATH_TG uses
    __builtin_types_compatible_p, which is not available in C++ mode.
    
    On the other hand, libstdc++ undefines (in cmath) many macros from
    math.h, including signbit, so that it can provide its own functions.
    However, during its configure tests, libstdc++ just tests for the
    availability of the macros (it does not undefine them, nor does it
    provide its own functions).
    
    Finally, libstdc++ configure tests include math.h and get the definition
    of signbit that uses __MATH_TG (and __builtin_types_compatible_p).
    Since libstdc++ does not undefine the macros during its configure
    tests, they fail.
    
    This patch lets signbit use the builtin in C++ mode when gcc < 6.x is
    used. This allows the configure test in libstdc++ to work.
    
    Tested for x86_64.
    
    	[BZ #22296]
    	* math/math.h: Let signbit use the builtin in C++ mode with gcc
    	< 6.x
    
    Cc: Gabriel F. T. Gomes <gftg@linux.vnet.ibm.com>
    Cc: Joseph Myers <joseph@codesourcery.com>
    (cherry picked from commit 386e1c26ac473d6863133ab9cbe3bbda16c15816)

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog   |    6 ++++++
 NEWS        |    3 +++
 math/math.h |    9 +++++++++
 3 files changed, 18 insertions(+), 0 deletions(-)
Comment 6 Carlos O'Donell 2018-02-01 20:34:50 UTC
This bug is on 2.27 stable branch, removing glibc_2.27 tag.