Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 871150 - dev-lang/go fails to compile on mips with sys-devel/binutils-2.39 and CGO_ENABLED
Summary: dev-lang/go fails to compile on mips with sys-devel/binutils-2.39 and CGO_ENA...
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: MIPS Linux
: Normal normal (vote)
Assignee: William Hubbs
URL: https://github.com/golang/go/issues/5...
Whiteboard:
Keywords:
Depends on:
Blocks: binutils-2.39
  Show dependency tree
 
Reported: 2022-09-18 02:56 UTC by matoro
Modified: 2023-07-30 16:43 UTC (History)
5 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description matoro archtester 2022-09-18 02:56:10 UTC
With sys-devel/binutils-2.39, dev-lang/go spits out a bunch of errors during linking the final stage that look like:

+ ./cmd/dist/dist bootstrap -a
Building Go toolchain1 using /usr/lib/go-bootstrap.
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
Building Go toolchain2 using go_bootstrap and Go toolchain1.
Building Go toolchain3 using go_bootstrap and Go toolchain2.
Building packages and commands for linux/mips64.
# cmd/trace
/var/tmp/portage/dev-lang/go-1.19.1/work/go/pkg/tool/linux_mips64/link: running mips64-unknown-linux-gnu-gcc failed: exit status 1
/var/tmp/portage/dev-lang/go-1.19.1/temp/go-link-3757955373/go.o: in function `internal/cpu.Initialize':
/usr/lib/go/src/internal/cpu/cpu.go:123:(.text+0x14): relocation R_MIPS_26 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu.go:124:(.text+0x30): relocation R_MIPS_HI16 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/var/tmp/portage/dev-lang/go-1.19.1/temp/go-link-3757955373/go.o: in function `internal/cpu.Initialize':
/usr/lib/go/src/internal/cpu/cpu_mips64x.go:22:(.text+0x40): relocation R_MIPS_26 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/var/tmp/portage/dev-lang/go-1.19.1/temp/go-link-3757955373/go.o: in function `internal/cpu.doinit':
/usr/lib/go/src/internal/cpu/cpu_mips64x.go:23:(.text+0x54): relocation R_MIPS_HI16 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu_mips64x.go:23:(.text+0x64): relocation R_MIPS_HI16 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu_mips64x.go:22:(.text+0x78): relocation R_MIPS_HI16 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu_mips64x.go:22:(.text+0x84): relocation R_MIPS_HI16 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu_mips64x.go:22:(.text+0x90): relocation R_MIPS_HI16 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu_mips64x.go:22:(.text+0xa4): relocation R_MIPS_HI16 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu_mips64x.go:22:(.text+0xb8): relocation R_MIPS_HI16 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu_mips64x.go:22:(.text+0xc4): relocation R_MIPS_26 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu_mips64x.go:27:(.text+0xcc): relocation R_MIPS_HI16 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu_mips64x.go:27:(.text+0xe4): relocation R_MIPS_HI16 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/var/tmp/portage/dev-lang/go-1.19.1/temp/go-link-3757955373/go.o: in function `internal/cpu.Initialize':
/usr/lib/go/src/internal/cpu/cpu.go:125:(.text+0x100): relocation R_MIPS_26 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/var/tmp/portage/dev-lang/go-1.19.1/temp/go-link-3757955373/go.o: in function `internal/cpu.processOptions':
/usr/lib/go/src/internal/cpu/cpu.go:148:(.text+0x130): relocation R_MIPS_26 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu.go:180:(.text+0x34c): relocation R_MIPS_HI16 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu.go:187:(.text+0x368): relocation R_MIPS_HI16 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu.go:175:(.text+0x384): relocation R_MIPS_26 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu.go:175:(.text+0x38c): relocation R_MIPS_HI16 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu.go:175:(.text+0x3a4): relocation R_MIPS_26 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu.go:175:(.text+0x3bc): relocation R_MIPS_26 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu.go:175:(.text+0x3c4): relocation R_MIPS_HI16 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu.go:175:(.text+0x3dc): relocation R_MIPS_26 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu.go:175:(.text+0x3f4): relocation R_MIPS_26 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu.go:175:(.text+0x3fc): relocation R_MIPS_HI16 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu.go:175:(.text+0x414): relocation R_MIPS_26 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu.go:175:(.text+0x41c): relocation R_MIPS_26 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu.go:163:(.text+0x43c): relocation R_MIPS_26 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu.go:163:(.text+0x444): relocation R_MIPS_HI16 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu.go:163:(.text+0x45c): relocation R_MIPS_26 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC
/usr/lib/go/src/internal/cpu/cpu.go:163:(.text+0x474): relocation R_MIPS_26 against `a local symbol' cannot be used when making a shared object; recompile with -fPIC


Thousands of these messages, presumably one for every single local symbol.

Setting CGO_ENABLED=0 in the ebuild removes the issue, but the build you get will encounter the same problem for any golang packages that are attempted to be built unless CGO_ENABLED=0 is also set for them.  This completely removes the ability to build cgo-required projects like go-sqlite.

Reverting to sys-devel/binutils-2.38 also removes the issue, this works without the CGO_ENABLED workaround.

Reproducible: Always




Portage 3.0.36 (python 3.10.7-final-0, default/linux/mips/17.0/n64, gcc-12.2.0, glibc-2.35-r8, 5.19.9-gentoo-mips mips64)
=================================================================
System uname: Linux-5.19.9-gentoo-mips-mips64-Cavium_Octeon_II_V0.10-with-glibc2.35
KiB Mem:     8151216 total,   4664052 free
KiB Swap:          0 total,         0 free
Timestamp of repository gentoo: Sat, 17 Sep 2022 18:02:03 +0000
Head commit of repository gentoo: b12ecc26ce0b2ca611566fdae3bb9d28b45338d8

sh bash 5.1_p16-r2
ld GNU ld (Gentoo 2.38 p4) 2.38
app-misc/pax-utils:        1.3.5::gentoo
app-shells/bash:           5.1_p16-r2::gentoo
dev-lang/perl:             5.36.0::gentoo
dev-lang/python:           3.10.7::gentoo, 3.11.0_rc2::gentoo
dev-lang/rust:             1.63.0-r1::gentoo
dev-util/cmake:            3.24.2::gentoo
dev-util/meson:            0.63.2-r1::gentoo
sys-apps/baselayout:       2.8-r2::gentoo
sys-apps/openrc:           0.45.2::gentoo
sys-apps/sandbox:          2.29::gentoo
sys-devel/autoconf:        2.71-r2::gentoo
sys-devel/automake:        1.16.5::gentoo
sys-devel/binutils:        2.38-r2::gentoo, 2.39-r2::gentoo
sys-devel/binutils-config: 5.4.1::gentoo
sys-devel/gcc:             12.2.0::gentoo
sys-devel/gcc-config:      2.5-r1::gentoo
sys-devel/libtool:         2.4.7::gentoo
sys-devel/make:            4.3::gentoo
sys-kernel/linux-headers:  5.19::gentoo (virtual/os-headers)
sys-libs/glibc:            2.35-r8::gentoo
Repositories:

gentoo
    location: /var/db/repos/gentoo
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/gentoo
    sync-user: portage:portage
    priority: -1000

guru
    location: /var/lib/layman/guru
    sync-type: laymansync
    sync-uri: https://anongit.gentoo.org/git/repo/proj/guru.git
    masters: gentoo
    priority: 50

ACCEPT_KEYWORDS="mips ~mips"
ACCEPT_LICENSE="@FREE"
CBUILD="mips64-unknown-linux-gnu"
CFLAGS="-O3 -pipe -march=native -mtune=native -mabi=64"
CHOST="mips64-unknown-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O3 -pipe -march=native -mtune=native -mabi=64"
DISTDIR="/var/cache/distfiles"
EMERGE_DEFAULT_OPTS="--usepkg --autounmask=n --complete-graph --keep-going --with-bdeps=y"
ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN GOPATH PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR"
FCFLAGS=""
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs binpkg-multi-instance buildpkg buildpkg-live compress-build-logs compressdebug config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-install pid-sandbox preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms splitdebug strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS=""
GENTOO_MIRRORS="https://gentoo.osuosl.org/ https://mirror.leaseweb.com/gentoo/ https://mirror.rackspace.com/gentoo/"
LANG="en_US.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j16"
PKGDIR="/var/cache/binpkgs"
PORTAGE_CONFIGROOT="/"
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=/.git"
PORTAGE_TMPDIR="/var/tmp"
SHELL="/bin/bash"
USE="acl bash-completion big-endian bzip2 caps cli crypt elogind gdbm gentoo-vm graphite headless-awt iconv ipv6 libbsd libglvnd lm-sensors lto mips ncurses nls nptl pam pcre pgo readline seccomp split-usr ssl symlink system-bootstrap system-llvm threads udev unicode verify-sig vhosts vim-syntax xattr zlib" ABI_MIPS="n64" ADA_TARGET="gnat_2020" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="libinput" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LLVM_TARGETS="Mips" LUA_SINGLE_TARGET="lua5-1" LUA_TARGETS="lua5-1" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-4 php8-0" POSTGRES_TARGETS="postgres12 postgres13" PYTHON_SINGLE_TARGET="python3_10" PYTHON_TARGETS="python3_10" RUBY_TARGETS="ruby31" USERLAND="GNU" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq proto steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  ADDR2LINE, AR, ARFLAGS, AS, ASFLAGS, CC, CCLD, CONFIG_SHELL, CPP, CPPFLAGS, CTARGET, CXX, CXXFILT, ELFEDIT, EXTRA_ECONF, F77FLAGS, FC, GCOV, GPROF, INSTALL_MASK, LC_ALL, LD, LEX, LFLAGS, LIBTOOL, LINGUAS, MAKE, MAKEFLAGS, NM, OBJCOPY, OBJDUMP, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, RANLIB, READELF, RUSTFLAGS, SIZE, STRINGS, STRIP, YACC, YFLAGS
Comment 1 matoro archtester 2022-09-18 02:58:33 UTC
Complete build log, unfortunately way too big to attach even compressed:  https://0x0.st/oOOp.c
Comment 2 William Hubbs gentoo-dev 2022-09-19 04:20:35 UTC
Hey,

Can you try this again with the newest version of go-bootstrap?

Thanks,

William
Comment 3 matoro archtester 2022-09-19 17:03:45 UTC
(In reply to William Hubbs from comment #2)
> Hey,
> 
> Can you try this again with the newest version of go-bootstrap?
> 
> Thanks,
> 
> William

Hmm, just tried this again but it's erroring with:

 * ERROR: dev-lang/go-1.19.1::gentoo failed (compile phase):
 *   USE Flag 'abi_mips_o32' not in IUSE for dev-lang/go-1.19.1
 * 
 * Call stack:
 *          ebuild.sh, line  122:  Called src_compile
 *        environment, line 1269:  Called go_arch 'mips64-unknown-linux-gnu'
 *        environment, line  922:  Called use 'abi_mips_o32'
 *   phase-helpers.sh, line  256:  Called die
 * The specific snippet of code:
 *                              die "USE Flag '${u}' not in IUSE for ${CATEGORY}/${PF}"
 * 
 * If you need support, post the output of `emerge --info '=dev-lang/go-1.19.1::gentoo'`,
 * the complete build log and the output of `emerge -pqv '=dev-lang/go-1.19.1::gentoo'`.
 * The complete build log is located at '/var/tmp/portage/dev-lang/go-1.19.1/temp/build.log.gz'.
 * The ebuild environment file is located at '/var/tmp/portage/dev-lang/go-1.19.1/temp/environment'.
 * Working directory: '/var/tmp/portage/dev-lang/go-1.19.1/work/go'
 * S: '/var/tmp/portage/dev-lang/go-1.19.1/work/go'
Comment 4 William Hubbs gentoo-dev 2022-09-19 18:01:16 UTC
IUSE has been updated, so try this again.

Thanks,

William
Comment 5 matoro archtester 2022-11-06 23:54:26 UTC
This was technically fixed in https://github.com/gentoo/gentoo/commit/8db889827661b38cfbe74f335e095a4288a83ff7.  I don't think there's an understanding of why this fixes it, but it does.
Comment 6 Joshua Kinard gentoo-dev 2022-11-08 00:19:50 UTC
(In reply to matoro from comment #5)
> This was technically fixed in
> https://github.com/gentoo/gentoo/commit/
> 8db889827661b38cfbe74f335e095a4288a83ff7.  I don't think there's an
> understanding of why this fixes it, but it does.

I have vague recollections of some weirdness in the MIPS ELF ABI regarding execstacks being discussed on the old linux-mips mailing list years ago, possibly in relation to MIPS not supporting execstacks originally?  I think there was a specific CPU feature that added support for exec stacks (RI/XI), so building for MIPS targets that don't support that feature could be what triggers the error?  Kinda guessing here, as I never did wrap my head about the various quirks that the MIPS ELF ABI uses.

Probably the one linux-mips maintainer that would actually know this answer is Maciej W. Rozycki.  If there is a desire for an answer, and someone can format a specific question for me, I can go and ask.
Comment 7 Andreas K. Hüttel archtester gentoo-dev 2022-11-12 23:51:19 UTC
(In reply to matoro from comment #5)
> This was technically fixed in
> https://github.com/gentoo/gentoo/commit/
> 8db889827661b38cfbe74f335e095a4288a83ff7.  I don't think there's an
> understanding of why this fixes it, but it does.

OK
Comment 8 Larry the Git Cow gentoo-dev 2023-07-30 16:43:39 UTC
The bug has been referenced in the following commit(s):

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

commit 86ac5c16e3149458710b691e1cad81c50be8d661
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2023-07-30 16:26:38 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2023-07-30 16:42:29 +0000

    sys-devel/binutils: add various hardening options to 2.41
    
    Newer Binutils has its several configure arguments we can use:
    * --enable-textrel-check={warning,error}
    * --enable-warn-execstack=yes (*)
    * --enable-warn-rwx-segments=yes (*)
    * --enable-default-execstack=no
    
    We chuck these in now unconditionally (with some stricter changes for USE=hardened,
    as described below) except for those marked with (*) where we whitelist certain
    arches (amd64/arm64/x86 for now) because the autoconf logic is broken, see
    https://sourceware.org/bugzilla/show_bug.cgi?id=29592 (it both needs --enable...=no
    rather than --disable, but it also breaks arches where executable stacks are
    unavoidable.)
    
    In the past (see 47b8db23ff55dd29992198dfbadda53984a4ab2d, e4b8746852919960969944904c59334cecddfe25
    in binutils-patches.git), we patched Binutils to always warn on textrels
    opt-out on a per-build basis with '--no-warn-shared-textrel'). From >= Binutils 2.35,
    upstream has a '--enable-textrel-check=warning' configure option we use.
    
    For USE=hardened, our new changes for TEXTRELs are equivalent to `-z text`
    which make TEXTRELs fatal.
    
    Now, while at it, also make TEXTRELs fatal on musl unconditionally because
    musl doesn't support them and they explode at runtime. Yet another reason
    to get rid of them entirely.
    
    So, in summary: there's several changes here:
    * Make textrels fatal for USE=hardened (we've warned about them for a while
      on all profiles)
    * Make textrels fatal for musl (they don't work there at all, bug #707660)
    * Disable implicit/automatic executable stacks for USE=hardened (plan to do this
      in general later on)
    * Warn on executable stacks in general
    * Warn on RWX segments in general
    
    See also https://www.redhat.com/en/blog/linkers-warnings-about-executable-stacks-and-segments
    for more information.
    
    All of this came to mind again after reading the Qualys writeup for the recent
    OpenSSH bug (bug #910553): https://www.qualys.com/2023/07/19/cve-2023-38408/rce-openssh-forwarded-ssh-agent.txt.
    
    (Note their use of various gadgets involving these.)
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29592
    Bug: https://bugs.gentoo.org/707660
    Bug: https://bugs.gentoo.org/869881
    Bug: https://bugs.gentoo.org/871150
    Bug: https://bugs.gentoo.org/910553
    Signed-off-by: Sam James <sam@gentoo.org>

 sys-devel/binutils/binutils-2.41.ebuild | 43 +++++++++++++++++++++++-------
 sys-devel/binutils/binutils-9999.ebuild | 47 ++++++++++++++++++++++++---------
 2 files changed, 68 insertions(+), 22 deletions(-)