diff options
12 files changed, 275 insertions, 19 deletions
diff --git a/meta/classes/go.bbclass b/meta/classes/go.bbclass index a9e31b50ea5..8b6c5ad5c24 100644 --- a/meta/classes/go.bbclass +++ b/meta/classes/go.bbclass @@ -14,6 +14,8 @@ export GOOS = "${TARGET_GOOS}" export GOHOSTARCH="${BUILD_GOARCH}" export GOHOSTOS="${BUILD_GOOS}" +export GODEBUG = "gocachehash=1" + GOARM[export] = "0" GOARM_arm_class-target = "${TARGET_GOARM}" GOARM_arm_class-target[export] = "1" @@ -52,6 +54,11 @@ GOTOOLDIR = "${STAGING_LIBDIR_NATIVE}/${TARGET_SYS}/go/pkg/tool/${BUILD_GOTUPLE} GOTOOLDIR_class-native = "${STAGING_LIBDIR_NATIVE}/go/pkg/tool/${BUILD_GOTUPLE}" export GOTOOLDIR +DEBUG_PREFIX_MAP = "-fmacro-prefix-map=${WORKDIR}=/usr/src/debug/${PN}/${EXTENDPE}${PV}-${PR} \ + -fdebug-prefix-map=${STAGING_DIR_HOST}= \ + -fdebug-prefix-map=${STAGING_DIR_NATIVE}= \ +" + export CGO_ENABLED ?= "1" export CGO_ENABLED_riscv64 = "0" export CGO_CFLAGS ?= "${CFLAGS}" @@ -64,7 +71,7 @@ GO_INSTALL_FILTEROUT ?= "${GO_IMPORT}/vendor/" B = "${WORKDIR}/build" export GOPATH = "${B}" -export GOTMPDIR ?= "${WORKDIR}/go-tmp" +export GOTMPDIR ?= "${WORKDIR}/build-tmp" GOTMPDIR[vardepvalue] = "" python go_do_unpack() { diff --git a/meta/conf/distro/include/default-providers.inc b/meta/conf/distro/include/default-providers.inc index ea88bd4876a..7465bc93a81 100644 --- a/meta/conf/distro/include/default-providers.inc +++ b/meta/conf/distro/include/default-providers.inc @@ -58,3 +58,6 @@ PREFERRED_PROVIDER_pkgconfig-native ?= "pkgconfig-native" PREFERRED_RPROVIDER_initd-functions ?= "initscripts" PREFERRED_PROVIDER_nativesdk-mesa ?= "nativesdk-mesa" + +PREFERRED_PROVIDER_go-native ?= "go-native" + diff --git a/meta/recipes-devtools/go/go-1.15.inc b/meta/recipes-devtools/go/go-1.15.inc index ccfb0c5987e..edd67dba446 100644 --- a/meta/recipes-devtools/go/go-1.15.inc +++ b/meta/recipes-devtools/go/go-1.15.inc @@ -6,15 +6,19 @@ FILESEXTRAPATHS_prepend := "${FILE_DIRNAME}/go-${GO_BASEVERSION}:" LIC_FILES_CHKSUM = "file://LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707" -SRC_URI += "\ - file://0001-allow-CC-and-CXX-to-have-multiple-words.patch \ - file://0002-cmd-go-make-content-based-hash-generation-less-pedan.patch \ - file://0003-allow-GOTOOLDIR-to-be-overridden-in-the-environment.patch \ - file://0004-ld-add-soname-to-shareable-objects.patch \ - file://0005-make.bash-override-CC-when-building-dist-and-go_boot.patch \ - file://0006-cmd-dist-separate-host-and-target-builds.patch \ - file://0007-cmd-go-make-GOROOT-precious-by-default.patch \ - file://0008-use-GOBUILDMODE-to-set-buildmode.patch \ - file://0009-cmd-go-permit-CGO_LDFLAGS-to-appear-in-go-ldflag.patch \ -" +SRC_URI += " \ + file://0001-allow-CC-and-CXX-to-have-multiple-words.patch \ + file://0002-cmd-go-make-content-based-hash-generation-less-pedan.patch \ + file://0003-allow-GOTOOLDIR-to-be-overridden-in-the-environment.patch \ + file://0004-ld-add-soname-to-shareable-objects.patch \ + file://0005-make.bash-override-CC-when-building-dist-and-go_boot.patch \ + file://0006-cmd-dist-separate-host-and-target-builds.patch \ + file://0007-cmd-go-make-GOROOT-precious-by-default.patch \ + file://0008-use-GOBUILDMODE-to-set-buildmode.patch \ + file://0009-cmd-go-permit-CGO_LDFLAGS-to-appear-in-go-ldflag.patch \ + file://0001-src-cmd-dist-buildgo.go-do-not-hardcode-host-compile.patch \ + file://0001-cgo-do-not-write-a-reference-to-the-original-file-in.patch \ + file://0001-action-do-not-clear-temp-dir.patch \ + file://0001-exec.go-do-not-write-linker-flags-into-buildids.patch \ + " SRC_URI[main.sha256sum] = "c1076b90cf94b73ebed62a81d802cd84d43d02dea8c07abdc922c57a071c84f1" diff --git a/meta/recipes-devtools/go/go-1.15/0001-action-do-not-clear-temp-dir.patch b/meta/recipes-devtools/go/go-1.15/0001-action-do-not-clear-temp-dir.patch new file mode 100644 index 00000000000..e0ecb172928 --- /dev/null +++ b/meta/recipes-devtools/go/go-1.15/0001-action-do-not-clear-temp-dir.patch @@ -0,0 +1,60 @@ +From dfb087d04ed38c8e2ef377d0afca6b7d8e409d3d Mon Sep 17 00:00:00 2001 +From: Alexander Kanavin <alex.kanavin@gmail.com> +Date: Mon, 23 Nov 2020 18:30:58 +0000 +Subject: [PATCH] action: do not clear temp dir + +Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com> +--- + src/cmd/go/internal/work/action.go | 24 +++--------------------- + 1 file changed, 3 insertions(+), 21 deletions(-) + +diff --git a/src/cmd/go/internal/work/action.go b/src/cmd/go/internal/work/action.go +index 2ab7860..f195800 100644 +--- a/src/cmd/go/internal/work/action.go ++++ b/src/cmd/go/internal/work/action.go +@@ -16,7 +16,6 @@ import ( + "io/ioutil" + "os" + "path/filepath" +- "runtime" + "strings" + "sync" + "time" +@@ -256,7 +255,7 @@ func (b *Builder) Init() { + if !filepath.IsAbs(tmp) { + abs, err := filepath.Abs(tmp) + if err != nil { +- os.RemoveAll(tmp) ++ //os.RemoveAll(tmp) + base.Fatalf("go: creating work dir: %v", err) + } + tmp = abs +@@ -266,26 +265,9 @@ func (b *Builder) Init() { + fmt.Fprintf(os.Stderr, "WORK=%s\n", b.WorkDir) + } + if !cfg.BuildWork { +- workdir := b.WorkDir ++ //workdir := b.WorkDir + base.AtExit(func() { +- start := time.Now() +- for { +- err := os.RemoveAll(workdir) +- if err == nil { +- return +- } +- +- // On some configurations of Windows, directories containing executable +- // files may be locked for a while after the executable exits (perhaps +- // due to antivirus scans?). It's probably worth a little extra latency +- // on exit to avoid filling up the user's temporary directory with leaked +- // files. (See golang.org/issue/30789.) +- if runtime.GOOS != "windows" || time.Since(start) >= 500*time.Millisecond { +- fmt.Fprintf(os.Stderr, "go: failed to remove work dir: %s\n", err) +- return +- } +- time.Sleep(5 * time.Millisecond) +- } ++ return + }) + } + } diff --git a/meta/recipes-devtools/go/go-1.15/0001-cgo-do-not-write-a-reference-to-the-original-file-in.patch b/meta/recipes-devtools/go/go-1.15/0001-cgo-do-not-write-a-reference-to-the-original-file-in.patch new file mode 100644 index 00000000000..484e2ce050c --- /dev/null +++ b/meta/recipes-devtools/go/go-1.15/0001-cgo-do-not-write-a-reference-to-the-original-file-in.patch @@ -0,0 +1,27 @@ +From 66b449ef1d5e0919f13075d0cb2de134feee7fc3 Mon Sep 17 00:00:00 2001 +From: Alexander Kanavin <alex.kanavin@gmail.com> +Date: Wed, 18 Nov 2020 21:32:53 +0000 +Subject: [PATCH] cgo: do not write a reference to the original file into + transient source + +This can contain full build paths which is non-reproducible. + +Upstream-Status: Pending +Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com> +--- + src/cmd/cgo/out.go | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go +index cbdb4e0..cc92ccb 100644 +--- a/src/cmd/cgo/out.go ++++ b/src/cmd/cgo/out.go +@@ -604,7 +604,7 @@ func (p *Package) writeOutput(f *File, srcfile string) { + + // Write Go output: Go input with rewrites of C.xxx to _C_xxx. + fmt.Fprintf(fgo1, "// Code generated by cmd/cgo; DO NOT EDIT.\n\n") +- fmt.Fprintf(fgo1, "//line %s:1:1\n", srcfile) ++ //fmt.Fprintf(fgo1, "//line %s:1:1\n", srcfile) + fgo1.Write(f.Edit.Bytes()) + + // While we process the vars and funcs, also write gcc output. diff --git a/meta/recipes-devtools/go/go-1.15/0001-exec.go-do-not-write-linker-flags-into-buildids.patch b/meta/recipes-devtools/go/go-1.15/0001-exec.go-do-not-write-linker-flags-into-buildids.patch new file mode 100644 index 00000000000..61eca3c40b8 --- /dev/null +++ b/meta/recipes-devtools/go/go-1.15/0001-exec.go-do-not-write-linker-flags-into-buildids.patch @@ -0,0 +1,35 @@ +From bdd69b55387f80c8df18d0af5008bf5e1a66be6a Mon Sep 17 00:00:00 2001 +From: Alexander Kanavin <alex.kanavin@gmail.com> +Date: Mon, 23 Nov 2020 19:22:04 +0000 +Subject: [PATCH] exec.go: do not write linker flags into buildids + +Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com> +--- + src/cmd/go/internal/work/exec.go | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go +index 696db23..727d40b 100644 +--- a/src/cmd/go/internal/work/exec.go ++++ b/src/cmd/go/internal/work/exec.go +@@ -1136,7 +1136,7 @@ func (b *Builder) linkActionID(a *Action) cache.ActionID { + } + + // Toolchain-dependent configuration, shared with b.linkSharedActionID. +- b.printLinkerConfig(h, p) ++ //b.printLinkerConfig(h, p) + + // Input files. + for _, a1 := range a.Deps { +@@ -1418,7 +1418,7 @@ func (b *Builder) linkSharedActionID(a *Action) cache.ActionID { + fmt.Fprintf(h, "goos %s goarch %s\n", cfg.Goos, cfg.Goarch) + + // Toolchain-dependent configuration, shared with b.linkActionID. +- b.printLinkerConfig(h, nil) ++ //b.printLinkerConfig(h, nil) + + // Input files. + for _, a1 := range a.Deps { +-- +2.17.1 + diff --git a/meta/recipes-devtools/go/go-1.15/0001-src-cmd-dist-buildgo.go-do-not-hardcode-host-compile.patch b/meta/recipes-devtools/go/go-1.15/0001-src-cmd-dist-buildgo.go-do-not-hardcode-host-compile.patch new file mode 100644 index 00000000000..91dccaff4b5 --- /dev/null +++ b/meta/recipes-devtools/go/go-1.15/0001-src-cmd-dist-buildgo.go-do-not-hardcode-host-compile.patch @@ -0,0 +1,40 @@ +From 2055a46b396e272616c0b2273903e02c3b49a2ff Mon Sep 17 00:00:00 2001 +From: Alexander Kanavin <alex.kanavin@gmail.com> +Date: Tue, 10 Nov 2020 16:33:27 +0000 +Subject: [PATCH] src/cmd/dist/buildgo.go: do not hardcode host compilers into + target binaries + +This helps reproducibility. + +Upstream-Status: Inappropriate [oe-core specific] +Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com> +--- + src/cmd/dist/buildgo.go | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/src/cmd/dist/buildgo.go b/src/cmd/dist/buildgo.go +index caafc13..4eb1c96 100644 +--- a/src/cmd/dist/buildgo.go ++++ b/src/cmd/dist/buildgo.go +@@ -34,8 +34,8 @@ func mkzdefaultcc(dir, file string) { + fmt.Fprintf(&buf, "package cfg\n") + fmt.Fprintln(&buf) + fmt.Fprintf(&buf, "const DefaultPkgConfig = `%s`\n", defaultpkgconfig) +- buf.WriteString(defaultCCFunc("DefaultCC", defaultcc)) +- buf.WriteString(defaultCCFunc("DefaultCXX", defaultcxx)) ++ buf.WriteString(defaultCCFunc("DefaultCC", map[string]string{"":"gcc"})) ++ buf.WriteString(defaultCCFunc("DefaultCXX", map[string]string{"":"g++"})) + writefile(buf.String(), file, writeSkipSame) + return + } +@@ -46,8 +46,8 @@ func mkzdefaultcc(dir, file string) { + fmt.Fprintf(&buf, "package main\n") + fmt.Fprintln(&buf) + fmt.Fprintf(&buf, "const defaultPkgConfig = `%s`\n", defaultpkgconfig) +- buf.WriteString(defaultCCFunc("defaultCC", defaultcc)) +- buf.WriteString(defaultCCFunc("defaultCXX", defaultcxx)) ++ buf.WriteString(defaultCCFunc("defaultCC", map[string]string{"":"gcc"})) ++ buf.WriteString(defaultCCFunc("defaultCXX", map[string]string{"":"g++"})) + writefile(buf.String(), file, writeSkipSame) + } + diff --git a/meta/recipes-devtools/go/go-1.15/0001-src-cmd-go-internal-work-action.go-do-not-randomize-.patch b/meta/recipes-devtools/go/go-1.15/0001-src-cmd-go-internal-work-action.go-do-not-randomize-.patch new file mode 100644 index 00000000000..ce3215c2f07 --- /dev/null +++ b/meta/recipes-devtools/go/go-1.15/0001-src-cmd-go-internal-work-action.go-do-not-randomize-.patch @@ -0,0 +1,50 @@ +From bc4413bb5185bc742e46c470a129d04dce9e15fd Mon Sep 17 00:00:00 2001 +From: Alexander Kanavin <alex.kanavin@gmail.com> +Date: Thu, 12 Nov 2020 09:17:25 +0000 +Subject: [PATCH] src/cmd/go/internal/work/action.go: do not randomize build + directory name + +This sets off a chain that ends with go binary becoming non-reproducible +due to having a different build id in it every time: + +- go build creates a directory with a random name +- cgo module builds generates several .c files into that directory +- those modules are being built by gcc, leaking the random path into binary .o files +- cgo module becomes non-reproducible due to that, with a different +build id and content each time +- as building the final go binary depends on this module, go's build system writes a different +build id into it every time as well (it tracks not just the inputs, but also the tools used). + +I have made the build directory deterministic, but this might cause +parallel builds to clash (haven't seen it in testing though). Upstream +would probably need a different fix (hence Inappropriate status). + +Upstream-Status: Inappropriate [need to file a bug with the patch attached] +Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com> +--- + src/cmd/go/internal/work/action.go | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/src/cmd/go/internal/work/action.go b/src/cmd/go/internal/work/action.go +index 2ab7860..2cc954a 100644 +--- a/src/cmd/go/internal/work/action.go ++++ b/src/cmd/go/internal/work/action.go +@@ -13,7 +13,6 @@ import ( + "debug/elf" + "encoding/json" + "fmt" +- "io/ioutil" + "os" + "path/filepath" + "runtime" +@@ -249,7 +248,9 @@ func (b *Builder) Init() { + if cfg.BuildN { + b.WorkDir = "$WORK" + } else { +- tmp, err := ioutil.TempDir(cfg.Getenv("GOTMPDIR"), "go-build") ++ //tmp, err := ioutil.TempDir(cfg.Getenv("GOTMPDIR"), "go-build") ++ tmp := cfg.Getenv("GOTMPDIR") + "/" + "go-build" ++ err := os.MkdirAll(tmp, 0755) + if err != nil { + base.Fatalf("go: creating work dir: %v", err) + } diff --git a/meta/recipes-devtools/go/go-1.15/0001-src-cmd-go-internal-work-exec.go-do-not-add-fdebug-p.patch b/meta/recipes-devtools/go/go-1.15/0001-src-cmd-go-internal-work-exec.go-do-not-add-fdebug-p.patch new file mode 100644 index 00000000000..982a0dc5ffa --- /dev/null +++ b/meta/recipes-devtools/go/go-1.15/0001-src-cmd-go-internal-work-exec.go-do-not-add-fdebug-p.patch @@ -0,0 +1,28 @@ +From fa000199408fdac04368d17b06f415315b5db61c Mon Sep 17 00:00:00 2001 +From: Alexander Kanavin <alex.kanavin@gmail.com> +Date: Sat, 14 Nov 2020 20:05:28 +0000 +Subject: [PATCH] src/cmd/go/internal/work/exec.go: do not add + -fdebug-prefix-map + +This thwarts both Yocto-supplied CFLAGS and Go's own mapping of +randomized build directory to a stable one. + +Upstream-Status: Pending [need to file a bug] +Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com> +--- + src/cmd/go/internal/work/exec.go | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go +index 696db23..6e20e18 100644 +--- a/src/cmd/go/internal/work/exec.go ++++ b/src/cmd/go/internal/work/exec.go +@@ -2225,7 +2225,7 @@ func (b *Builder) ccompile(a *Action, p *load.Package, outfile string, flags []s + } + flags = append(flags[:len(flags):len(flags)], "-fdebug-prefix-map="+from+"="+to) + } else if p.Goroot && cfg.GOROOT_FINAL != cfg.GOROOT { +- flags = append(flags[:len(flags):len(flags)], "-fdebug-prefix-map="+cfg.GOROOT+"="+cfg.GOROOT_FINAL) ++ //flags = append(flags[:len(flags):len(flags)], "-fdebug-prefix-map="+cfg.GOROOT+"="+cfg.GOROOT_FINAL) + } + } + diff --git a/meta/recipes-devtools/go/go-common.inc b/meta/recipes-devtools/go/go-common.inc index f18d928c704..e942dc2d9d6 100644 --- a/meta/recipes-devtools/go/go-common.inc +++ b/meta/recipes-devtools/go/go-common.inc @@ -23,7 +23,7 @@ INHIBIT_PACKAGE_DEBUG_SPLIT = "1" SSTATE_SCAN_CMD = "true" export GOROOT_OVERRIDE = "1" -export GOTMPDIR ?= "${WORKDIR}/go-tmp" +export GOTMPDIR ?= "${WORKDIR}/build-tmp" GOTMPDIR[vardepvalue] = "" export CGO_ENABLED = "1" diff --git a/meta/recipes-devtools/go/go-runtime.inc b/meta/recipes-devtools/go/go-runtime.inc index 21179a83a00..0a6d226dc88 100644 --- a/meta/recipes-devtools/go/go-runtime.inc +++ b/meta/recipes-devtools/go/go-runtime.inc @@ -2,9 +2,7 @@ DEPENDS = "virtual/${TUNE_PKGARCH}-go go-native" DEPENDS_class-nativesdk = "virtual/${TARGET_PREFIX}go-crosssdk" PROVIDES = "virtual/${TARGET_PREFIX}go-runtime" -export CGO_CFLAGS = "${CFLAGS}" export CGO_CPPFLAGS = "${CPPFLAGS}" -export CGO_CXXFLAGS = "${CXXFLAGS}" export CGO_LDFLAGS = "${LDFLAGS}" export GOCACHE = "${B}/.cache" @@ -20,8 +18,8 @@ do_configure_libc-musl() { } do_compile() { - export CC_FOR_${TARGET_GOTUPLE}="${CC}" - export CXX_FOR_${TARGET_GOTUPLE}="${CXX}" + export CC_FOR_${TARGET_GOTUPLE}="${CC} ${CFLAGS}" + export CXX_FOR_${TARGET_GOTUPLE}="${CXX} ${CXXFLAGS}" cd src ./make.bash --target-only --no-banner std diff --git a/meta/recipes-devtools/go/go-target.inc b/meta/recipes-devtools/go/go-target.inc index 8e442470318..8bec981aed7 100644 --- a/meta/recipes-devtools/go/go-target.inc +++ b/meta/recipes-devtools/go/go-target.inc @@ -6,13 +6,17 @@ GO_LDFLAGS = "" GO_LDFLAGS_class-nativesdk = "-linkmode external" export GO_LDFLAGS +#export GOBUILDFLAGS = "-v -trimpath" + +export GODEBUG = "gocachehash=1" + CC_append_class-nativesdk = " ${SECURITY_NOPIE_CFLAGS}" do_configure[noexec] = "1" do_compile() { - export CC_FOR_${TARGET_GOOS}_${TARGET_GOARCH}="${CC}" - export CXX_FOR_${TARGET_GOOS}_${TARGET_GOARCH}="${CXX}" + export CC_FOR_${TARGET_GOOS}_${TARGET_GOARCH}="${CC} ${CFLAGS}" + export CXX_FOR_${TARGET_GOOS}_${TARGET_GOARCH}="${CXX} ${CXXFLAGS}" cd src ./make.bash --target-only --no-banner |