This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: glibc-2.26 Implementation of signbit in math.h causes problem with C++ programs


Hi Andrew,

Le 24/10/2017 à 11:28, Andrew Paxie a écrit :
> Greetings.
> 
> I read in
> https://sourceware.org/ml/libc-alpha/2017-08/msg00010.html
> that you wanted some feedback on which compilers can support
> glibc 2.26:
> 
>   Older GCC versions and non-GNU compilers are still supported when
>   compiling programs that use the GNU C Library.  (We do not know exactly
>   how old, and some GNU extensions to C may be _de facto_ required.  If you
>   are interested in helping us make this statement less vague, please
>   contact libc-alpha@sourceware.org <mailto:libc-alpha@sourceware.org>.)
> 
> 
> Here's a copy of a defect report I raised with Canonical,
> https://bugs.launchpad.net/ubuntu/+source/glibc/+bug/1725869
> 
> I don't expect to get much help from Canonical with g++-4.8, g++-4.9, or g++-5
> but even if I create my own builds of these compilers they will still be unable
> to interoperate with glibc-2.26 unless a patch is made to <math.h>.
> 
> My use case: I am a contributor to Trompeloeil, a C++ mock object framework,
> which up until now had "broad" support for a number of compilers and C++ standard
> library implementations.  That support got much narrower with this issue.
> See: https://github.com/rollbear/trompeloeil/issues/63
> 
> Environment
> -----------
> 
> Test program compiled on Artful Aardvark Ubuntu 17.10.
> 
> $ which g++-4.8
> /usr/bin/g++-4.8
> 
> $ /usr/bin/g++-4.8 --version
> g++-4.8 (Ubuntu 4.8.5-4ubuntu6) 4.8.5
> Copyright (C) 2015 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions. There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> 
> $ which g++-4.9
> /usr/bin/g++-4.9
> 
> $ /usr/bin/g++-4.9 --version
> g++-4.9 (Ubuntu 4.9.4-2ubuntu1) 4.9.4
> Copyright (C) 2015 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions. There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> 
> $ which g++-5
> /usr/bin/g++-5
> 
> $ /usr/bin/g++-5 --version
> g++-5 (Ubuntu 5.5.0-1ubuntu1) 5.4.1 20171010
> Copyright (C) 2015 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions. There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> 
> $ which g++-6
> /usr/bin/g++-6
> 
> $ /usr/bin/g++-6 --version
> g++-6 (Ubuntu 6.4.0-8ubuntu1) 6.4.0 20171010
> Copyright (C) 2017 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions. There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> 
> $ which g++-7
> /usr/bin/g++-7
> 
> $ /usr/bin/g++-7 --version
> g++-7 (Ubuntu 7.2.0-8ubuntu3) 7.2.0
> Copyright (C) 2017 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions. There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> 
> $ dpkg --status libc6-dev:amd64
> Package: libc6-dev
> Status: install ok installed
> Priority: optional
> Section: libdevel
> Installed-Size: 18041
> Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
> Architecture: amd64
> Multi-Arch: same
> Source: glibc
> Version: 2.26-0ubuntu2
> Provides: libc-dev
> Depends: libc6 (= 2.26-0ubuntu2), libc-dev-bin (= 2.26-0ubuntu2), linux-libc-dev
> (>= 4.13.0)
> Suggests: glibc-doc, manpages-dev
> Breaks: binutils (<< 2.26), binutils-gold (<< 2.20.1-11), cmake (<<
> 2.8.4+dfsg.1-5), gcc-4.4 (<< 4.4.6-4), gcc-4.5 (<< 4.5.3-2), gcc-4.6 (<<
> 4.6.0-12), libhwloc-dev (<< 1.2-3), libjna-java (<< 3.2.7-4), liblouis-dev (<<
> 2.3.0-2), liblouisxml-dev (<< 2.4.0-2), make (<< 3.81-8.1), pkg-config (<< 0.26-1)
> Conflicts: libc0.1-dev, libc0.3-dev, libc6.1-dev
> Description: GNU C Library: Development Libraries and Header Files
>  Contains the symlinks, headers, and object files needed to compile
>  and link programs which use the standard C library.
> Homepage: http://www.gnu.org/software/libc/libc.html
> <http://www.gnu.org/software/libc/libc.html>
> Original-Maintainer: GNU Libc Maintainers <debian-glibc@lists.debian.org>
> 
> Test cases that fail
> --------------------
> 
> $ g++-5 -x c++ - <<EOF
> #include <math.h>
> int main()
> {
>   return signbit(1.0);
> }
> EOF
> 
> In file included from <stdin>:1:0:
> <stdin>: In function ‘int main()’:
> <stdin>:4:10: error: expected primary-expression before ‘__typeof’
> <stdin>:4:10: error: expected primary-expression before ‘float’
> <stdin>:4:10: error: ‘__builtin_types_compatible_p’ was not declared in this scope
> <stdin>:4:10: error: expected primary-expression before ‘__typeof’
> <stdin>:4:10: error: expected primary-expression before ‘double’
> <stdin>:4:10: error: expected primary-expression before ‘__typeof’
> <stdin>:4:10: error: expected primary-expression before ‘long’
> <stdin>:4:10: error: ‘__builtin_choose_expr’ was not declared in this scope
> <stdin>:4:10: error: ‘__builtin_choose_expr’ was not declared in this scope
> <stdin>:4:10: error: redeclaration of ‘<typeprefixerror>__builtin_choose_expr’
> <stdin>:4:10: note: previous declaration ‘<typeprefixerror>__builtin_choose_expr’
> <stdin>:4:10: error: ‘__builtin_choose_expr’ was not declared in this scope
> <stdin>:4:10: error: redeclaration of ‘<typeprefixerror>__builtin_choose_expr’
> <stdin>:4:10: note: previous declaration ‘<typeprefixerror>__builtin_choose_expr’
> 

Indeed, this issue has been fixed recently in the 2.26 stable branch [1].

There are some C++ issues related to __MATH_TG macro and most of them should be
fixed now (as far I can tell).

[1]
https://sourceware.org/git/?p=glibc.git;a=commit;h=f8279a4b3cc66d3ec8bfb8519e9987b8f7727f53

Best regards,
Romain

> $ g++-4.9 -x c++ - <<EOF
> #include <math.h>
> int main()
> {
>   return signbit(1.0);
> }
> EOF
> 
> In file included from <stdin>:1:0:
> <stdin>: In function ‘int main()’:
> <stdin>:4:10: error: expected primary-expression before ‘__typeof’
> <stdin>:4:10: error: expected primary-expression before ‘float’
> <stdin>:4:10: error: ‘__builtin_types_compatible_p’ was not declared in this scope
> <stdin>:4:10: error: expected primary-expression before ‘__typeof’
> <stdin>:4:10: error: expected primary-expression before ‘double’
> <stdin>:4:10: error: expected primary-expression before ‘__typeof’
> <stdin>:4:10: error: expected primary-expression before ‘long’
> <stdin>:4:10: error: ‘__builtin_choose_expr’ was not declared in this scope
> <stdin>:4:10: error: ‘__builtin_choose_expr’ was not declared in this scope
> <stdin>:4:10: error: redeclaration of ‘<typeprefixerror>__builtin_choose_expr’
> <stdin>:4:10: note: previous declaration ‘<typeprefixerror>__builtin_choose_expr’
> <stdin>:4:10: error: ‘__builtin_choose_expr’ was not declared in this scope
> <stdin>:4:10: error: redeclaration of ‘<typeprefixerror>__builtin_choose_expr’
> <stdin>:4:10: note: previous declaration ‘<typeprefixerror>__builtin_choose_expr’
> 
> $ g++-4.8 -x c++ - <<EOF
> #include <math.h>
> int main()
> {
>   return signbit(1.0);
> }
> EOF
> 
> In file included from <stdin>:1:0:
> <stdin>: In function ‘int main()’:
> <stdin>:4:10: error: expected primary-expression before ‘__typeof’
> <stdin>:4:10: error: expected primary-expression before ‘float’
> <stdin>:4:10: error: ‘__builtin_types_compatible_p’ was not declared in this scope
> <stdin>:4:10: error: expected primary-expression before ‘__typeof’
> <stdin>:4:10: error: expected primary-expression before ‘double’
> <stdin>:4:10: error: expected primary-expression before ‘__typeof’
> <stdin>:4:10: error: expected primary-expression before ‘long’
> <stdin>:4:10: error: ‘__builtin_choose_expr’ was not declared in this scope
> <stdin>:4:10: error: ‘__builtin_choose_expr’ was not declared in this scope
> <stdin>:4:10: error: redeclaration of ‘<typeprefixerror>__builtin_choose_expr’
> <stdin>:4:10: note: previous declaration ‘<typeprefixerror>__builtin_choose_expr’
> <stdin>:4:10: error: ‘__builtin_choose_expr’ was not declared in this scope
> <stdin>:4:10: error: redeclaration of ‘<typeprefixerror>__builtin_choose_expr’
> <stdin>:4:10: note: previous declaration ‘<typeprefixerror>__builtin_choose_expr’
> 
> Test cases that succeed
> -----------------------
> 
> $ g++-6 -x c++ - <<EOF
> #include <math.h>
> int main()
> {
>   return signbit(1.0);
> }
> EOF
> 
> $ g++-7 -x c++ - <<EOF
> #include <math.h>
> int main()
> {
>   return signbit(1.0);
> }
> EOF
> 
> Expected result
> ---------------
> 
> Successful compile and return 0.
> 
> Supposed cause
> --------------
> 
> The definition of function-like macro __MATH_TG at
> lines 343-74 of /usr/include/math.h
> requires some finesse to handle C++ programs.
> 
> As noted in
> 
> gcc.gnu.org <http://gcc.gnu.org>, "6.59 Other Built-in Functions Provided by GCC"
> Available: https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
> <https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html>
> Accessed: 22 October 2017
> 
> the built-in functions __builtin_choose_expr and __builtin_types_compatible_p
> are only available in C.
> 
> Workaround
> ----------
> 
> Hack /usr/include/math.h and modify line 346
> 
> #elif __HAVE_DISTINCT_FLOAT128
> 
> to read
> 
> #elif __HAVE_DISTINCT_FLOAT128 && !__cplusplus
> 
> This clearly doesn't cover all the cases but you get the picture.
> 
> Regards
> Andrew Paxie


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]