Skip to contentSkip to conversation

go.bbclass: set buildid to empty string to improve reproducibility

PATCH Superseded [email protected] 2 participants 6 messages Jan 8 – Jan 14 1 message not in the archive

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 go.bbclass: set buildid to empty string to improve reproducibility

From: Changqing Li <[email protected]>

Go packages and binaries are stamped with build IDs that record both the action ID, which is a hash of the inputs to the action that produced the packages or binary, and the content ID, which is a hash of the action output, namely the archive or binary itself, Refer [1].

And action ID include hash of modroot, which will include build path, so this make go package not reproducible.
Refer [2], keying off module path instead of module root directory is a TODO.

[snip of log]
HASH[moduleIndex]: "go1.25.3"
HASH[moduleIndex]: "modroot /build-a/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/recipe-sysroot-native/usr/lib/go/src/cmd\n" HASH[moduleIndex]: "package go1.25.3 go index v2 /build-a/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/recipe-sysroot-native/usr/lib/go/src/cmd/buildid\n" HASH[moduleIndex]: "file buildid.go 2025-10-13 16:08:43 +0000 UTC 1704\n"
HASH[moduleIndex]: "file doc.go 2025-10-13 16:08:43 +0000 UTC 558\n"
HASH[moduleIndex]: 007b9fe2edd5b3232f5c98ae6c46e80a435141cb627ba5418c5314c0cbf4df7b

Report this issue to upstream, refer [3]
Workaround the reproducible by setting buildid to empty, refer [4]

Refer:
[1] https://github.com/golang/go/blob/master/src/cmd/go/internal/work/buildid.go#L26
[2] https://github.com/golang/go/blob/master/src/cmd/go/internal/modindex/read.go#L70
[1] https://github.com/golang/go/issues/77086
[2] https://github.com/golang/go/issues/34186

---
 meta/classes-recipe/go.bbclass | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
meta/classes-recipe/go.bbclass +2 -1
index b540471ba2..1c43b36fc0 100644
@@ -51,11 +51,12 @@ GO_RPATH:class-native = "${@'-r ${STAGING_LIBDIR_NATIVE}/go/pkg/${TARGET_GOTUPLE
 GO_RPATH_LINK:class-native = "${@'-Wl,-rpath-link=${STAGING_LIBDIR_NATIVE}/go/pkg/${TARGET_GOTUPLE}_dynlink' if d.getVar('GO_DYNLINK') else ''}"
 GO_EXTLDFLAGS ?= "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${GO_RPATH_LINK} ${LDFLAGS}"
 GO_LINKMODE ?= ""
+GO_BUILDID ?= "-buildid="
 GO_EXTRA_LDFLAGS ?= ""
 GO_LINUXLOADER ?= "-I ${@get_linuxloader(d)}"
 # Use system loader. If uninative is used, the uninative loader will be patched automatically
 GO_LINUXLOADER:class-native = ""
-GO_LDFLAGS ?= '-ldflags="${GO_RPATH} ${GO_LINKMODE} ${GO_LINUXLOADER} ${GO_EXTRA_LDFLAGS} -extldflags '${GO_EXTLDFLAGS}'"'
+GO_LDFLAGS ?= '-ldflags="${GO_RPATH} ${GO_LINKMODE} ${GO_LINUXLOADER} ${GO_EXTRA_LDFLAGS} ${GO_BUILDID} -extldflags '${GO_EXTLDFLAGS}'"'
 export GOBUILDFLAGS ?= "-v ${GO_LDFLAGS} -trimpath"
 export GOPATH_OMIT_IN_ACTIONID ?= "1"
 export GOPTESTBUILDFLAGS ?= "${GOBUILDFLAGS} -c"
Signature · 1 line
2.34.1
#1 lore raw

There's go-helloworld in oe-core, which is reproducible as it is. How can the non-reproducibility that this patch is fixing be observed? Can we improve our tests for it?

Alex

Quoted 64 lines · Changqing Li via lists.openembedded.org

From: Changqing Li <[email protected]>

Go packages and binaries are stamped with build IDs that record both the action ID, which is a hash of the inputs to the action that produced the packages or binary, and the content ID, which is a hash of the action output, namely the archive or binary itself, Refer [1].

And action ID include hash of modroot, which will include build path, so this make go package not reproducible.
Refer [2], keying off module path instead of module root directory is a TODO.

[snip of log]
HASH[moduleIndex]: "go1.25.3"
HASH[moduleIndex]: "modroot /build-a/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/recipe-sysroot-native/usr/lib/go/src/cmd\n" HASH[moduleIndex]: "package go1.25.3 go index v2 /build-a/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/recipe-sysroot-native/usr/lib/go/src/cmd/buildid\n" HASH[moduleIndex]: "file buildid.go 2025-10-13 16:08:43 +0000 UTC 1704\n"
HASH[moduleIndex]: "file doc.go 2025-10-13 16:08:43 +0000 UTC 558\n"
HASH[moduleIndex]: 007b9fe2edd5b3232f5c98ae6c46e80a435141cb627ba5418c5314c0cbf4df7b

Report this issue to upstream, refer [3]
Workaround the reproducible by setting buildid to empty, refer [4]

Refer:
[1] https://github.com/golang/go/blob/master/src/cmd/go/internal/work/buildid.go#L26
[2] https://github.com/golang/go/blob/master/src/cmd/go/internal/modindex/read.go#L70
[1] https://github.com/golang/go/issues/77086
[2] https://github.com/golang/go/issues/34186

---
 meta/classes-recipe/go.bbclass | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
meta/classes-recipe/go.bbclass +2 -2
index b540471ba2..1c43b36fc0 100644
@@ -51,11 +51,12 @@ GO_RPATH:class-native = "${@'-r ${STAGING_LIBDIR_NATIVE}/go/pkg/${TARGET_GOTUPLE
 GO_RPATH_LINK:class-native = "${@'-Wl,-rpath-link=${STAGING_LIBDIR_NATIVE}/go/pkg/${TARGET_GOTUPLE}_dynlink' if d.getVar('GO_DYNLINK') else ''}"
 GO_EXTLDFLAGS ?= "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${GO_RPATH_LINK} ${LDFLAGS}"
 GO_LINKMODE ?= ""
+GO_BUILDID ?= "-buildid="
 GO_EXTRA_LDFLAGS ?= ""
 GO_LINUXLOADER ?= "-I ${@get_linuxloader(d)}"
 # Use system loader. If uninative is used, the uninative loader will be patched automatically
 GO_LINUXLOADER:class-native = ""
-GO_LDFLAGS ?= '-ldflags="${GO_RPATH} ${GO_LINKMODE} ${GO_LINUXLOADER} ${GO_EXTRA_LDFLAGS} -extldflags '${GO_EXTLDFLAGS}'"'
+GO_LDFLAGS ?= '-ldflags="${GO_RPATH} ${GO_LINKMODE} ${GO_LINUXLOADER} ${GO_EXTRA_LDFLAGS} ${GO_BUILDID} -extldflags '${GO_EXTLDFLAGS}'"'
 export GOBUILDFLAGS ?= "-v ${GO_LDFLAGS} -trimpath"
 export GOPATH_OMIT_IN_ACTIONID ?= "1"
 export GOPTESTBUILDFLAGS ?= "${GOBUILDFLAGS} -c"
--

2.34.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#229038): https://lists.openembedded.org/g/openembedded-core/message/229038
Mute This Topic: https://lists.openembedded.org/mt/117148599/1686489
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#2 lore raw
Quoted 6 lines · Alexander Kanavin

CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.

There's go-helloworld in oe-core, which is reproducible as it is. How can the non-reproducibility that this patch is fixing be observed? Can we improve our tests for it?

This moduleindex info only be used when GO111MODULE=on,  and thego-helloworld is compiled with

GO111MODULE=off, so it is reproducible as it is. To improve test, we properly need to enable GO111MODULE

This issue can be easily reproduced by "bitbake buildah"  with different path on a host. There are also other

recipes under meta-virtualization have this issue. I have also send a series of patches to meta-virtualization.

Bruce prefer not set to empty,  but to a value like git hash that values for us.

SRCREV seems like a proper value to use, but maybe not all the recipes set this value SRCREV,  is it possible that

a recipe use a tarball and SRC_URI[sha256sum]?

and some recipes like  nerdctl,  it set multiple SRCREV,  set a value in go.bbclass will make the logic here complicated.

SRCREV_nerdcli = "497c7cf74d09bf1ddf2678382360ca61e6faebac"

SRCREV_sys = "74cfc93a99be6ca6f193856132e6799065b071af"
...

//Sandy

Quoted 69 lines

Alex

Quoted 64 lines · Changqing Li via lists.openembedded.org

From: Changqing Li<[email protected]>

Go packages and binaries are stamped with build IDs that record both the action ID, which is a hash of the inputs to the action that produced the packages or binary, and the content ID, which is a hash of the action output, namely the archive or binary itself, Refer [1].

And action ID include hash of modroot, which will include build path, so this make go package not reproducible.
Refer [2], keying off module path instead of module root directory is a TODO.

[snip of log]
HASH[moduleIndex]: "go1.25.3"
HASH[moduleIndex]: "modroot /build-a/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/recipe-sysroot-native/usr/lib/go/src/cmd\n" HASH[moduleIndex]: "package go1.25.3 go index v2 /build-a/tmp/work/x86-64-v3-wrs-linux/buildah/1.41.5/recipe-sysroot-native/usr/lib/go/src/cmd/buildid\n" HASH[moduleIndex]: "file buildid.go 2025-10-13 16:08:43 +0000 UTC 1704\n"
HASH[moduleIndex]: "file doc.go 2025-10-13 16:08:43 +0000 UTC 558\n"
HASH[moduleIndex]: 007b9fe2edd5b3232f5c98ae6c46e80a435141cb627ba5418c5314c0cbf4df7b

Report this issue to upstream, refer [3]
Workaround the reproducible by setting buildid to empty, refer [4]

Refer:
[1]https://github.com/golang/go/blob/master/src/cmd/go/internal/work/buildid.go#L26 [2]https://github.com/golang/go/blob/master/src/cmd/go/internal/modindex/read.go#L70 [1]https://github.com/golang/go/issues/77086 [2]https://github.com/golang/go/issues/34186

---
  meta/classes-recipe/go.bbclass | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
meta/classes-recipe/go.bbclass +0 -0
index b540471ba2..1c43b36fc0 100644
@@ -51,11 +51,12 @@ GO_RPATH:class-native = "${@'-r ${STAGING_LIBDIR_NATIVE}/go/pkg/${TARGET_GOTUPLE
  GO_RPATH_LINK:class-native ="${@'-Wl,-rpath-link=${STAGING_LIBDIR_NATIVE}/go/pkg/${TARGET_GOTUPLE}_dynlink' 

if d.getVar('GO_DYNLINK') else ''}"
GO_EXTLDFLAGS ?= "${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} ${GO_RPATH_LINK} ${LDFLAGS}" GO_LINKMODE ?= ""

meta/classes-recipe/go.bbclass +2 -2
+GO_BUILDID ?= "-buildid="
  GO_EXTRA_LDFLAGS ?= ""
  GO_LINUXLOADER ?= "-I ${@get_linuxloader(d)}"
  # Use system loader. If uninative is used, the uninative loader will be patched automatically
  GO_LINUXLOADER:class-native = ""
-GO_LDFLAGS ?= '-ldflags="${GO_RPATH} ${GO_LINKMODE} ${GO_LINUXLOADER} ${GO_EXTRA_LDFLAGS} -extldflags '${GO_EXTLDFLAGS}'"'
+GO_LDFLAGS ?= '-ldflags="${GO_RPATH} ${GO_LINKMODE} ${GO_LINUXLOADER} ${GO_EXTRA_LDFLAGS} ${GO_BUILDID} -extldflags '${GO_EXTLDFLAGS}'"'
  export GOBUILDFLAGS ?= "-v ${GO_LDFLAGS} -trimpath"
  export GOPATH_OMIT_IN_ACTIONID ?= "1"
  export GOPTESTBUILDFLAGS ?= "${GOBUILDFLAGS} -c"
--

2.34.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#229038):https://lists.openembedded.org/g/openembedded-core/message/229038 Mute This Topic:https://lists.openembedded.org/mt/117148599/1686489
Group Owner:[email protected] Unsubscribe:https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#3 lore raw
Quoted 7 lines · Changqing Li

There's go-helloworld in oe-core, which is reproducible as it is. How can the non-reproducibility that this patch is fixing be observed? Can we improve our tests for it?

This moduleindex info only be used when GO111MODULE=on, and the go-helloworld is compiled with

GO111MODULE=off, so it is reproducible as it is. To improve test, we properly need to enable GO111MODULE

Can you do this please, and add the change to the patchset?

Alex

#4 lore raw
Quoted 4 lines · Alexander Kanavin

CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.

On Mon, 12 Jan 2026 at 08:40, Changqing Li <[email protected]> wrote:

Quoted 8 lines
Quoted 7 lines

There's go-helloworld in oe-core, which is reproducible as it is. How can the non-reproducibility that this patch is fixing be observed? Can we improve our tests for it?

This moduleindex info only be used when GO111MODULE=on, and the go-helloworld is compiled with

GO111MODULE=off, so it is reproducible as it is. To improve test, we properly need to enable GO111MODULE

Can you do this please, and add the change to the patchset?

OK, I will change this in V4 patch.

//changqing

Quoted 2 lines

Alex

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw
Quoted 10 lines · Changqing Li via lists.openembedded.org
Quoted 8 lines · Alexander Kanavin

CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.

Quoted 4 lines · Changqing Li

There's go-helloworld in oe-core, which is reproducible as it is. How can the non-reproducibility that this patch is fixing be observed? Can we improve our tests for it?

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

This moduleindex info only be used when GO111MODULE=on,  and the go-helloworld is compiled with

GO111MODULE=off, so it is reproducible as it is. To improve test, we properly need to enable GO111MODULE

Can you do this please, and add the change to the patchset?

OK, I will change this in V4 patch.

I don't  include this patch in V4,  because I am considering add another example go program, which enable GO111MODULE

and also enable cgo, so we can cover this reproducibility issue and this one:

https://git.openembedded.org/openembedded-core/commit/?id=0642d2323072f561a4d0eeb9266213387b2997fc

So another patch will be sent later after above example program is ready.

Only change one minor typo issue in V4.

Regards

Changqing

Quoted 14 lines

//changqing

Quoted 2 lines

Alex

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#229221): https://lists.openembedded.org/g/openembedded-core/message/229221
Mute This Topic: https://lists.openembedded.org/mt/117148599/3616873
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-