Repository navigation
runtime: fatal error: found bad pointer in Go heap when compiling on amd64 host for arm64 (QEMU) #77572
Copy link
Copy link
Closed as not planned
Closed as not planned
Copy link
Labels
BugReportIssues describing a possible bug in the Go implementation.Issues describing a possible bug in the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Description
Update(2026-02-18): This is a QEMU bug, which is fixed in the new versions of QEMU. QEMU 10.0.6+ is known to work. 7.1.0+ may also work.
For users with an older version of QEMU, there is a workaround on the Go side: set GODEBUG=madvdontneed=0.
This splits off the QEMU emulation issue from #74552 (comment).
When running go install on amd64 host with qemu arm64 emulation it seems to crash.
#27 [linux/arm64 tools 4/4] RUN --mount=type=cache,target=/root/.cache/go-build,id=gobuild --mount=type=cache,target=/go/pkg/mod,id=gopkg go install ./...
#27 0.888 runtime: pointer 0x39d8218b4000 to unallocated span span.base()=0x39d8218c0000 span.limit=0x39d8218c1ec0 span.state=0
#27 0.896 fatal error: found bad pointer in Go heap (incorrect use of unsafe or cgo?)
#27 0.901
#27 0.901 runtime stack:
#27 0.903 runtime.throw({0x71ec51?, 0x49e000?})
#27 0.904 runtime/panic.go:1229 +0x38 fp=0x39d821579ea0 sp=0x39d821579e70 pc=0x93918
#27 0.905 runtime.badPointer(0x554740a080, 0x39d8218b4000, 0x0, 0x0)
#27 0.905 runtime/mbitmap.go:1334 +0x128 fp=0x39d821579ef0 sp=0x39d821579ea0 pc=0x330f8
#27 0.906 runtime.findObject(0x39d8218a4000?, 0x55475485a8?, 0x39d8217bbc20?)
#27 0.906 runtime/mbitmap.go:1386 +0xac fp=0x39d821579f30 sp=0x39d821579ef0 pc=0x9213c
#27 0.906 runtime.wbBufFlush1(0x39d821311808)
#27 0.906 runtime/mwbbuf.go:243 +0x120 fp=0x39d821579fa0 sp=0x39d821579f30 pc=0x56cb0
#27 0.906 runtime.wbBufFlush.func1()
#27 0.906 runtime/mwbbuf.go:181 +0x24 fp=0x39d821579fc0 sp=0x39d821579fa0 pc=0x8e8f4
#27 0.906 runtime.systemstack(0x39d821576000)
#27 0.906 runtime/asm_arm64.s:399 +0x68 fp=0x39d821579fd0 sp=0x39d821579fc0 pc=0x992a8
#27 0.907
and
#24 1.163 runtime: marked free object in span 0x55474772a8, elemsize=128 freeindex=1 (bad use of unsafe.Pointer or having race conditions? try -d=checkptr or -race)
#24 1.172 0x7b979736000 alloc unmarked
#24 1.177 0x7b979736080 free unmarked
#24 1.178 0x7b979736100 free unmarked
#24 1.178 0x7b979736180 free unmarked
#24 1.178 0x7b979736200 free unmarked
...
#24 1.181 fatal error: found pointer to free object
#24 1.197
#24 1.197 runtime stack:
#24 1.198 runtime.throw({0x703f56?, 0x0?})
#24 1.199 runtime/panic.go:1229 +0x38 fp=0x7b97932ba00 sp=0x7b97932b9d0 pc=0x93918
#24 1.200 runtime.(*mspan).reportZombies(0x55474772a8)
#24 1.200 runtime/mgcsweep.go:893 +0x314 fp=0x7b97932ba80 sp=0x7b97932ba00 pc=0x4a834
Full log can be found at https://gist.github.com/egonelbre/15e79abdd3d298028791d33f2392d865
The relevant information about qemu version:
$ docker buildx create --name multiplatform --driver docker-container --bootstrap
$ docker exec buildx_buildkit_multiplatform0 buildkit-qemu-aarch64 --version
qemu-aarch64 version 10.0.4 (v10.0.4)
Copyright (c) 2003-2025 Fabrice Bellard and the QEMU Project developers
$ docker exec buildx_buildkit_multiplatform0 uname -a
Linux 6f5951803e5a 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 Linux
One common denominator seems to be Ubuntu 22.04 host that also @wadey mentioned.
A related issue on arm64 #76985.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugReportIssues describing a possible bug in the Go implementation.Issues describing a possible bug in the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Activity
egonelbre commentedon Feb 12, 2026
Looks like a latest Ubuntu 22.04 does not trigger the issue, so there must be some additional important detail:
First attempt to setup on a Ubuntu 22.04 VM
Some additional details, in case they are relevant:
Working system kernel:
Non-working system kernel:
lscpu working system
lscpu non-working system
prattmic commentedon Feb 12, 2026
Which version of QEMU is used on the working vs non-working systems? (Edit: Ah, you included the version on the non-working system already, and the setup script specifies the same version, so I suppose it's the same in both cases.)
You don't mention flakes, so I assume this is quite reproducible? Most/all builds fail?
[-]cmd/go: fatal error: found bad pointer in Go heap when compiling on amd64 host for arm64[/-][+]runtime: fatal error: found bad pointer in Go heap when compiling on amd64 host for arm64 (QEMU)[/+]prattmic commentedon Feb 12, 2026
cc @golang/runtime @golang/compiler
prattmic commentedon Feb 12, 2026
If this works OK with 1.25 and fails reliably with 1.26, I think the most helpful thing you can do at the moment would be to bisect the Go between 1.25 and 1.26 to try to pinpoint which change caused the failure.
My immediate suspicion is that this is a limitation/bug in QEMU's arm64 translation that some change in Go has started triggering.
wadey commentedon Feb 12, 2026
Bad host 1 (this is a
c6a.largeAWS instance in us-east-1):lscpu
Running this test causes a different crash each time within moments.
wadey commentedon Feb 12, 2026
Bad host 2 (this is a
c5.4xlargeAWS instance in us-east-1):lscpu
Same crashes as bad host 1
wadey commentedon Feb 12, 2026
Good host 1 (this is a
m6i.largeAWS instance in us-east-1):lscpu
No crashes with the test.
wadey commentedon Feb 12, 2026
Bisecting is going to be difficult because I think I would have to cross compile Go for each bisect version for arm64? Unless perhaps we can bisect using the
tipdocker images, likegolang:tip-20260124etc (and I'm not sure docker hub keeps that many of these historically)egonelbre commentedon Feb 12, 2026
@wadey I think you can use the same host to cross-compile you a binary and then hoist the binary into a docker image with mounting a directory.
cherrymui commentedon Feb 12, 2026
QEMU user space emulation have been known to be buggy from time to time. If I recall correctly, one problem it had was it can give addresses that are actually amd64-like, which would never occur with real arm64 machine/kernel.
wadey commentedon Feb 12, 2026
A quick bisect with available
tipversions.On "Bad host 1" from above,
golang:tip-20251026passes andgolang:tip-20251102fails.54e3adc...388c41c
wadey commentedon Feb 12, 2026
I have a guess that it might be this bug, that was fixed later in 2022 (lines up with qemu in 22.04 being the issue): https://gitlab.com/qemu-project/qemu/-/issues/326
And this commit is in the bisect range: 2793728
It looks like this fix is in qemu
v7.1.0and later, and my bad hosts havev6.213 remaining items
nikpivkin commentedon Feb 18, 2026
I know that to solve the problem, you need to upgrade the QEMU version, but I tried to use the suggested workaround.
cherrymui commentedon Feb 18, 2026
Thanks for the investigation. As @egonelbre mentioned, it is a QEMU bug that has been fixed in the new versions of QEMU, and there is a simple workaround on the Go side (GODEBUG=madvdontneed=0), we can close this. Thanks.
I edited the top post to mention the version and the workarund.
prattmic commentedon Feb 18, 2026
For posterity since it isn't directly linked from the issue, the merged fix commit is https://gitlab.com/qemu-project/qemu/-/commit/892a4f6a750abceeda4c1ee8324f58f82fd6bd89, which is indeed in
v7.1.0.Note that this fix does not fix cases where the host page size is larger than the guest page size. In that case,
MADV_DONTNEEDis still a no-op. I could imagine this being a problem for arm64 hosts with amd64 guests, as arm64 can have a larger page size.gopherbot commentedon Feb 18, 2026
Change https://go.dev/cl/746600 mentions this issue:
MinimumRequirements: add QEMU user space emulatorprattmic commentedon Feb 18, 2026
I have a few meta questions for folks affected by this issue:
This issue was reported shortly after the Go 1.26.0 release. Though this ended up being a QEMU bug, we'd of course prefer to find subtle issues like this before the final release. We release Go release candidates for around two months prior to final releases, which we encourage users to test and find issues not covered by our own testing.
For folks that encountered this issue, I'm curious:
To be clear, this isn't about QEMU specifically, I've just been thinking about ways we improve our prerelease process to find more bugs before the final release and I figure that a group of folks hit by an issue at release is a good audience for questions. :)
seankhliao commentedon Feb 18, 2026
Perhaps if you don't have the bandwidth to update your base os packages like docker / qemu, you also don't have the bandwidth to test pre releases...
egonelbre commentedon Feb 18, 2026
Yes, I usually start using rc versions locally whenever they come out. I don't test them in CI with full testsuite every release, it depends on how much time I have available. Currently the QEMU problem was in a different part of the system that was used to build some images i.e. a part of the system I didn't consider.
I feel like rc testing is easy enough.
As for updating base OS packages. QEMU 6.20 is the current version in Ubuntu 22.04 LTS, which is supported until 2027. So just an
apt updateis not sufficient.MinimumRequirements: add QEMU user space emulator
ci: work around QEMU Go compiler panic (golang/go#77572)
darccio commentedon Oct 7, 2026
Re: the "QEMU 10.0.6+ is known to work" note — qemu-aarch64 10.2.3 (shipped today by tonistiigi/binfmt:latest, the standard GitHub Actions/Buildx arm64 registration) still corrupts for us - at Datadog - under GOMEMLIMIT-driven scavenger pressure, with the exact signatures from this issue ("marked free object in span", "found bad pointer in Go heap", plus acquireSudog / concurrent-map-writes variants). Minimal 24-line reproducer, 20-run rates (default 15/20 crash; GODEBUG=madvdontneed=0 20/20 clean), and a QEMU-side report: https://gitlab.com/qemu-project/qemu/-/work_items/4654. The workaround from this issue remains effective; we now scope it automatically to emulated arm64 runs in our CI.