Skip to contentSkip to conversation

package/go: fixes

PATCH New Anisse Astier 2 participants 7 messages May 11, 2018

lore
Share & tools
lore
#0 lore raw

v2 cover package/go: fixes

Hi,

In this patch series, you'll find a fix to the build issues in the go package, as well as a debug feature and a minor version bump.

Regards,

Anisse

--
Changes since v1:
- rebase on top of Angelo's contribution, with my added sign-off to honor Developer Certificate of Origin
- second patch now contains only cleanup
- fix verbose variable scope pollution
- DEVELOPERS modification is now a standalone patch

Angelo Compagnucci (1):
package/go: fixing host go cross compilation

Anisse Astier (4):
go: cleanup cross-compilation support
go: add self to developers to get cc-ed for build failures
go: honor building with V=1 for debugging purposes
go: bump to version 1.10.2

 DEVELOPERS                                         |  3 ++
 ...d.go-explicit-option-for-crosscompilation.patch | 40 ++++++++++++++++++++++
 package/go/go.hash                                 |  2 +-
 package/go/go.mk                                   | 35 ++++++-------------
 4 files changed, 54 insertions(+), 26 deletions(-)
 create mode 100644 package/go/0001-build.go-explicit-option-for-crosscompilation.patch
Signature · 1 line
2.14.3
#1 lore raw

PATCH v2 1/5 package/go: fixing host go cross compilation

From: Angelo Compagnucci <[email protected]>

Actually if GOHOSTOS == GOOS || GOHOSTARCH == GOARCH the go build system assume it's not cross compiling and uses the same toolchain for both the host and the target. This commit adds a patch to enable the explicit GO_ASSUME_CROSSCOMPILING in go build system and updates to go package accordingly.

Fixes:
http://autobuild.buildroot.net/results/3636b1ac5756a782fd7578186508aaf9d105e3e9/
http://autobuild.buildroot.net/results/25790dca7e19527bb360d7dfb325cd9cfc3b56cc/
and many more.

References:
https://github.com/golang/go/issues/25177
https://golang.org/cl/112156

---
 ...d.go-explicit-option-for-crosscompilation.patch | 40 ++++++++++++++++++++++
 package/go/go.mk                                   |  3 +-
 2 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 package/go/0001-build.go-explicit-option-for-crosscompilation.patch
package/go/0001-build.go-explicit-option-for-crosscompilation.patch new file +40 -0
new file mode 100644
index 0000000000..f76c5b1d03
@@ -0,0 +1,40 @@
+From e1382a731a726293e30901038c6870fa77ef6095 Mon Sep 17 00:00:00 2001
+From: Angelo Compagnucci <[email protected]>
+Date: Tue, 8 May 2018 16:08:44 +0200
+Subject: [PATCH] build.go: explicit option for crosscompilation
+
+Actually if GOHOSTOS == GOOS || GOHOSTARCH == GOARCH the go build system
+assume it's not cross compiling and uses the same toolchain also for the
+bootstrap.  This is a problem in case the cross compilation mandates a
+different toolchain for bootstrap and target.  This patch adds
+GO_ASSUME_CROSSCOMPILING varible to assure that in case of cross
+compilation CC_FOR_TARGET can be different from CC.
+
+Signed-off-by: Angelo Compagnucci <[email protected]>
+Signed-off-by: Anisse Astier <[email protected]>
+---
+ src/cmd/dist/build.go | 3 ++-
+ 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
+--- a/src/cmd/dist/build.go
++++ b/src/cmd/dist/build.go
+@@ -252,12 +252,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}
++	crosscompiling := os.Getenv("GO_ASSUME_CROSSCOMPILING")
+ 
+ 	if env := os.Getenv(envName); env != "" {
+ 		m[""] = env
+ 	}
+ 	if env := os.Getenv(envName + "_FOR_TARGET"); env != "" {
+-		if gohostos != goos || gohostarch != goarch {
++		if gohostos != goos || gohostarch != goarch || crosscompiling == "1" {
+ 			m[gohostos+"/"+gohostarch] = m[""]
+ 		}
+ 		m[""] = env
+-- 
+2.7.4
+
package/go/go.mk +2 -1
index 4d55e16cc3..6af58f04be 100644
@@ -75,7 +75,8 @@ HOST_GO_MAKE_ENV = \
 	$(if $(GO_GOARM),GOARM=$(GO_GOARM)) \
 	GOOS=linux \
 	CC=$(HOSTCC_NOCCACHE) \
-	CXX=$(HOSTCXX_NOCCACHE)
+	CXX=$(HOSTCXX_NOCCACHE) \
+	GO_ASSUME_CROSSCOMPILING=1
 
 HOST_GO_TARGET_CC = \
 	CC_FOR_TARGET="$(TARGET_CC)" \
Signature · 1 line
2.14.3
#2 lore raw

PATCH v2 2/5 go: cleanup cross-compilation support

In reply to Anisse Astier

Now that we fixed cross-compilation in the go package, cleanup the build to remove the workaround added in 60c5c96ae109dcea48e0997b5e6e6645ac9b86 "package/go: Build host tools with host CC". We only need a single pass to build the go toolchain.

---
 package/go/go.mk | 27 +++++----------------------
 1 file changed, 5 insertions(+), 22 deletions(-)
package/go/go.mk +5 -22
index 6af58f04be..b70c5d49d8 100644
@@ -58,13 +58,7 @@ else
 HOST_GO_CGO_ENABLED = 0
 endif
 
-# The go build system doesn't have the notion of cross compiling, but just the
-# notion of architecture.  When the host and target architectures are different
-# it expects to be given a target cross compiler in CC_FOR_TARGET.  When the
-# architectures are the same it will use CC_FOR_TARGET for both host and target
-# compilation.  To work around this limitation build and install a set of
-# compiler and tool binaries built with CC_FOR_TARGET set to the host compiler.
-# Also, the go build system is not compatible with ccache, so use
+# The go build system is not compatible with ccache, so use
 # HOSTCC_NOCCACHE.  See https://github.com/golang/go/issues/11685.
 HOST_GO_MAKE_ENV = \
 	GOROOT_BOOTSTRAP=$(HOST_GO_BOOTSTRAP_ROOT) \
@@ -82,25 +76,14 @@ HOST_GO_TARGET_CC = \
 	CC_FOR_TARGET="$(TARGET_CC)" \
 	CXX_FOR_TARGET="$(TARGET_CXX)"
 
-HOST_GO_HOST_CC = \
-	CC_FOR_TARGET=$(HOSTCC_NOCCACHE) \
-	CXX_FOR_TARGET=$(HOSTCXX_NOCCACHE)
-
-HOST_GO_TMP = $(@D)/host-go-tmp
-
 define HOST_GO_BUILD_CMDS
-	cd $(@D)/src && \
-		$(HOST_GO_MAKE_ENV) $(HOST_GO_HOST_CC) CGO_ENABLED=0 ./make.bash
-	mkdir -p $(HOST_GO_TMP)
-	mv $(@D)/pkg/tool $(HOST_GO_TMP)/
-	mv $(@D)/bin/ $(HOST_GO_TMP)/
 	cd $(@D)/src && \
 		$(HOST_GO_MAKE_ENV) $(HOST_GO_TARGET_CC) CGO_ENABLED=$(HOST_GO_CGO_ENABLED) ./make.bash
 endef
 
 define HOST_GO_INSTALL_CMDS
-	$(INSTALL) -D -m 0755 $(HOST_GO_TMP)/bin/go $(HOST_GO_ROOT)/bin/go
-	$(INSTALL) -D -m 0755 $(HOST_GO_TMP)/bin/gofmt $(HOST_GO_ROOT)/bin/gofmt
+	$(INSTALL) -D -m 0755 $(@D)/bin/go $(HOST_GO_ROOT)/bin/go
+	$(INSTALL) -D -m 0755 $(@D)/bin/gofmt $(HOST_GO_ROOT)/bin/gofmt
 
 	ln -sf ../lib/go/bin/go $(HOST_DIR)/bin/
 	ln -sf ../lib/go/bin/gofmt $(HOST_DIR)/bin/
@@ -109,7 +92,7 @@ define HOST_GO_INSTALL_CMDS
 
 	mkdir -p $(HOST_GO_ROOT)/pkg
 	cp -a $(@D)/pkg/include $(@D)/pkg/linux_* $(HOST_GO_ROOT)/pkg/
-	cp -a $(HOST_GO_TMP)/tool $(HOST_GO_ROOT)/pkg/
+	cp -a $(@D)/pkg/tool $(HOST_GO_ROOT)/pkg/
 
 	# There is a known issue which requires the go sources to be installed
 	# https://golang.org/issue/2775
@@ -117,7 +100,7 @@ define HOST_GO_INSTALL_CMDS
 
 	# Set all file timestamps to prevent the go compiler from rebuilding any
 	# built in packages when programs are built.
-	find $(HOST_GO_ROOT) -type f -exec touch -r $(HOST_GO_TMP)/bin/go {} \;
+	find $(HOST_GO_ROOT) -type f -exec touch -r $(@D)/bin/go {} \;
 endef
 
 $(eval $(host-generic-package))
Signature · 1 line
2.14.3
#3 lore raw

PATCH v2 3/5 go: add self to developers to get cc-ed for build failures

In reply to Anisse Astier
---
 DEVELOPERS | 3 +++
 1 file changed, 3 insertions(+)
DEVELOPERS +3 -0
index b910a86a8c..dabea65b03 100644
@@ -153,6 +153,9 @@ F:	package/python-pydal/
 F:	package/python-web2py/
 F:	package/sysdig/
 
+N:	Anisse Astier <[email protected]>
+F:	package/go/
+
 N:	Antony Pavlov <[email protected]>
 F:	package/lsscsi/
 
Signature · 1 line
2.14.3
#4 lore raw

PATCH v2 4/5 go: honor building with V=1 for debugging purposes

In reply to Anisse Astier
---
 package/go/go.mk | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
package/go/go.mk +2 -1
index b70c5d49d8..6e2612481d 100644
@@ -78,7 +78,8 @@ HOST_GO_TARGET_CC = \
 
 define HOST_GO_BUILD_CMDS
 	cd $(@D)/src && \
-		$(HOST_GO_MAKE_ENV) $(HOST_GO_TARGET_CC) CGO_ENABLED=$(HOST_GO_CGO_ENABLED) ./make.bash
+		$(HOST_GO_MAKE_ENV) $(HOST_GO_TARGET_CC) CGO_ENABLED=$(HOST_GO_CGO_ENABLED) \
+		./make.bash $(if $(VERBOSE),-v)
 endef
 
 define HOST_GO_INSTALL_CMDS
Signature · 1 line
2.14.3
#5 lore raw

PATCH v2 5/5 go: bump to version 1.10.2

In reply to Anisse Astier

This bump contains many bug fixes, as well as the following security issue, patched in Go 1.10.1:

CVE-2018-7187: The "go get" implementation in Go 1.9.4, when the -insecure command-line option is used, does not validate the import path (get/vcs.go only checks for "://" anywhere in the string), which allows remote attackers to execute arbitrary OS commands via a crafted web site.

---
 package/go/go.hash | 2 +-
 package/go/go.mk   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
package/go/go.hash +1 -1
index 73c1578d0b..9f5b80e9f5 100644
@@ -1,2 +1,2 @@
 # From https://golang.org/dl/
-sha256	f3de49289405fda5fd1483a8fe6bd2fa5469e005fd567df64485c4fa000c7f24	go1.10.src.tar.gz
+sha256	6264609c6b9cd8ed8e02ca84605d727ce1898d74efa79841660b2e3e985a98bd	go1.10.2.src.tar.gz
package/go/go.mk +1 -1
index 6e2612481d..73f14cc78f 100644
@@ -4,7 +4,7 @@
 #
 ################################################################################
 
-GO_VERSION = 1.10
+GO_VERSION = 1.10.2
 GO_SITE = https://storage.googleapis.com/golang
 GO_SOURCE = go$(GO_VERSION).src.tar.gz
 
Signature · 1 line
2.14.3
#6 lore raw

v2 cover package/go: fixes

In reply to Anisse Astier

Hello,

Quoted 8 lines · Anisse Astier

Angelo Compagnucci (1):
package/go: fixing host go cross compilation

Anisse Astier (4):
go: cleanup cross-compilation support
go: add self to developers to get cc-ed for build failures
go: honor building with V=1 for debugging purposes
go: bump to version 1.10.2

Thanks a lot, series applied to master.

I've decided to apply the whole series to master because:

- PATCH 1 solves build failures reported in the autobuilders.

- PATCH 2 really could have been squashed into PATCH 1, it was mainly kept separate to preserve authorship

- PATCH 3 is just a documentation update, useful to make sure Anisse gets notified on "go" breakage.

- PATCH 4 is trivial

- PATCH 5 is a security update (I've adjusted the commit title to indicate it's a security bump)

Thanks Anisse for this work, much appreciated.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com