Bug 239648 - lang/gcc9 on powerpc64 defines _GNU_SOURCE by default
Summary: lang/gcc9 on powerpc64 defines _GNU_SOURCE by default
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: powerpc Any
: --- Affects Some People
Assignee: Gerald Pfeifer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-04 18:00 UTC by Piotr Kubaj
Modified: 2019-08-17 07:16 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Piotr Kubaj freebsd_committer freebsd_triage 2019-08-04 18:00:48 UTC
G++9 (only C++) defines _GNU_SOURCE by default. This breaks some ports (e.g. https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=239627 ) on GCC architectures. After further investigation, I pinpointed it to /usr/local/lib/gcc9/gcc/powerpc64-portbld-freebsd12.0/9.1.0/plugin/include/config/gnu-user.h, which has this line:
#define CPLUSPLUS_CPP_SPEC "-D_GNU_SOURCE %(cpp)"

GCC8 didn't set it, this problem only appeared in 9.
Comment 1 Piotr Kubaj freebsd_committer freebsd_triage 2019-08-04 18:06:53 UTC
(In reply to Piotr Kubaj from comment #0)
I'm trying this patch:
--- gcc/config/gnu-user.h.orig  2019-08-04 18:05:25 UTC
+++ gcc/config/gnu-user.h
@@ -92,7 +92,7 @@ see the files COPYING3 and COPYING.RUNTIME respectivel

 /* The GNU C++ standard library requires that these macros be defined.  */
 #undef CPLUSPLUS_CPP_SPEC
-#define CPLUSPLUS_CPP_SPEC "-D_GNU_SOURCE %(cpp)"
+#define CPLUSPLUS_CPP_SPEC "%(cpp)"

 #define GNU_USER_TARGET_NO_PTHREADS_LIB_SPEC \
   "%{shared:-lc} \
Comment 2 Piotr Kubaj freebsd_committer freebsd_triage 2019-08-04 18:13:34 UTC
(In reply to Piotr Kubaj from comment #1)
Hm, looks like this macro was added 9 years ago, but for some reason this file isn't installed for GCC8 (only GCC9 started installing it).
Comment 3 Piotr Kubaj freebsd_committer freebsd_triage 2019-08-04 18:18:30 UTC
(In reply to Piotr Kubaj from comment #2)
Comment at the top of this file is:
/* Definitions for systems using, at least optionally, a GNU
   (glibc-based) userspace or other userspace with libc derived from
   glibc (e.g. uClibc) or for which similar specs are appropriate.

It seems plainly wrong to install this file on FreeBSD.
Comment 4 Gerald Pfeifer freebsd_committer freebsd_triage 2019-08-04 19:48:59 UTC
Thanks for the report and first analysis, Piotr.

At first I was surprised why this did not manifest on i386 or x86-64,
but a little research makes me think this is specific to ppc (or rs6000
in GCC-land).  And was introduced by

  https://gcc.gnu.org/ml/gcc-patches/2018-11/msg00921.html

which states

  This patch removes some duplication in rs6000/sysv4.h of macros found
  in gnu-user.h that we want for linux.  Including gnu-user.h will mean
  powerpc doesn't miss updates to that file.

  Requires https://gcc.gnu.org/ml/gcc-patches/2018-11/msg00917.html and
  https://gcc.gnu.org/ml/gcc-patches/2018-11/msg00919.html

  Bootstrapped etc. powerpc-linux and powerpc64le-linux.

	* config.gcc (powerpc*-*-freebsd*, powerpc-*-netbsd*),
	(powerpc-*-eabisimaltivec*, powerpc-*-eabisim*, powerpc-*-elf*),
	(powerpc-*-eabialtivec*, powerpc-*-eabi*, powerpc-*-rtems*),
	(powerpc-wrs-vxworks*, powerpc-*-lynxos*, powerpcle-*-elf*),
	(powerpcle-*-eabisim*, powerpcle-*-eabi*): Add gnu-user.h to tm_file.
	* config/rs6000/freebsd.h (CPLUSPLUS_CPP_SPEC),
	(LINK_GCC_C_SEQUENCE_SPEC): Undef.
	(ASM_APP_ON, ASM_APP_OFF): Don't define.
	* config/rs6000/freebsd64.h (ASM_APP_ON, ASM_APP_OFF): Don't define.
        :
Comment 5 Piotr Kubaj freebsd_committer freebsd_triage 2019-08-04 19:55:21 UTC
(In reply to Gerald Pfeifer from comment #4)
Thanks for your comment, I was just about to send comment with https://gcc.gnu.org/viewcvs/gcc/trunk/gcc/config.gcc?r1=266496&r2=266495&pathrev=266496

:)

Trying to revert it now.
Comment 6 Piotr Kubaj freebsd_committer freebsd_triage 2019-08-04 20:36:51 UTC
After reverting, it fails to build with:
/usr/local/poudriere/ports/default/lang/gcc9/work/gcc-9.1.0/gcc/config/rs6000/sysv4.h:774:9: error: expected ',' or ';' before 'GNU_USER_TARGET_LIB_SPEC'
      :" GNU_USER_TARGET_LIB_SPEC "}"
         ^~~~~~~~~~~~~~~~~~~~~~~~

Looks like it needs gnu-user.h after all. Maybe we should put #ifndef __FreeBSD__ around CPLUSPLUS_CPP_SPEC?
Comment 7 Piotr Kubaj freebsd_committer freebsd_triage 2019-08-04 20:40:09 UTC
(In reply to Piotr Kubaj from comment #6)
Oh, sysv4.h also needs reverting.

I will look at it tomorrow...
Comment 8 Gerald Pfeifer freebsd_committer freebsd_triage 2019-08-04 22:01:00 UTC
Let's take a step back, breathe, and involve upstream instead of creating
random hacks that are definitely not upstreamable.

In fact, this would have been a perfect bug report upstream and actually
necessary to flag the regression and get any fixes into the GCC 9 release
branch.

So I went ahead and just did that, copying the original author of what I
believe causes this:

   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91349
Comment 9 Piotr Kubaj freebsd_committer freebsd_triage 2019-08-04 22:40:27 UTC
(In reply to Gerald Pfeifer from comment #8)
I compared the changes done in that commit to freebsd.h and freebsd64.h and noticed that freebsd64.h misses:
/* Undef gnu-user.h macros we don't want.  */
#undef CPLUSPLUS_CPP_SPEC
#undef LINK_GCC_C_SEQUENCE_SPEC

I'm compiling right now gcc9 with those undefs and build progresses fine. Other than that, there are no changes.
Comment 10 Piotr Kubaj freebsd_committer freebsd_triage 2019-08-05 11:05:44 UTC
That change works and I can see it's already committed upstream and merged to 9.

Can you patch lang/gcc9?
Comment 11 Andreas Tobler freebsd_committer freebsd_triage 2019-08-05 19:57:36 UTC
I'm not really keen on patching that hack. The whole gnu-user.h thing is not very convenient. I'd like to wait until the guys found a suitable solution.
Comment 12 Piotr Kubaj freebsd_committer freebsd_triage 2019-08-05 20:06:24 UTC
(In reply to Andreas Tobler from comment #11)
I agree, but currently many ports don't build on powerpc64 because of _GNU_SOURCE. Either tens of ports are patched not to use the code that is behind _GNU_SOURCE check, or gcc itself is fixed.
Comment 13 Andreas Tobler freebsd_committer freebsd_triage 2019-08-05 20:25:36 UTC
I see. Give me 24h and we see if there is a better solution till then. Otherwise I can 'patch' lang/gcc9(-devel) and lang/gcc10-devel.
Comment 14 Gerald Pfeifer freebsd_committer freebsd_triage 2019-08-05 20:36:32 UTC
Thank you, Andreas!

Note that in the upstream bug I filed 
  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91349
there is also a discussion about the patch that got committed upstream.

(I agree the upstream approached Alan took end of last year was not
exactly elegant, but diverging from upstream is not a good options I
guess, so are you going to propose something there?)
Comment 15 Andreas Tobler freebsd_committer freebsd_triage 2019-08-05 20:40:10 UTC
I won't. And I try not to diverge from upstream but I try to avoid needless patch cycles.
Comment 16 Andreas Tobler freebsd_committer freebsd_triage 2019-08-06 21:11:31 UTC
I will not patch gcc9, gcc-9.2 is coming soon, and it contains the fix. gcc9-devel and gcc10-devel will contain the 'fix' in the next update. Soon means next week if all goes well.
Comment 17 commit-hook freebsd_committer freebsd_triage 2019-08-11 09:27:49 UTC
A commit references this bug:

Author: gerald
Date: Sun Aug 11 09:27:26 UTC 2019
New revision: 508592
URL: https://svnweb.freebsd.org/changeset/ports/508592

Log:
  Update to the 20180803 snapshot of GCC 9.1.1.

  This brings a larger number of backports for the testsuite, a fix for
  Fortran, one for rs6000 (aka powerpc*) and most importantly now longer
  has _GNU_SOURCE defined on powerpc64 (which was a regression from the
  GCC 8 series [1]).

  PR:		239648 [1]

Changes:
  head/lang/gcc9-devel/Makefile
  head/lang/gcc9-devel/distinfo
Comment 18 Gerald Pfeifer freebsd_committer freebsd_triage 2019-08-11 09:29:24 UTC
This should address the issue for lang/gcc9-devel.

Can you please verify and let me know it does for you?
Comment 19 commit-hook freebsd_committer freebsd_triage 2019-08-12 07:31:25 UTC
A commit references this bug:

Author: gerald
Date: Mon Aug 12 07:30:35 UTC 2019
New revision: 508710
URL: https://svnweb.freebsd.org/changeset/ports/508710

Log:
  Ensure _GNU_SOURCE is now longer defined on powerpc64 (which was a
  regression from the GCC 8 series).

  The technical background is that a consolidation in upstream GCC made
  non-GNU platforms include gnu-user.h and then undefined some macros
  in rs6000/freebsd.h, but missed doing the same in rs6000/freebsd64.h.

  The has now been included upstream and the current snapshot that the
  lang/gcc9-devel port tracks; carrying files/patch-powerpc64-no-_GNU_SOURCE
  in this port should become obsolete with the GCC 9.2 release.

  (As this should be a very short-lived measure, bump PORTREVISION only
  for powerpc64 to avoid all other users having to rebuild, too.)

  PR:		239648

Changes:
  head/lang/gcc9/Makefile
  head/lang/gcc9/files/patch-powerpc64-no-_GNU_SOURCE
Comment 20 commit-hook freebsd_committer freebsd_triage 2019-08-14 07:08:45 UTC
A commit references this bug:

Author: gerald
Date: Wed Aug 14 07:08:20 UTC 2019
New revision: 508894
URL: https://svnweb.freebsd.org/changeset/ports/508894

Log:
  Update to the 201900811 snapshot of GCC 10.0.0.

  This no longer has _GNU_SOURCE defined on powerpc64 (which was a
  regression from the GCC 8 series). [1]

  PR:		239648 [1]

Changes:
  head/lang/gcc10-devel/Makefile
  head/lang/gcc10-devel/distinfo
Comment 21 Gerald Pfeifer freebsd_committer freebsd_triage 2019-08-14 07:13:42 UTC
With that, all affected ports -- lang/gcc9{,-devel} and lang/gcc10 --
should be addressed, either by now referring to upstream snapshots that
have (in case of the -devel ports) or a local backport (in case of gcc9).

If you are using/building on powerpc64, please still do advise if this
matches your understanding and experience.
Comment 22 commit-hook freebsd_committer freebsd_triage 2019-08-17 07:16:57 UTC
A commit references this bug:

Author: gerald
Date: Sat Aug 17 07:16:27 UTC 2019
New revision: 509141
URL: https://svnweb.freebsd.org/changeset/ports/509141

Log:
  Update to GCC 9.2 release, the second in the GCC 9 series, which fixes
  some 68 bugs.

  This is the default version of GCC in the Ports Collection, and it just
  got a bit more polish and stability.

  Both files/patch-amd64-gcc-multilib-support and
  files/patch-powerpc64-no-_GNU_SOURCE [1] have been integrated upstream
  (and also been part of lang/gcc9-devel already), so remove them here.

  PR:		239648 [1]

Changes:
  head/lang/gcc9/Makefile
  head/lang/gcc9/distinfo
  head/lang/gcc9/files/patch-amd64-gcc-multilib-support
  head/lang/gcc9/files/patch-powerpc64-no-_GNU_SOURCE