Repository navigation
Description
Go version
1.25.3
Output of go env in your module/workspace:
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/build/.cache'
GOCACHEPROG=''
GODEBUG='gocachehash=1'
GOENV=''
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/recipe-sysroot -I . -fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/go-build-tmp/go-build3678307125=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/build/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/build'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/recipe-sysroot-native/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTMPDIR='/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/go-build-tmp'
GOTOOLCHAIN='auto'
GOTOOLDIR='/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/recipe-sysroot-native/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.25.3'
GOWORK=''What did you do?
I am compiling buildah with yocto project, under build path ra and build path rb-extend, here is the build command:
x86_64-wrs-linux-go install -v -ldflags="-r /usr/lib64/go/pkg/linux_amd64_dynlink -I /usr/lib64/ld-linux-x86-64.so.2 -extldflags ' -m64 -march=x86-64-v3 -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/recipe-sysroot -Wl,-rpath-link=/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/recipe-sysroot/usr/lib64/go/pkg/linux_amd64_dynlink -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -ffile-prefix-map=/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/sources/buildah-1.41.5=/usr/src/debug/buildah/1.41.5 -ffile-prefix-map=/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/build=/usr/src/debug/buildah/1.41.5 -ffile-prefix-map=/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/recipe-sysroot= -ffile-prefix-map=/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/recipe-sysroot-native= -Wl,-z,relro,-z,now'" -trimpath -mod vendor -buildmode=pie ./cmd/buildah
With above command, the generated buildah is not reproducible,
BUT, after adding "-buildid=", the generated buildah is reproducible.
go buildid make the binary buildah not reproducible.
maybe this is related to: https://github.com/golang/go/blob/master/src/cmd/go/internal/modindex/read.go#L70
the buildid include hash of module root directory, in my case, module root directory is different, so maybe the TODO in comments,
use module path instead of module root directory can resolve this problem.
Here is the log under build path ra:
HASH[moduleIndex]: "go1.25.3"
HASH[moduleIndex]: "modroot /ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/sources/buildah-1.41.5/src/github.com/containers/buildah\n"
HASH[moduleIndex]: "package go1.25.3 go index v2 /ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/sources/buildah-1.41.5/src/github.com/containers/buildah/cmd/buildah\n"
...
Here is the log under build path rb-extend:
HASH[moduleIndex]: "go1.25.3"
HASH[moduleIndex]: "modroot /rb-extend/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/sources/buildah-1.41.5/src/github.com/containers/buildah\n"
HASH[moduleIndex]: "package go1.25.3 go index v2 /rb-extend/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/sources/buildah-1.41.5/src/github.com/containers/buildah/cmd/buildah\n"
...
What did you see happen?
I am compiling buildah with yocto project, under build path ra and build path rb-extend, here is the build command:
x86_64-wrs-linux-go install -v -ldflags="-r /usr/lib64/go/pkg/linux_amd64_dynlink -I /usr/lib64/ld-linux-x86-64.so.2 -extldflags ' -m64 -march=x86-64-v3 -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/recipe-sysroot -Wl,-rpath-link=/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/recipe-sysroot/usr/lib64/go/pkg/linux_amd64_dynlink -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -ffile-prefix-map=/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/sources/buildah-1.41.5=/usr/src/debug/buildah/1.41.5 -ffile-prefix-map=/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/build=/usr/src/debug/buildah/1.41.5 -ffile-prefix-map=/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/recipe-sysroot= -ffile-prefix-map=/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/recipe-sysroot-native= -Wl,-z,relro,-z,now'" -trimpath -mod vendor -buildmode=pie ./cmd/buildah
With above command, the generated buildah is not reproducible, I tried to add "-buildvcs=false ", not work.
BUT, after adding "-buildid=", the generated buildah is reproducible. Seems there is still something make buildid not reproducile.
I checked the compile log and output of "go tool buildid ./buildah", I can see some hash difference, but I cannot get what make this happen? Could you provide some guide, so that I can collect more info for debuging this? Thanks.``
What did you expect to see?
the binary buildah compiled out by go is reproducible
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTodo
Activity
[-]go buildid make the compiled binary not reproducible[/-][+]go BuildID make the compiled binary not reproducible[/+]gabyhelp commentedon Jan 6, 2026
Related Issues
Related Discussions
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
[-]go BuildID make the compiled binary not reproducible[/-][+]cmd/go: non reproducible builds from buildid using modroot directory[/+]JunyangShao commentedon Jan 6, 2026
@golang/command-line
sandy-lcq commentedon Jan 22, 2026
Hi,
After do more investigation, it turns out that the not reproducible is not related to the moduleIndex. But related to the cgo_ldflag in
_go_.o, and this_go_.ois one of file for ar archive file_pkg_.a. This cgo_ldflag contains build path, so cause not reproducible.Take example:
In my env, build runtime/cgo will generate
_pkg_.a, and_go_.oin_pkg_.acontains contents like below:["cgo_ldflag","-ffile-prefix-map=/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/sources/buildah-1.41.5=/usr/src/debug/buildah/1.41.5"],["cgo_ldflag","-ffile-prefix-map=/ra/build/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/build=/usr/src/debug/buildah/1.41.5"]
So when call buildid.FindAndHash, the content hash of
_pkg_.awill be calculated, and the build path make it not reproducible. And all the package deps on it will not reproducible.Besides build path, in
_go_.oand__.PKGDEF, 'build id "actionid/contentid" also different since above build path diffI find that there is function like excludeHostBuildID, try to remove content that influence reproducible before calculate content hash:
https://github.com/golang/go/blob/master/src/cmd/internal/buildid/rewrite.go#L46
So I tried to exclude the buildpath and buildid before calculate content hash, but seems this content hash cannot be changed like this:
It will cause errors like "go: internal cache error: cache verify failed" or "Stale: xxx build id mismatch", I have no idea how the content hash is handle in the whole process, so I am stucked and have no idea how this should be fixed.
Could experts in this please help to review and give your comments, Thanks.
[-]cmd/go: non reproducible builds from buildid using modroot directory[/-][+]cmd/go: non reproducible builds since cgo_ldflag that contains build path[/+]StaticRocket commentedon Jan 27, 2026
Just a heads up, build paths being included in CGO_LDFLAGS was a requirement when using LTO with GCC versions < 12. Tools like Yocto didn't make this conditional based on LTO enablement and just always passed macro prefixes to work around the issue reproducible builds using LTO.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101473
If/when #43505 is addressed we may need to add some form of disclaimer.
go.bbclass: remove macro prefix maps on CGO_LDFLAGS
cherrymui commentedon Apr 15, 2026
Thanks for the report and the investigation! It seems the go command adds
-ffile-prefix-mapto C compilations when-trimpathis used. I think the buildID computation should be more robust with that. One tricky part is that when the build cache is used, it should pick the right object with the right path. If one object containscgo_ldflag -ffile-prefix-map=/ra/build/...and one containscgo_ldflag -ffile-prefix-map=/rb/build/..., they should have different cache keys, so simply ignoring that part from the buildID is probably not going to work. Maybe we need a different mechanism to pass these flags to the linker without affecting the buildID?cc @matloob