Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 577238 - sys-devel/gcc-4.8 and above: uclibc/90_all_302-c99-snprintf.patch needs to be updated for c++11 std.
Summary: sys-devel/gcc-4.8 and above: uclibc/90_all_302-c99-snprintf.patch needs to be...
Status: RESOLVED OBSOLETE
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL: https://gcc.gnu.org/bugzilla/show_bug...
Whiteboard:
Keywords:
Depends on:
Blocks: uclibc-porting
  Show dependency tree
 
Reported: 2016-03-12 21:13 UTC by Anthony Basile
Modified: 2018-06-23 22:08 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
90_all_302-c99-c++11.patch (90_all_302-c99-c++11.patch,10.21 KB, patch)
2016-03-12 21:21 UTC, Anthony Basile
Details | Diff
90_all_302-c99-c++11-gcc-4.8.patch (90_all_302-c99-c++11-gcc-4.8.patch,11.01 KB, patch)
2016-03-12 23:17 UTC, Anthony Basile
Details | Diff
90_all_302-c99-c++11-gcc-4.9.patch (90_all_302-c99-c++11-gcc-4.9.patch,10.21 KB, patch)
2016-03-12 23:18 UTC, Anthony Basile
Details | Diff
90_all_302-c99-c++11-gcc-5.patch (90_all_302-c99-c++11-gcc-5.patch,11.18 KB, patch)
2016-03-12 23:19 UTC, Anthony Basile
Details | Diff
90_all_302_gcc-4.9-compat-c99.patch (90_all_302-gcc-4.9-compat-c99.patch,53.05 KB, text/plain)
2016-05-22 17:31 UTC, Anthony Basile
Details
90_all_302_gcc-5.3-compat-c99.patch (90_all_302-gcc-5.3-compat-c99.patch,55.34 KB, text/plain)
2016-05-22 17:31 UTC, Anthony Basile
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Anthony Basile gentoo-dev 2016-03-12 21:13:43 UTC
uclibc conforms to C99 standards and requires _GLIBCXX_USE_C99 to be define when making use of c++ standards.  rather than doing a -D_GLIBCXX_USE_C99 everywhere, we've been patching gcc with 90_all_302-c99-snprintf.patch.  with the c++11 standards, we need to expand this.  for example, g++ fails to find stod in namespace std:

#include <string>
int main() { std::stod("42.0"); }

[i686-uclibc] cyan ~ # g++ -std=c++11 -o yy yy.c 
yy.c: In function 'int main()':
yy.c:2:14: error: 'stod' is not a member of 'std'
 int main() { std::stod("42.0"); }
              ^
of course adding -D_GLIBCXX_USE_C99 would fix this, but its better to expand our patch.
Comment 1 Anthony Basile gentoo-dev 2016-03-12 21:21:09 UTC
Created attachment 428072 [details, diff]
90_all_302-c99-c++11.patch

This patch follows the suggestion of the openadk team, but I believe their patch is missing one instance of _GLIBCXX_USE_C99.

http://cgit.openadk.org/cgi/cgit/openadk.git/tree/toolchain/gcc/patches/4.9.3/libstdcxx-uclibc-c99.patch

Also note that libstdc++-v3 makes use of an lot of defines of the form _GLIBCXX_USE_C99_XXX but these are set by tests defined in acinclude.m4 in a function called GLIBCXX_CHECK_C99_TR1 included in the configure.ac.  ie, we don't need to bother with them.
Comment 2 Anthony Basile gentoo-dev 2016-03-12 21:37:51 UTC
(In reply to Anthony Basile from comment #1)
> Created attachment 428072 [details, diff] [details, diff]
> 90_all_302-c99-c++11.patch
> 
> This patch follows the suggestion of the openadk team, but I believe their
> patch is missing one instance of _GLIBCXX_USE_C99.
> 
> http://cgit.openadk.org/cgi/cgit/openadk.git/tree/toolchain/gcc/patches/4.9.
> 3/libstdcxx-uclibc-c99.patch
> 
> Also note that libstdc++-v3 makes use of an lot of defines of the form
> _GLIBCXX_USE_C99_XXX but these are set by tests defined in acinclude.m4 in a
> function called GLIBCXX_CHECK_C99_TR1 included in the configure.ac.  ie, we
> don't need to bother with them.

sorry that patch only applies cleanly for 4.x.  I'll prepare a clean patch for 5.x.
Comment 3 Anthony Basile gentoo-dev 2016-03-12 23:17:35 UTC
Created attachment 428080 [details, diff]
90_all_302-c99-c++11-gcc-4.8.patch

We need to update this patch for 4.8 because of bug #544756
Comment 4 Anthony Basile gentoo-dev 2016-03-12 23:18:24 UTC
Created attachment 428082 [details, diff]
90_all_302-c99-c++11-gcc-4.9.patch

This is identical to my first patch, I just changed the name so its clear that its for 4.9.
Comment 5 Anthony Basile gentoo-dev 2016-03-12 23:19:06 UTC
Created attachment 428084 [details, diff]
90_all_302-c99-c++11-gcc-5.patch

This applies to 5.1.0, 5.2.0 and 5.3.0.
Comment 6 SpanKY gentoo-dev 2016-05-03 22:58:51 UTC
we should fix/update uClibc so that _GLIBCXX_USE_C99 gets defined.  we want the headers to be C99 compliant.  then this patch won't be needed.
Comment 7 Anthony Basile gentoo-dev 2016-05-20 12:03:40 UTC
(In reply to SpanKY from comment #6)
> we should fix/update uClibc so that _GLIBCXX_USE_C99 gets defined.  we want
> the headers to be C99 compliant.  then this patch won't be needed.

Actually there's a fix in gcc.  The idea is to break up the C99 features check and replace _GLIBCXX_USE_C99 with _GLIBCXX_USE_C99_{STDIO,WCHAR,MATH}, so that we can get the wide string functions, std::to_w?string (WCHAR) without requiring MATH.  Globbing all the features together made it an all or nothing deal.

As an addendum, we could build up uclibc so that it provides everything C99 needs.  According to the bug report that means complex math which could be ported over from glibc and enabled/disabled by a config option to avoid unwanted bloat.  Something for the future maybe.

Bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58393
git commit: bdb62e6a5583c7e41c438d1c29789aee41f8d519

I'm testing it out now to see how cleanly it will backport.
Comment 8 Anthony Basile gentoo-dev 2016-05-22 17:31:12 UTC
Created attachment 434986 [details]
90_all_302_gcc-4.9-compat-c99.patch

Okay this (and the following patch) are big, ~1700 lines.  Most of this is due to `configure`.  So I stripped it down.  Here's what I did:

1. I dropped the changes to ChangeLog and acinclude.m4.  We won't be autoreconf-ing so we don't need acinclude.m4

2. 4.9 doesn't have DragonFly BSD stuff, so the patches to dragonfly/c_locale.h and dragonfly/os_defines.h are useless.  Similarly util/testsuite_fs.h isn't in 4.9.3.

3. There were a lot of whitespace diff's in configure of the form 

 /* end confdefs.h.  */
 #include <math.h>
-      volatile double d1, d2;
-      volatile int i;
+         volatile double d1, d2;
+         volatile int i;

which I collapsed by editing the whitespace in the plus lines to match the - lines.  I then used some git magic to get clean patches.

4. I made no changes to the other diff's, but line numbers were cleaned up.

5. I tested on glibc and uclibc and everything appears to be working.
Comment 9 Anthony Basile gentoo-dev 2016-05-22 17:31:50 UTC
Created attachment 434988 [details]
90_all_302_gcc-5.3-compat-c99.patch
Comment 10 Anthony Basile gentoo-dev 2016-05-22 18:48:36 UTC
In my opinion, while these last two patches are backported from upstream, I think its safest to go with my original patches because the former simply add || defined(__UCLIBC__) which can't make any difference on glibc, while the latter add a more complex testing of a "sharded" _GLIBCXX_USE_C99 which could introduce an error.
Comment 11 SpanKY gentoo-dev 2016-06-13 17:20:39 UTC
i'm fine with extending the hack for <6 versions since upstream seems to have cleaned things up, and the backport is kind of a pita
Comment 12 Anthony Basile gentoo-dev 2016-06-13 17:24:03 UTC
(In reply to SpanKY from comment #11)
> i'm fine with extending the hack for <6 versions since upstream seems to
> have cleaned things up, and the backport is kind of a pita

okay i'll add that to the patchset.
Comment 13 SpanKY gentoo-dev 2016-06-13 18:30:41 UTC
(In reply to Anthony Basile from comment #12)

i'm handling it now w/the gcc-5.4 upgrade.  the updated patch had a typo too which breaks compiling ;).
Comment 14 Anthony Basile gentoo-dev 2016-06-13 18:37:45 UTC
(In reply to SpanKY from comment #13)
> (In reply to Anthony Basile from comment #12)
> 
> i'm handling it now w/the gcc-5.4 upgrade.  the updated patch had a typo too
> which breaks compiling ;).

thanks :)
Comment 15 Joshua Kinard gentoo-dev 2016-11-27 09:11:06 UTC
This patch may no longer be needed for gcc-6.2.0:

# cat yy.cpp
#include <string>
int main() { std::stod("42.0"); }

# g++ -std=c++11 -o yy yy.cpp
# ./yy
# echo $?
0

 # gcc --version
gcc (Gentoo 6.2.0-r1 p1.1) 6.2.0
Copyright (C) 2016 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.

# ldd /usr/mips-unknown-linux-uclibc/gcc-bin/6.2.0/gcc
        libiconv.so.2 => /lib/libiconv.so.2 (0x77c70000)
        libc.so.0 => /lib/libc.so.0 (0x77bb0000)
        ld-uClibc.so.0 => /lib/ld-uClibc.so.0 (0x77db0000)


I have a working, gcc-6.2.x/binutils-2.27/uclibc-ng-1.0.19 with everything but pkgconfig rebuilt using gcc-6.2.x if anyone wants to test things.  It's MIPS-III, Big Endian, though.
Comment 16 Anthony Basile gentoo-dev 2016-11-27 13:27:02 UTC
(In reply to Joshua Kinard from comment #15)
> This patch may no longer be needed for gcc-6.2.0:
> 

it isn't needed in gcc-6.  upstream has a fix, see comment #7.  its just that backporting that particular fix would be a pita, so my original patch was the easier stop gap for gcc-4.9.
Comment 17 Magnus Granberg gentoo-dev 2016-11-27 13:34:29 UTC
Gentoo's gcc 6.2 don't have this patch included in the patchset.
Comment 18 Andreas K. Hüttel archtester gentoo-dev 2018-06-23 22:08:51 UTC
> 
> it isn't needed in gcc-6.  upstream has a fix, see comment #7.  its just
> that backporting that particular fix would be a pita, so my original patch
> was the easier stop gap for gcc-4.9.

closing since <=gcc-5 is masked