Thank you for letting me know about those tools! I’ve managed to go forward a little bit, but I’m still blocked by random packages getting stuck in compilation, for example github.com/spf13/cobra:
mkdir -p $WORK/b319/
mkdir -p $WORK/b319/_importcfgroot_/github.com/spf13
ln -s $WORK/b063/_pkg_.a $WORK/b319/_importcfgroot_/github.com/spf13/libpflag.a
cd /var/tmp/portage/net-analyzer/sensu-5.21.3/homedir/go/pkg/mod/github.com/spf13/cobra@v0.0.5
/usr/x86_64-pc-linux-gnu/gcc-bin/10.3.0/gccgo -c -O2 -g -m64 -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches -fgo-pkgpath=github.com/spf13/cobra -o $WORK/b319/_go_.o -I $WORK/b319/_importcfgroot_ ./args.go ./bash_completions.go ./cobra.go ./command.go ./command_notwin.go ./powershell_completions.go ./shell_completions.go ./zsh_completions.go
echo ' .section .go.buildid,"e"' >> $WORK/b319/_buildid.s
echo ' .byte 0x58,0x76,0x35,0x4d,0x38,0x44,0x5f,0x69' >> $WORK/b319/_buildid.s
echo ' .byte 0x56,0x39,0x4d,0x47,0x73,0x4f,0x50,0x64' >> $WORK/b319/_buildid.s
echo ' .byte 0x5a,0x59,0x31,0x69,0x2f,0x58,0x76,0x35' >> $WORK/b319/_buildid.s
echo ' .byte 0x4d,0x38,0x44,0x5f,0x69,0x56,0x39,0x4d' >> $WORK/b319/_buildid.s
echo ' .byte 0x47,0x73,0x4f,0x50,0x64,0x5a,0x59,0x31' >> $WORK/b319/_buildid.s
echo ' .byte 0x69' >> $WORK/b319/_buildid.s
echo ' .section .note.GNU-stack,"",@progbits' >> $WORK/b319/_buildid.s
echo ' .section .note.GNU-split-stack,"",@progbits' >> $WORK/b319/_buildid.s
echo '' >> $WORK/b319/_buildid.s
/usr/x86_64-pc-linux-gnu/gcc-bin/10.3.0/gccgo -xassembler-with-cpp -I $WORK/b319/ -c -o $WORK/b319/_buildid.o -D GOOS_linux -D GOARCH_amd64 -D GOPKGPATH=github.x2ecom..z2fspf13..z2fcobra -m64 $WORK/b319/_buildid.s
ar rcD $WORK/b319/_pkg_.a $WORK/b319/_go_.o $WORK/b319/_buildid.o
/usr/libexec/gcc/x86_64-pc-linux-gnu/10.3.0/buildid -w $WORK/b319/_pkg_.a # internal
cp $WORK/b319/_pkg_.a /var/tmp/portage/net-analyzer/sensu-5.21.3/homedir/.cache/go-build/be/be10e89cf7bf0e555356a7e526fef70d76c92d6098c5b41aa3505f3259b5e7c8-d # internal
It has been stuck like that for a couple days now. This is the build code that got me here:
src_unpack() {
set -x
if [ -z ${I_KNOW_WHAT_IM_DOING} ]; then
local I_KNOW_WHAT_IM_DOING=0
fi
GO_TOOL="go"
if use gcc; then
GO_TOOL="go-$(gcc --version | head -n1 | sed 's/^.*Gentoo\ //;s/\..*$//')"
fi
if use systemd; then
die "We don't have systemd unit files yet."
fi
if use backend && \
(use x86 || use arm) && \
! use gcc && \
[ ${I_KNOW_WHAT_IM_DOING} -eq 0 ]; then
die "Backend does not work reliably on 32bit hosts. If you really want this, either re-emerge with I_KNOW_WHAT_IM_DOING=1 or enable USE flag gcc"
fi
tar -xf "${DISTDIR}"/sensu-${PV}.tar.gz
cd ${PN}-go-${PV}
local TODAY=$(date +%Y-%m-%d)
local BUILD_SIGNATURE="-X github.com/sensu/sensu-go/version.Version=${PV} -X github.com/sensu/sensu-go/version.BuildDate=${TODAY}"
if (use x86 || use arm); then
CFLAGS+=" -mstackrealign"
fi
if use agent; then
${GO_TOOL} build -x -v -gccgoflags "${CFLAGS}" -gcflags "${CFLAGS}" -ldflags "${BUILD_SIGNATURE}" -o bin/sensu-agent ./cmd/sensu-agent >/dev/null
cp "${DISTDIR}"/"${PN}"_"${PV}"_agent.yml "${S}"/agent.yml.example
fi
if use backend; then
${GO_TOOL} build -x -v -gccgoflags "${CFLAGS}" -gcflags "${CFLAGS}" -ldflags "${BUILD_SIGNATURE}" -o bin/sensu-backend ./cmd/sensu-backend >/dev/null
cp "${DISTDIR}"/"${PN}"_"${PV}"_backend.yml "${S}"/backend.yml.example
fi
${GO_TOOL} build -x -v -gccgoflags "${CFLAGS}" -gcflags \""${CFLAGS}"\" -ldflags "${BUILD_SIGNATURE}" -o bin/sensuctl ./cmd/sensuctl >/dev/null
set +x
}
Ideally, the ebuild could also pass CFLAGS defined in /etc/portage/make.conf
. I tried a couple ways, but all was in vain. I can’t even remember which ones those are since it’s been at least a week since.
The goal is that each invocation of gcc’s Go compiler would also add something like “-O2 -fomit-frame-pointer -march=native”, or if we detect we’re a 32bit host trying to compile with GCC, we force to compile with -mstackrealign to make sure that 64bit atomics are satisfied.