You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cmd/go: -buildmode=pie requires external (cgo) linking, but cgo is not enabled #64875
I think that is expected, riscv does not support internal linking with buildmode=pie. Can you point out to the source that says PIE works without cgo on riscv64?
Thanks for the heads-up! There was some logic shifted around in CL 472515 and CL 522239 for #31544 that causes -buildmode=pie to explicitly require CGO_ENABLED=1 with riscv64, this was not a requirement in go 1.21 and earlier. I imagine this also affects linux/s390x the same way.
My understanding is that for riscv64, s390x buildmode=pie do require cgo because of the external linking, so the current behavior is correct, while in 1.21 and earlier we were compiling with cgo anyway, regardless of CGO_ENABLED. But I might be wrong here.
linux/riscv64 is not currently marked as supporting internal linking for PIE binaries. If that is incorrect — that is, if the Go linker actually does support internal linking in this configuration — then internal/platform.InternalLinkPIESupported should be updated (along with any affected tests) to reflect that.
Otherwise, the fact that CGO_ENABLED=0 go build -buildmode=pie hellogo.go previously exited without error is a bug, and the new error here is working as intended.
In triage, are we understanding correctly that, given that -buildmode=pie doesn't work with internal linking on linux/riscv64, that this issue is now basically a feature request for this behavior?
Even though the build didn't fail for Go 1.21, did we really support -buildmode=pie with internal linking? It looks to us like in Go 1.21 the toolchain would just silently build a non-PIE binary, which seems undesirable.
Hi, Alpine Linux maintainer here 👋 We use -buildmode=pie by default for all Go packages in our repository. Since Go 1.22 we are running into a lot of build failures as there seems to be a lot of software which sets CGO_ENABLED=0 in Makefiles and other go build-wrappers, for example fq. Just checking in here to make sure that this is intended. If so, I believe we have to patch all software which sets CGO_ENABLED=0?
Hi, Alpine Linux maintainer here 👋 We use -buildmode=pie by default for all Go packages in our repository. Since Go 1.22 we are running into a lot of build failures as there seems to be a lot of software which sets CGO_ENABLED=0 in Makefiles and other go build-wrappers, for example fq. Just checking in here to make sure that this is intended. If so, I believe we have to patch all software which sets CGO_ENABLED=0?
We are from Arch Linux RISC-V and having the exact same problem.
@nmeum, @Xeonacid: correct. If the Go linker requires an external (C) linker for -buildmode=pie on a given platform, then cgo must also be enabled in order to link PIE binaries on that platform.
Activity
mauri870 commentedon Dec 27, 2023
I think that is expected, riscv does not support internal linking with buildmode=pie. Can you point out to the source that says PIE works without cgo on riscv64?
andreas-schwab commentedon Dec 27, 2023
Why does it work with 1.21?
mauri870 commentedon Dec 28, 2023
Thanks for the heads-up! There was some logic shifted around in CL 472515 and CL 522239 for #31544 that causes
-buildmode=pieto explicitly require CGO_ENABLED=1 with riscv64, this was not a requirement in go 1.21 and earlier. I imagine this also affects linux/s390x the same way.My understanding is that for riscv64, s390x buildmode=pie do require cgo because of the external linking, so the current behavior is correct, while in 1.21 and earlier we were compiling with cgo anyway, regardless of CGO_ENABLED. But I might be wrong here.
cc @bcmills
bcmills commentedon Jan 2, 2024
linux/riscv64is not currently marked as supporting internal linking for PIE binaries. If that is incorrect — that is, if the Go linker actually does support internal linking in this configuration — theninternal/platform.InternalLinkPIESupportedshould be updated (along with any affected tests) to reflect that.Otherwise, the fact that
CGO_ENABLED=0 go build -buildmode=pie hellogo.gopreviously exited without error is a bug, and the new error here is working as intended.(attn @golang/riscv64)
andreas-schwab commentedon Jan 2, 2024
https://build.opensuse.org/package/live_build_log/openSUSE:Factory:RISCV/velero-plugin-for-aws/standard/riscv64
https://build.opensuse.org/package/live_build_log/home:Andreas_Schwab:riscv:go/velero-plugin-for-aws/standard/riscv64
mknyszek commentedon Jan 3, 2024
In triage, are we understanding correctly that, given that
-buildmode=piedoesn't work with internal linking onlinux/riscv64, that this issue is now basically a feature request for this behavior?Even though the build didn't fail for Go 1.21, did we really support
-buildmode=piewith internal linking? It looks to us like in Go 1.21 the toolchain would just silently build a non-PIE binary, which seems undesirable.3 remaining items
nmeum commentedon Mar 2, 2024
Hi, Alpine Linux maintainer here 👋 We use
-buildmode=pieby default for all Go packages in our repository. Since Go 1.22 we are running into a lot of build failures as there seems to be a lot of software which setsCGO_ENABLED=0in Makefiles and othergo build-wrappers, for example fq. Just checking in here to make sure that this is intended. If so, I believe we have to patch all software which setsCGO_ENABLED=0?See: https://gitlab.alpinelinux.org/alpine/aports/-/issues/15809
Xeonacid commentedon Mar 2, 2024
We are from Arch Linux RISC-V and having the exact same problem.
seankhliao commentedon Mar 2, 2024
see #65887 (comment)
bcmills commentedon Mar 5, 2024
@nmeum, @Xeonacid: correct. If the Go linker requires an external (C) linker for
-buildmode=pieon a given platform, then cgo must also be enabled in order to link PIE binaries on that platform.gopherbot commentedon Mar 5, 2024
Change https://go.dev/cl/569296 mentions this issue:
_content/doc: mention cgo requirements for external linking in release notes for Go 1.21 and 1.22_content/doc: mention cgo requirements for external linking in releas…
Set CGO_ENABLED=1 on riscv64
ricardobranco777 commentedon Feb 11, 2025
I can confirm it also affects s390x.
build/docker: disable PIE buildmode under riscv64 due to golang/go#64875
gopherbot commentedon Feb 4, 2026
Change https://go.dev/cl/741860 mentions this issue:
cmd/link: add R_RISCV_TLS_IE support for internal linkgopherbot commentedon Feb 5, 2026
Change https://go.dev/cl/742200 mentions this issue:
cmd/link: enable PIE internal link for riscv64addpatch: openbao 2.5.3-1
addpatch: openbao, ver=2.5.3-1 (#914)