]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
go: fix buildpath issue for go-runtime
authorHongxu Jia <hongxu.jia@windriver.com>
Sat, 1 Mar 2025 07:55:51 +0000 (15:55 +0800)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 3 Mar 2025 18:00:47 +0000 (18:00 +0000)
In upstream commit [cmd: remove support for GOROOT_FINAL][1], it clear
GOROOT for func ld when -trimpath is used

But it missed to do the same thing for share libarary linking which caused
building go-runtime failed with buildpath issue

|ERROR: go-runtime-1.23.4-r0 do_package_qa: QA Issue: File /usr/lib/go/pkg/
linux_amd64_dynlink/libstd.so in package go-runtime contains reference to
TMPDIR [buildpaths]

This commit applied a patch to clear GOROOT for func ldShared when
-trimpath is used and add option -trimpath to go-runtime build

[1] https://github.com/golang/go/commit/507d1b22f4b58ac68841582d0c2c0ab6b20e5a98
[2] https://github.com/golang/go/commit/507d1b22f4b58ac68841582d0c2c0ab6b20e5a98#diff-cab5921f94f2667bb0bc1b935d2d46b4c03541b4351b33438ab7290b94dea212R669

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/recipes-devtools/go/go-1.24.0.inc
meta/recipes-devtools/go/go-runtime.inc
meta/recipes-devtools/go/go/0010-cmd-go-clear-GOROOT-for-func-ldShared-when-trimpath-.patch [new file with mode: 0644]

index 26a4947cafb636015711795c9f8693c0c5f9e8cf..a52dd19e76a4546e1b575203168aaba2ba6fb28f 100644 (file)
@@ -14,6 +14,7 @@ SRC_URI += "\
     file://0007-exec.go-filter-out-build-specific-paths-from-linker-.patch \
     file://0008-src-cmd-dist-buildgo.go-do-not-hardcode-host-compile.patch \
     file://0009-go-Filter-build-paths-on-staticly-linked-arches.patch \
+    file://0010-cmd-go-clear-GOROOT-for-func-ldShared-when-trimpath-.patch \
     file://6d265b008e3d106b2706645e5a88cd8e2fb98953.patch \
 "
 SRC_URI[main.sha256sum] = "d14120614acb29d12bcab72bd689f257eb4be9e0b6f88a8fb7e41ac65f8556e5"
index 413cf6d33f0b107242c92a111b479c2f03ebc131..e5f17337bcb100d9b57b09a28166fef6ac9f5a68 100644 (file)
@@ -34,7 +34,7 @@ do_compile() {
        if [ -n "${GO_DYNLINK}" ]; then
                export GOTOOLDIR="${B}/pkg/tool/native_native"
                CC="$CC_FOR_${TARGET_GOTUPLE}" GOARCH="${TARGET_GOARCH}" GOOS="${TARGET_GOOS}" GOROOT=${B} \
-                       $GOTOOLDIR/go_bootstrap install -linkshared -buildmode=shared ${GO_SHLIB_LDFLAGS} std
+                       $GOTOOLDIR/go_bootstrap install -linkshared -trimpath -buildmode=shared ${GO_SHLIB_LDFLAGS} std
        fi
        cd ${B}
 }
diff --git a/meta/recipes-devtools/go/go/0010-cmd-go-clear-GOROOT-for-func-ldShared-when-trimpath-.patch b/meta/recipes-devtools/go/go/0010-cmd-go-clear-GOROOT-for-func-ldShared-when-trimpath-.patch
new file mode 100644 (file)
index 0000000..2c2f0cb
--- /dev/null
@@ -0,0 +1,51 @@
+From c4215b5ca69a7626d97cf9b7ebc460c2b5b9148b Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Fri, 28 Feb 2025 19:13:18 -0800
+Subject: [PATCH 10/11] cmd/go: clear GOROOT for func ldShared when -trimpath
+ is used
+
+In commit [cmd: remove support for GOROOT_FINAL][1], it clear GOROOT
+for func ld when -trimpath is used. [2]
+
+This commit do the same thing for func ldShared, otherwise run go_bootstrap
+with -trimpath does not remove build path directory from the generated share
+libarary
+
+  $ ./make.bash --target-only --no-banner std
+  $ go_bootstrap install -linkshared -buildmode=shared -trimpath std
+  $ grep "$(pwd)" ./pkg/linux_amd64_dynlink/libstd.so
+  Binary file ./pkg/linux_amd64_dynlink/libstd.so matches
+
+[1] https://github.com/golang/go/commit/507d1b22f4b58ac68841582d0c2c0ab6b20e5a98
+[2] https://github.com/golang/go/commit/507d1b22f4b58ac68841582d0c2c0ab6b20e5a98#diff-cab5921f94f2667bb0bc1b935d2d46b4c03541b4351b33438ab7290b94dea212R669
+
+Upstream-Status: Submitted [https://go-review.googlesource.com/c/go/+/653895]
+
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+---
+ src/cmd/go/internal/work/gc.go | 9 ++++++++-
+ 1 file changed, 8 insertions(+), 1 deletion(-)
+
+diff --git a/src/cmd/go/internal/work/gc.go b/src/cmd/go/internal/work/gc.go
+index 3a173efee8..8b7a44e031 100644
+--- a/src/cmd/go/internal/work/gc.go
++++ b/src/cmd/go/internal/work/gc.go
+@@ -728,7 +728,14 @@ func (gcToolchain) ldShared(b *Builder, root *Action, toplevelactions []*Action,
+       // the output file path is recorded in the .gnu.version_d section.
+       dir, targetPath := filepath.Split(targetPath)
+-      return b.Shell(root).run(dir, targetPath, nil, cfg.BuildToolexec, base.Tool("link"), "-o", targetPath, "-importcfg", importcfg, ldflags)
++      env := []string{}
++      // When -trimpath is used, GOROOT is cleared
++      if cfg.BuildTrimpath {
++              env = append(env, "GOROOT=")
++      } else {
++              env = append(env, "GOROOT="+cfg.GOROOT)
++      }
++      return b.Shell(root).run(dir, targetPath, env, cfg.BuildToolexec, base.Tool("link"), "-o", targetPath, "-importcfg", importcfg, ldflags)
+ }
+ func (gcToolchain) cc(b *Builder, a *Action, ofile, cfile string) error {
+-- 
+2.25.1
+