Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 924632 - dev-lang/go-1.22.0: Various Go packages fail to build with "-buildmode=pie requires external (cgo) linking, but cgo is not enabled
Summary: dev-lang/go-1.22.0: Various Go packages fail to build with "-buildmode=pie re...
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: William Hubbs
URL:
Whiteboard:
Keywords: PATCH
: 924629 924630 939190 939691 941115 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-02-15 11:06 UTC by Agostino Sarubbo
Modified: 2025-03-13 12:14 UTC (History)
10 users (show)

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


Attachments
build.log (build.log,41.35 KB, text/plain)
2024-02-15 11:06 UTC, Agostino Sarubbo
Details
patch with CGO_ENABLED=1 (containerd-1.7.22.patch,486 bytes, patch)
2024-10-21 19:50 UTC, powerN00b
Details | Diff
patch with CGO_ENABLED=1 (go-md2man-2.0.3.patch,343 bytes, patch)
2024-10-21 19:50 UTC, powerN00b
Details | Diff
ebuild patch (containerd-1.7.23.ebuild.diff,433 bytes, patch)
2024-12-02 06:54 UTC, powerN00b
Details | Diff
ebuild patch (go-md2man-2.0.3.ebuild.diff,464 bytes, patch)
2024-12-02 06:55 UTC, powerN00b
Details | Diff
Prometheus-2.43.0-r2 build log (prometheus-2.43.0-r2 build.log,3.23 KB, text/x-log)
2024-12-02 18:47 UTC, Barnabás Virágh
Details
patch with CGO_ENABLED=1 (syncthing-1.27.9.patch,256 bytes, patch)
2025-02-14 18:03 UTC, Richard H.
Details | Diff
Patch for containerd-2.0.2 (file_924632.txt,504 bytes, patch)
2025-02-27 15:20 UTC, misterxx
Details | Diff
Patch for go-md2man-2.0.6 to enable cgi (enable-cgo.patch,152 bytes, patch)
2025-03-13 12:14 UTC, misterxx
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Agostino Sarubbo gentoo-dev 2024-02-15 11:06:51 UTC
https://blogs.gentoo.org/ago/2020/07/04/gentoo-tinderbox/

Issue: dev-go/go-md2man-2.0.3 fails to compile.
Discovered on: x86 (internal ref: tinderbox_x86)
System: GCC-14-SYSTEM (https://wiki.gentoo.org/wiki/Project:Tinderbox/Common_Issues_Helper#GCC-14)

Info about the issue:
https://wiki.gentoo.org/wiki/Project:Tinderbox/Common_Issues_Helper#CF0014
Comment 1 Agostino Sarubbo gentoo-dev 2024-02-15 11:06:52 UTC
Created attachment 885018 [details]
build.log

build log and emerge --info
Comment 2 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-02-16 00:50:54 UTC
*** Bug 924630 has been marked as a duplicate of this bug. ***
Comment 3 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-02-16 00:50:58 UTC
*** Bug 924629 has been marked as a duplicate of this bug. ***
Comment 4 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-02-16 00:51:34 UTC
I can hit this with syncthing-1.27.2 with dev-lang/go-1.22.0, but downgrading Go to dev-lang/go-1.21.7, it builds fine.
Comment 5 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-02-16 00:52:05 UTC
(In reply to Sam James from comment #4)
> I can hit this with syncthing-1.27.2 with dev-lang/go-1.22.0, but
> downgrading Go to dev-lang/go-1.21.7, it builds fine.

At first, this looked like https://github.com/golang/go/issues/47949, but it doesn't make sense by itself given it's a regression and that linked bug isn't.
Comment 6 lukasstraub2 2024-04-20 10:44:44 UTC
Are you sure this is only affects x86? This comment on github suggests that it is an issue with CGO_ENABLED=0 and -buildmode=pie being incompatible and go-1.22 intentionally breaks the build in this case:
github.com/golang/go/issues/64875#issuecomment-1974786520
Comment 7 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-04-21 02:03:04 UTC
(In reply to lukasstraub2 from comment #6)
> Are you sure this is only affects x86? This comment on github suggests that
> it is an issue with CGO_ENABLED=0 and -buildmode=pie being incompatible and
> go-1.22 intentionally breaks the build in this case:
> github.com/golang/go/issues/64875#issuecomment-1974786520

Yeah, I've seen it on amd64 too.
Comment 8 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-04-21 02:03:36 UTC
I hope to look at this over the weekend even though it's.. gross.
Comment 9 Marius Dinu 2024-07-24 16:44:26 UTC
I ran into this problem on arm-musl (32bit) with dev-go/go-md2man-2.0.3 and dev-lang/go-1.22.4
Comment 10 misterxx 2024-09-27 13:06:09 UTC
Even with the latest version dev-lang/go-1.23.1 I get exactly the same error message when I compile dev-go/md2man-2.0.3. Already waiting April 2024 for the solution ;-(
Comment 11 misterxx 2024-10-08 08:39:28 UTC
(In reply to Sam James from comment #8)
> I hope to look at this over the weekend even though it's.. gross.

Hello Sam James, do you have any news for us in this regard? Thanks in advance.
Comment 12 powerN00b 2024-10-21 19:50:27 UTC
Created attachment 906575 [details, diff]
patch with CGO_ENABLED=1
Comment 13 powerN00b 2024-10-21 19:50:55 UTC
Created attachment 906576 [details, diff]
patch with CGO_ENABLED=1
Comment 14 powerN00b 2024-10-21 19:51:49 UTC
>it is an issue with CGO_ENABLED=0 and -buildmode=pie being incompatible and go-1.22 intentionally breaks the build in this case
>do you have any news for us in this regard?
I suggest you to patch Makefiles with CGO_ENABLED=1 and see if it builds this way. I got go-md2man and containerd building on i686.
Comment 15 Marius Dinu 2024-10-22 07:29:01 UTC
md2man was built, but containerd still fails with the same error.


>>> Unpacking containerd-1.7.21.tar.gz to /var/tmp/portage/app-containers/containerd-1.7.21/work
>>> Source unpacked in /var/tmp/portage/app-containers/containerd-1.7.21/work
>>> Preparing source in /var/tmp/portage/app-containers/containerd-1.7.21/work/containerd-1.7.21 ...
 * =============================================================================================================================================================================================================================================
 * Applying user patches from /etc/portage/patches ...
 * Applying go.patch ...
 [ ok ]
 * User patches applied.
 * =============================================================================================================================================================================================================================================
>>> Source prepared.
>>> Configuring source in /var/tmp/portage/app-containers/containerd-1.7.21/work/containerd-1.7.21 ...
>>> Source configured.
>>> Compiling source in /var/tmp/portage/app-containers/containerd-1.7.21/work/containerd-1.7.21 ...
make -j4 'BUILDTAGS=no_cri no_devmapper seccomp' LDFLAGS= REVISION=472731909fa34bd7bc9c087e4c27943f9835f111 VERSION=v1.7.21 man -j1 
+ bin/gen-manpages
go build  -gcflags=-trimpath=/var/tmp/portage/app-containers/containerd-1.7.21/homedir/go/src -buildmode=pie  -o bin/gen-manpages -ldflags '-X github.com/containerd/containerd/version.Version=v1.7.21 -X github.com/containerd/containerd/version.Revision=472731909fa34bd7bc9c087e4c27943f9835f111 -X github.com/containerd/containerd/version.Package=github.com/containerd/containerd  ' -tags "no_cri no_devmapper seccomp "  ./cmd/gen-manpages
WORK=/var/tmp/portage/app-containers/containerd-1.7.21/temp/go-build1313120252
-buildmode=pie requires external (cgo) linking, but cgo is not enabled
Comment 16 misterxx 2024-10-22 14:43:55 UTC
The patching of containerd-1.7.22 worked for me as follows:

Code:
--- /Makefile   2024-10-21 06:58:29.817958556 +0200
+++ Makefile   2024-10-21 07:03:39.072092347 +0200
@@ -33,7 +33,7 @@
 VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.m' --always)
 REVISION=$(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi)
 PACKAGE=github.com/containerd/containerd
-SHIM_CGO_ENABLED ?= 0
+SHIM_CGO_ENABLED ?= 1
 
 ifneq "$(strip $(shell command -v $(GO) 2>/dev/null))" ""
    GOOS ?= $(shell $(GO) env GOOS)
Comment 17 Marius Dinu 2024-10-23 19:28:44 UTC
app-containers/containerd-1.7.22 doesn't work either. I checked that the patch was applied correctly. My system is armv7.

Are there any USE flags that might affect this?
Comment 18 misterxx 2024-10-25 08:30:46 UTC
I use also armv7 (odroid xu4). The patch worked for me as well.

I did not have to use any special USE tags for this compilation.

Used GO version: dev-lang/go-1.23.2
Comment 19 Barnabás Virágh 2024-11-12 19:42:55 UTC
The error for:

app-metrics/prometheus-2.43.0-r2

CHOST=armv7a-unknown-linux-gnueabihf
dev-lang/go-1.22.6
profile=default/linux/arm/23.0/split-usr/armv7a_hf/hardened
Comment 20 Zac Medico gentoo-dev 2024-11-13 21:39:04 UTC
(In reply to misterxx from comment #16)
> The patching of containerd-1.7.22 worked for me as follows:
> 
> Code:
> --- /Makefile   2024-10-21 06:58:29.817958556 +0200
> +++ Makefile   2024-10-21 07:03:39.072092347 +0200
> @@ -33,7 +33,7 @@
>  VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.m' --always)
>  REVISION=$(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff
> --quiet --exit-code; then echo .m; fi)
>  PACKAGE=github.com/containerd/containerd
> -SHIM_CGO_ENABLED ?= 0
> +SHIM_CGO_ENABLED ?= 1
>  
>  ifneq "$(strip $(shell command -v $(GO) 2>/dev/null))" ""
>     GOOS ?= $(shell $(GO) env GOOS)

We might want to somehow make this patch conditional just for those architectures that require CGO_ENABLED, so that we can have static binaries for other architectures that don't require CGO_ENABLED.
Comment 21 powerN00b 2024-12-02 06:54:51 UTC
Created attachment 913020 [details, diff]
ebuild patch

conditional CGO_ENABLED=1 for x86 and arm $ARCH
Comment 22 powerN00b 2024-12-02 06:55:31 UTC
Created attachment 913021 [details, diff]
ebuild patch

conditional CGO_ENABLED=1 for x86 and arm $ARCH
Comment 23 powerN00b 2024-12-02 07:00:28 UTC
(In reply to Barnabás Virágh from comment #19)
> The error for:
> 
> app-metrics/prometheus-2.43.0-r2
> 
> CHOST=armv7a-unknown-linux-gnueabihf
> dev-lang/go-1.22.6
> profile=default/linux/arm/23.0/split-usr/armv7a_hf/hardened

I don't see any CGO-related variables in prometheus Makefile, probably because it uses npm. 
Can you post a full build log?
Comment 24 Barnabás Virágh 2024-12-02 18:47:41 UTC
Created attachment 913101 [details]
Prometheus-2.43.0-r2 build log
Comment 25 John Helmert III archtester Gentoo Infrastructure gentoo-dev Security 2025-01-20 23:40:52 UTC
*** Bug 939691 has been marked as a duplicate of this bug. ***
Comment 26 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2025-01-20 23:50:54 UTC
*** Bug 941115 has been marked as a duplicate of this bug. ***
Comment 27 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2025-01-20 23:51:03 UTC
*** Bug 939190 has been marked as a duplicate of this bug. ***
Comment 28 Richard H. 2025-02-08 15:33:11 UTC
Any way to fix syncthing too? I am a bit stuck on an ancient version because of this. Would very much like to upgrade but I can't find anything to patch like in the other ebuilds.
Comment 29 powerN00b 2025-02-13 13:52:43 UTC
(In reply to Richard H. from comment #28)
> Any way to fix syncthing too? I am a bit stuck on an ancient version because
> of this. Would very much like to upgrade but I can't find anything to patch
> like in the other ebuilds.

grep -R CGO on /var/tmp/portage/net-p2p/syncthing-1.27.12/work/syncthing
Comment 30 Richard H. 2025-02-14 18:03:23 UTC
Created attachment 918936 [details, diff]
patch with CGO_ENABLED=1
Comment 31 powerN00b 2025-02-19 01:03:07 UTC
> We might want to somehow make this patch conditional just for those
> architectures that require CGO_ENABLED, so that we can have static binaries
> for other architectures that don't require CGO_ENABLED.
src_prepare() {
	#See bug 924632
	for arch32 in x86 arm; do
		if [[ $ARCH = $arch32 ]]; then
			ewarn "Force CGO_ENABLED=1 for $ARCH, see bug #924632"
			sed -i 's/SHIM_CGO_ENABLED ?= 0/SHIM_CGO_ENABLED ?= 1/' \
			Makefile || ewarn "Can not force CGO_ENABLED=1"
		fi
	done
	unset arch32
}
Comment 32 misterxx 2025-02-27 15:18:23 UTC
Patch for containerd-2.0.2:



--- /Makefile   2025-02-27 09:55:29.817958556 +0200
+++ Makefile   2025-02-27 09:55:39.072092347 +0200
@@ -33,7 +33,7 @@
 VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.m' --always)
 REVISION=$(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi)
 PACKAGE=github.com/containerd/containerd/v2
-SHIM_CGO_ENABLED ?= 0
+SHIM_CGO_ENABLED ?= 1
 
 ifneq "$(strip $(shell command -v $(GO) 2>/dev/null))" ""
    GOOS ?= $(shell $(GO) env GOOS)
Comment 33 misterxx 2025-02-27 15:20:52 UTC
Created attachment 920020 [details, diff]
Patch for containerd-2.0.2
Comment 34 Marius Dinu 2025-02-27 20:19:39 UTC
Tested:

md2man works with patch
containerd works with patch
docker needs patch, but works with CGO_ENABLED=1 in /etc/portage/make.conf

Thanks!
Comment 35 misterxx 2025-03-13 12:14:13 UTC
Created attachment 920700 [details, diff]
Patch for go-md2man-2.0.6 to enable cgi

Resolves the emerge problem when cgo need to be enabled.