All, I'll send a V3, this patch was in my "outgoing" folder & was double-sent accidentally. Apologies for the double-send... Best regards, Christian Stewart On Tue, May 10, 2022 at 5:40 PM Christian Stewart wrote: > Enable the supported "riscv64" GOARCH. > > Add a patch to fix a build failure due to GOARCH leaking into the calls to > the > go-bootstrap compiler. Unsets the GOARCH before calling go-bootstrap. > > PR: https://github.com/golang/go/pull/52362 > > Signed-off-by: Christian Stewart > > --- > > v1 -> v2: > > - fixed build error with go-bootstrap > > Signed-off-by: Christian Stewart > --- > ...explicit-option-for-crosscompilation.patch | 8 +- > ...set-environment-before-generating-bu.patch | 111 ++++++++++++++++++ > package/go/Config.in.host | 2 +- > package/go/go.mk | 2 + > 4 files changed, 118 insertions(+), 5 deletions(-) > create mode 100644 > package/go/0002-build-bootstrap-set-environment-before-generating-bu.patch > > diff --git > a/package/go/0001-build.go-explicit-option-for-crosscompilation.patch > b/package/go/0001-build.go-explicit-option-for-crosscompilation.patch > index f76c5b1d03..a32a6ee355 100644 > --- a/package/go/0001-build.go-explicit-option-for-crosscompilation.patch > +++ b/package/go/0001-build.go-explicit-option-for-crosscompilation.patch > @@ -1,4 +1,4 @@ > -From e1382a731a726293e30901038c6870fa77ef6095 Mon Sep 17 00:00:00 2001 > +From 86fa3da18b5c73cc84dec91d92db4ae95f288bdc Mon Sep 17 00:00:00 2001 > From: Angelo Compagnucci > Date: Tue, 8 May 2018 16:08:44 +0200 > Subject: [PATCH] build.go: explicit option for crosscompilation > @@ -17,10 +17,10 @@ Signed-off-by: Anisse Astier > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go > -index 99d1db5..eb4097f 100644 > +index d37c3f83ef..d838485bd3 100644 > --- a/src/cmd/dist/build.go > +++ b/src/cmd/dist/build.go > -@@ -252,12 +252,13 @@ func xinit() { > +@@ -273,12 +273,13 @@ func xinit() { > // $CC_FOR_goos_goarch, if set, applies only to goos/goarch. > func compilerEnv(envName, def string) map[string]string { > m := map[string]string{"": def} > @@ -36,5 +36,5 @@ index 99d1db5..eb4097f 100644 > } > m[""] = env > -- > -2.7.4 > +2.35.1 > > diff --git > a/package/go/0002-build-bootstrap-set-environment-before-generating-bu.patch > b/package/go/0002-build-bootstrap-set-environment-before-generating-bu.patch > new file mode 100644 > index 0000000000..44b3fbecc2 > --- /dev/null > +++ > b/package/go/0002-build-bootstrap-set-environment-before-generating-bu.patch > @@ -0,0 +1,111 @@ > +From 00f3f4ee0d477779c87e4e60b08708362670e122 Mon Sep 17 00:00:00 2001 > +From: Christian Stewart > +Date: Thu, 14 Apr 2022 13:34:26 -0700 > +Subject: [PATCH] build: bootstrap: set environment before generating > buildcfg > + > +The GOOS and GOARCH environment variables should be unset before calling > +mkbuildcfg. This change fixes a build failure when GOARCH=riscv64. > + > +Building Go toolchain1 using go-1.4-bootstrap-20171003. > +src/cmd/compile/internal/ssa/rewriteRISCV64.go:4814 > +invalid operation: y << x (shift count type int64, must be unsigned > integer) > + > +There is a build issue with go1.4 with the riscv64 code: however, why is > the > +riscv64 code being compiled at all? > + > +GOARCH is set when calling mkbuildcfg, so go1.4 is trying to compile > riscv64. > +--- > + src/cmd/dist/buildtool.go | 56 ++++++++++++++++++++------------------- > + 1 file changed, 29 insertions(+), 27 deletions(-) > + > +diff --git a/src/cmd/dist/buildtool.go b/src/cmd/dist/buildtool.go > +index 036f8c52fa..73f6524969 100644 > +--- a/src/cmd/dist/buildtool.go > ++++ b/src/cmd/dist/buildtool.go > +@@ -112,9 +112,6 @@ func bootstrapBuildTools() { > + } > + xprintf("Building Go toolchain1 using %s.\n", goroot_bootstrap) > + > +- mkbuildcfg(pathf("%s/src/internal/buildcfg/zbootstrap.go", goroot)) > +- mkobjabi(pathf("%s/src/cmd/internal/objabi/zbootstrap.go", goroot)) > +- > + // Use $GOROOT/pkg/bootstrap as the bootstrap workspace root. > + // We use a subdirectory of $GOROOT/pkg because that's the > + // space within $GOROOT where we store all generated objects. > +@@ -126,6 +123,34 @@ func bootstrapBuildTools() { > + base := pathf("%s/src/bootstrap", workspace) > + xmkdirall(base) > + > ++ // Set up environment for invoking Go 1.4 go command. > ++ // GOROOT points at Go 1.4 GOROOT, > ++ // GOPATH points at our bootstrap workspace, > ++ // GOBIN is empty, so that binaries are installed to GOPATH/bin, > ++ // and GOOS, GOHOSTOS, GOARCH, and GOHOSTOS are empty, > ++ // so that Go 1.4 builds whatever kind of binary it knows how to > build. > ++ // Restore GOROOT, GOPATH, and GOBIN when done. > ++ // Don't bother with GOOS, GOHOSTOS, GOARCH, and GOHOSTARCH, > ++ // because setup will take care of those when bootstrapBuildTools > returns. > ++ > ++ defer os.Setenv("GOROOT", os.Getenv("GOROOT")) > ++ os.Setenv("GOROOT", goroot_bootstrap) > ++ > ++ defer os.Setenv("GOPATH", os.Getenv("GOPATH")) > ++ os.Setenv("GOPATH", workspace) > ++ > ++ defer os.Setenv("GOBIN", os.Getenv("GOBIN")) > ++ os.Setenv("GOBIN", "") > ++ > ++ os.Setenv("GOOS", "") > ++ os.Setenv("GOHOSTOS", "") > ++ os.Setenv("GOARCH", "") > ++ os.Setenv("GOHOSTARCH", "") > ++ > ++ // Create the build config files. > ++ mkbuildcfg(pathf("%s/src/internal/buildcfg/zbootstrap.go", goroot)) > ++ mkobjabi(pathf("%s/src/cmd/internal/objabi/zbootstrap.go", goroot)) > ++ > + // Copy source code into $GOROOT/pkg/bootstrap and rewrite import > paths. > + writefile("module bootstrap\n", pathf("%s/%s", base, "go.mod"), 0) > + for _, dir := range bootstrapDirs { > +@@ -172,30 +197,6 @@ func bootstrapBuildTools() { > + }) > + } > + > +- // Set up environment for invoking Go 1.4 go command. > +- // GOROOT points at Go 1.4 GOROOT, > +- // GOPATH points at our bootstrap workspace, > +- // GOBIN is empty, so that binaries are installed to GOPATH/bin, > +- // and GOOS, GOHOSTOS, GOARCH, and GOHOSTOS are empty, > +- // so that Go 1.4 builds whatever kind of binary it knows how to > build. > +- // Restore GOROOT, GOPATH, and GOBIN when done. > +- // Don't bother with GOOS, GOHOSTOS, GOARCH, and GOHOSTARCH, > +- // because setup will take care of those when bootstrapBuildTools > returns. > +- > +- defer os.Setenv("GOROOT", os.Getenv("GOROOT")) > +- os.Setenv("GOROOT", goroot_bootstrap) > +- > +- defer os.Setenv("GOPATH", os.Getenv("GOPATH")) > +- os.Setenv("GOPATH", workspace) > +- > +- defer os.Setenv("GOBIN", os.Getenv("GOBIN")) > +- os.Setenv("GOBIN", "") > +- > +- os.Setenv("GOOS", "") > +- os.Setenv("GOHOSTOS", "") > +- os.Setenv("GOARCH", "") > +- os.Setenv("GOHOSTARCH", "") > +- > + // Run Go 1.4 to build binaries. Use -gcflags=-l to disable > inlining to > + // workaround bugs in Go 1.4's compiler. See discussion thread: > + // > https://groups.google.com/d/msg/golang-dev/Ss7mCKsvk8w/Gsq7VYI0AwAJ > +@@ -217,6 +218,7 @@ func bootstrapBuildTools() { > + cmd = append(cmd, "-toolexec="+tool) > + } > + cmd = append(cmd, "bootstrap/cmd/...") > ++ > + run(base, ShowOutput|CheckExit, cmd...) > + > + // Copy binaries into tool binary directory. > +-- > +2.35.1 > + > diff --git a/package/go/Config.in.host b/package/go/Config.in.host > index e82ab6e81a..8be86103ea 100644 > --- a/package/go/Config.in.host > +++ b/package/go/Config.in.host > @@ -5,7 +5,7 @@ config BR2_PACKAGE_HOST_GO_TARGET_ARCH_SUPPORTS > depends on BR2_PACKAGE_HOST_GO_BOOTSTRAP_ARCH_SUPPORTS > depends on (BR2_arm && BR2_TOOLCHAIN_SUPPORTS_PIE) || BR2_aarch64 \ > || BR2_i386 || BR2_x86_64 || BR2_powerpc64le \ > - || BR2_mips64 || BR2_mips64el || BR2_s390x > + || BR2_mips64 || BR2_mips64el || BR2_riscv || BR2_s390x > depends on !BR2_ARM_CPU_ARMV4 > # MIPS R6 support in Go has not yet been developed. > depends on !BR2_MIPS_CPU_MIPS64R6 > diff --git a/package/go/go.mk b/package/go/go.mk > index 3df16c9a68..ba0da74b86 100644 > --- a/package/go/go.mk > +++ b/package/go/go.mk > @@ -63,6 +63,8 @@ else ifeq ($(BR2_mips64),y) > GO_GOARCH = mips64 > else ifeq ($(BR2_mips64el),y) > GO_GOARCH = mips64le > +else ifeq ($(BR2_riscv),y) > +GO_GOARCH = riscv64 > else ifeq ($(BR2_s390x),y) > GO_GOARCH = s390x > endif > -- > 2.35.1 > >