golang: Set buildid and enable stripping for Go compiler
authorJeffery To <redacted>
Wed, 13 May 2020 08:02:09 +0000 (16:02 +0800)
committerJeffery To <redacted>
Wed, 13 May 2020 08:07:27 +0000 (16:07 +0800)
Doing both should make the compiler reproducible.

Signed-off-by: Jeffery To <redacted>
lang/golang/golang/Makefile

index 21e261b1cc79036c7d3636fb6a7caabc5a5d9004..54091398ef2ba64f6fb89ad03643bee134db391a 100644 (file)
@@ -12,7 +12,7 @@ GO_VERSION_PATCH:=2
 
 PKG_NAME:=golang
 PKG_VERSION:=$(GO_VERSION_MAJOR_MINOR)$(if $(GO_VERSION_PATCH),.$(GO_VERSION_PATCH))
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 GO_SOURCE_URLS:=https://dl.google.com/go/ \
                 https://mirrors.ustc.edu.cn/golang/ \
@@ -101,7 +101,7 @@ PKG_UNPACK:=$(HOST_TAR) -C $(PKG_BUILD_DIR) --strip-components=1 -xzf $(DL_DIR)/
 HOST_UNPACK:=$(HOST_TAR) -C $(HOST_BUILD_DIR) --strip-components=1 -xzf $(DL_DIR)/$(PKG_SOURCE)
 BOOTSTRAP_UNPACK:=$(HOST_TAR) -C $(BOOTSTRAP_BUILD_DIR) --strip-components=1 -xzf $(DL_DIR)/$(BOOTSTRAP_SOURCE)
 
-# don't strip ELF executables in test data (and go itself)
+# don't strip ELF executables in test data
 RSTRIP:=:
 STRIP:=:
 
@@ -197,6 +197,23 @@ endef
 EXTERNAL_BOOTSTRAP_DIR:=$(call qstrip,$(CONFIG_GOLANG_EXTERNAL_BOOTSTRAP_ROOT))
 USE_DEFAULT_BOOTSTRAP:=$(if $(EXTERNAL_BOOTSTRAP_DIR),,1)
 
+PKG_GO_LDFLAGS= \
+       -buildid '$(SOURCE_DATE_EPOCH)'
+
+ifeq ($(CONFIG_NO_STRIP)$(CONFIG_DEBUG),)
+  PKG_GO_LDFLAGS+= -s -w
+endif
+
+# setting -trimpath is not necessary here because the paths inside the
+# compiler binary are relative to GOROOT_FINAL (PKG_GO_ROOT), which is
+# static / not dependent on the build environment
+PKG_GO_INSTALL_ARGS= \
+       -ldflags "all=$(PKG_GO_LDFLAGS)"
+
+ifeq ($(PKG_GO_ENABLE_PIE),1)
+  PKG_GO_INSTALL_ARGS+= -buildmode pie
+endif
+
 define Download/golang-bootstrap
   FILE:=$(BOOTSTRAP_SOURCE)
   URL:=$(BOOTSTRAP_SOURCE_URL)
@@ -322,7 +339,7 @@ define Build/Compile
                CXX=g++ \
                PKG_CONFIG=pkg-config \
                PATH=$(HOST_GO_ROOT)/openwrt:$$$$PATH \
-               ./go-host install -a $(if $(PKG_GO_ENABLE_PIE),-buildmode=pie) std cmd ; \
+               ./go-host install -a $(PKG_GO_INSTALL_ARGS) std cmd ; \
                retval=$$$$? ; \
                rm -f go-host ; \
                exit $$$$retval ; \
git clone https://git.99rst.org/PROJECT