Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 581406

Summary: Compiling >=sys-devel/gcc-5 with a cross-compiler using architecture dependent CXXFLAGS fails with "g++: error: unrecognized command line option"
Product: Gentoo Linux Reporter: Peter Levine <plevine457>
Component: Current packagesAssignee: Gentoo Crossdev team <crossdev>
Status: RESOLVED FIXED    
Severity: normal CC: chewi, landshark, matoro_bugzilla_gentoo, netbox253, plevine457, slyfox, wtt6, xaviermiller
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: armv7a-hardfloat-linux-gnueabi-emerge --info
sys-devel:gcc-5.2.0:20160428-015537.log
gcc-5-respect-build-cxxflags.patch
gcc-build-logs.tar.bz2

Description Peter Levine 2016-04-28 02:14:05 UTC
Compiling sys-devel/gcc-5.* with a cross-compiler using architecture dependent CXXFLAGS such as -mfpu=neon-vfpv4 causes it to fail with "g++: error: unrecognized command line option '-mfpu=neon-vfpv4'"

GCC seems to properly set CXXFLAGS_FOR_BUILD in it's Makefile  but doesn't properly export it to modules that need it, such as libcpp. It would initially use it to build tools that need to be compiled and run natively.  Instead, they pickup the host/target CXXFLAGS which is likely the wrong ARCH.
Comment 1 Peter Levine 2016-04-28 02:15:56 UTC
Created attachment 432356 [details]
armv7a-hardfloat-linux-gnueabi-emerge --info
Comment 2 Peter Levine 2016-04-28 02:17:33 UTC
Created attachment 432358 [details]
sys-devel:gcc-5.2.0:20160428-015537.log
Comment 3 Peter Levine 2016-04-28 02:21:44 UTC
Created attachment 432360 [details, diff]
gcc-5-respect-build-cxxflags.patch

This is a patch to gcc-5.* to properly handle CXXFLAGS_FOR_BUILD in its Makefile.  It applies cleanly to gcc-5.1.0, gcc-5.2.0, and gcc-5.3.0.
Comment 4 Xavier Miller (RETIRED) gentoo-dev 2016-09-22 07:14:53 UTC
Created attachment 447296 [details]
gcc-build-logs.tar.bz2

# armv6j-hardfloat-linux-gnueabi-emerge --info '=sys-devel/gcc-5.4.0::gentoo'

Portage 2.3.1 (python 2.7.12-final-0, default/linux/arm/13.0/armv6j, gcc-5.4.0, glibc-2.23-r2, 4.7.4-gentoo x86_64)
=================================================================
                         System Settings
=================================================================
System uname: Linux-4.7.4-gentoo-x86_64-Intel-R-_Celeron-R-_2957U_@_1.40GHz-with-gentoo-2.3
KiB Mem:     3967644 total,    470888 free
KiB Swap:    2097148 total,   2097124 free
Timestamp of repository gentoo: Tue, 20 Sep 2016 08:30:01 +0000
sh bash 4.3_p46
ld GNU ld (Gentoo 2.26.1 p1.0) 2.26.1
distcc 3.2rc1 x86_64-gentoo-linux-gnu [disabled]
app-shells/bash:          4.3_p46::gentoo
dev-lang/python:          3.4.5::gentoo
sys-apps/baselayout:      2.3::gentoo
sys-apps/openrc:          0.21.7::gentoo
sys-apps/sandbox:         2.10-r2::gentoo
sys-devel/binutils:       2.26.1::gentoo
sys-devel/gcc-config:     1.8-r1::gentoo
sys-devel/make:           4.2.1::gentoo
sys-kernel/linux-headers: 4.7::gentoo (virtual/os-headers)
sys-libs/glibc:           2.23-r2::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000

local
    location: /usr/local/portage/overlay
    masters: gentoo proaudio gentoo-kodi-overlay
    priority: 0

gentoo-kodi-overlay
    location: /usr/local/portage/gentoo-kodi-overlay
    masters: gentoo
    priority: 1

proaudio
    location: /var/lib/layman/proaudio
    masters: gentoo
    priority: 50

xmw
    location: /var/lib/layman/xmw
    masters: gentoo
    priority: 50

ACCEPT_KEYWORDS="arm ~arm"
ACCEPT_LICENSE="@FREE as-is freedist"
CBUILD="x86_64-gentoo-linux-gnu"
CFLAGS="-O2 -pipe -march=armv6j -mfpu=vfp -mfloat-abi=hard -fomit-frame-pointer"
CHOST="armv6j-hardfloat-linux-gnueabi"
CONFIG_PROTECT="/boot/cmdline.txt /boot/config.txt /etc /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/php/apache2-php7.0/ext-active/ /etc/php/cgi-php7.0/ext-active/ /etc/php/cli-php7.0/ext-active/ /etc/revdep-re"
CXXFLAGS="-O2 -pipe -march=armv6j -mfpu=vfp -mfloat-abi=hard -fomit-frame-pointer"
DISTDIR="/data/raspi_root/var/portage/distfiles"
EMERGE_DEFAULT_OPTS="--with-bdeps y --quiet-build=n --buildpkg"
FCFLAGS="-O2 -pipe -march=armv6j"
FEATURES="assume-digests binpkg-logs buildpkg candy config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync news parallel-fetch preserve-libs protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerg"
FFLAGS="-O2 -pipe -march=armv6j"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="fr_BE.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j5 -l2"
PKGDIR="/data/raspi_root/var/portage/packages"
PORTAGE_CONFIGROOT="/usr/armv6j-hardfloat-linux-gnueabi/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/."
PORTAGE_TMPDIR="/var/tmp"
USE="arm bzip2 cli cracklib crypt cxx dri iconv modules ncurses nls nptl openmp pcre readline seccomp session sqlite ssl tcpd unicode xattr zlib" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_"
Unset:  CC, CPPFLAGS, CTARGET, CXX, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, USE_PYTHON
Comment 5 Xavier Miller (RETIRED) gentoo-dev 2016-09-22 08:46:14 UTC
 With attachment 432360 [details, diff], gcc-5.4.0 can be cross-compiled
Comment 6 Fab 2017-04-22 09:23:40 UTC
Confirming the cross-building failure in my armv7a environment for gcc-5.4.0-r3.
Applying attachment 432360 [details, diff] makes it build.
Comment 7 James Le Cuirot gentoo-dev 2017-11-10 21:30:20 UTC
This is still a problem in 6.4.0 (the patch still applies) and I can see that it hasn't even been fixed in gcc master. :(
Comment 8 matoro archtester 2018-09-10 17:16:45 UTC
This is still somehow an issue on =sys-devel/gcc-8.2.0-r2.  How has this patch not been either 1) added to the official gentoo patchset or 2) merged upstream?
Comment 9 Sergei Trofimovich (RETIRED) gentoo-dev 2018-09-15 13:24:46 UTC
(In reply to matoro from comment #8)
> This is still somehow an issue on =sys-devel/gcc-8.2.0-r2.  How has this
> patch not been either 1) added to the official gentoo patchset or 2) merged
> upstream?

No reason. Feel free to send it upstream and post a link here.

The patch looks reasonable. I'll test it locally and apply to gentoo's gcc if it works.
Comment 10 Larry the Git Cow gentoo-dev 2018-09-15 18:41:04 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/gcc-patches.git/commit/?id=52d8f44f45d244184d737cec5a26a1754f877e75

commit 52d8f44f45d244184d737cec5a26a1754f877e75
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2018-09-15 18:40:09 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2018-09-15 18:40:09 +0000

    Pass CXXFLAGS as CXXFLAGS_FOR_BUILD to stage1.
    
    Fixes build failure when CXXFLAGS contains TARGET-specific flags.
    
    Tested on x86_64-pc-linux-gnu host as:
        # CFLAGS='-O2 -mfpu=neon-vfpv4' CXXFLAGS='-O2 -mfpu=neon-vfpv4' \
            armv7a-unknown-linux-gnueabihf-emerge -v1 sys-devel/gcc --quiet-build=n
    
    Fix by Peter Levine.
    
    Bug: https://bugs.gentoo.org/581406
    Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

 5.4.0/gentoo/98_all_respect-build-cxxflags.patch  | 39 +++++++++++++++++++++++
 5.4.0/gentoo/README.history                       |  2 ++
 6.4.0/gentoo/102_all_respect-build-cxxflags.patch | 39 +++++++++++++++++++++++
 6.4.0/gentoo/README.history                       |  1 +
 7.3.0/gentoo/100_all_respect-build-cxxflags.patch | 39 +++++++++++++++++++++++
 7.3.0/gentoo/README.history                       |  1 +
 8.2.0/gentoo/102_all_respect-build-cxxflags.patch | 39 +++++++++++++++++++++++
 8.2.0/gentoo/README.history                       |  1 +
 8 files changed, 161 insertions(+)
Comment 11 Sergei Trofimovich (RETIRED) gentoo-dev 2018-09-15 18:42:24 UTC
Patch is included in next patchset for 5.4.0, 6.4.0, 7.3.0, 8.2.0.

Meanwhile you can use /etc/portage/patches/ mechanism to workaround the failure.
Comment 12 Larry the Git Cow gentoo-dev 2018-09-23 22:36:20 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=fb5d77d453273447b9a1d7c63a0f8a09b0840e84

commit fb5d77d453273447b9a1d7c63a0f8a09b0840e84
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2018-09-23 21:04:12 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2018-09-23 22:35:59 +0000

    sys-devel/gcc: cut 1.10 patchset for 5.4.0
    
    One new patch:
    + 98_all_respect-build-cxxflags.patch
      fix cross-build for arch-specific CXXFLAGS
    
    Bug: https://bugs.gentoo.org/581406
    Package-Manager: Portage-2.3.49, Repoman-2.3.11

 sys-devel/gcc/Manifest            |  1 +
 sys-devel/gcc/gcc-5.4.0-r5.ebuild | 44 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=a8ff963554a3e28f8cd5905180b5c5428d1df7b8

commit a8ff963554a3e28f8cd5905180b5c5428d1df7b8
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2018-09-23 20:54:48 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2018-09-23 22:35:58 +0000

    sys-devel/gcc: cut 1.7 patchset for 6.4.0
    
    Two new patches:
    + 101_all_x32-fix-eh-return-address.patch
      fix exception handler ABI on x32
    + 102_all_respect-build-cxxflags.patch
      fix cross-build for arch-specific CXXFLAGS
    
    Bug: https://bugs.gentoo.org/664016
    Bug: https://bugs.gentoo.org/581406
    Package-Manager: Portage-2.3.49, Repoman-2.3.11

 sys-devel/gcc/Manifest            |  1 +
 sys-devel/gcc/gcc-6.4.0-r4.ebuild | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+)

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=fd1aa67de92c05d6a066e84ba5cd4236e637629e

commit fd1aa67de92c05d6a066e84ba5cd4236e637629e
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2018-09-23 20:48:40 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2018-09-23 22:35:58 +0000

    sys-devel/gcc: cut 1.7 patchset for 7.3.0
    
    Three new patches:
    + 98_all_msp430-partial-int.patch:
      fix msp430 code generator on complex types
    + 99_all_x32-fix-eh-return-address.patch
      fix exception handler ABI on x32
    + 100_all_respect-build-cxxflags.patch
      fix cross-build for arch-specific CXXFLAGS
    
    Bug: https://bugs.gentoo.org/664014
    Bug: https://bugs.gentoo.org/664016
    Bug: https://bugs.gentoo.org/581406
    Package-Manager: Portage-2.3.49, Repoman-2.3.11

 sys-devel/gcc/Manifest            |  1 +
 sys-devel/gcc/gcc-7.3.0-r5.ebuild | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+)

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=c7ec432dc64cefa8de88292efcc134cc8e9306c9

commit c7ec432dc64cefa8de88292efcc134cc8e9306c9
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2018-09-23 20:36:46 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2018-09-23 22:35:58 +0000

    sys-devel/gcc: cut 1.3 patchset for 8.2.0
    
    Four new patches:
    + 101_all_x32-fix-eh-return-address.patch:
      fix exception handler ABI on x32
    + 102_all_respect-build-cxxflags.patch:
      fix cross-build for arch-specific CXXFLAGS
    + 103_all_mmix-fix-85666-p1.patch
    + 104_all_mmix-fix-85666-p2.patch
      backport mmix support
    
    Bug: https://bugs.gentoo.org/664016
    Bug: https://bugs.gentoo.org/581406
    Package-Manager: Portage-2.3.49, Repoman-2.3.11

 sys-devel/gcc/Manifest            |  1 +
 sys-devel/gcc/gcc-8.2.0-r3.ebuild | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)
Comment 13 Sergei Trofimovich (RETIRED) gentoo-dev 2018-10-27 21:18:17 UTC
*** Bug 653898 has been marked as a duplicate of this bug. ***
Comment 14 Sergei Trofimovich (RETIRED) gentoo-dev 2018-11-27 23:39:05 UTC
*** Bug 645920 has been marked as a duplicate of this bug. ***