Skip to contentSkip to conversation

Fixes for go language support

PATCH New Geoff Levand 4 participants 16 messages May 26, 2016 – Oct 3, 2017

lore
Share & tools
lore
#0 lore raw

v3 cover Fixes for go language support

Hi,

This series includes a number of fixup for the go language support. All the buildbot problems pointed out by Thomas [1] should be resolved by this series.

Please consider all patches in this series to apply to master.

[1] http://lists.busybox.net/pipermail/buildroot/2016-April/159336.html

Changes for V3:
o Use two step compiler build for all configs.

-Geoff

The following changes since commit b5630ad7125d30cb5d65de49cc2f120bb5cf62ec:

eudev: link to real homepage (2016-05-26 15:50:01 +0200)

are available in the git repository at:

git at github.com:glevand/buildroot--buildroot.git for-merge-go-fixes-v3

for you to fetch changes up to a514602fc2cdd03806a41028d9943a7c94cf92b8:

package/go: Set file timestamp (2016-05-26 11:10:42 -0700)

----------------------------------------------------------------
Geoff Levand (6):
package/go: Build host tools with host CC package/go: Add HOST_GO_TARGET_ENV package/flannel: Use HOST_GO_TARGET_ENV package/go: Add HOST_GO_CGO_ENABLED package/flannel: Add BR2_TOOLCHAIN_HAS_THREADS package/go: Set file timestamp

 package/flannel/Config.in  |  4 ++++
 package/flannel/flannel.mk |  2 +-
 package/go/go.mk           | 54 +++++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 54 insertions(+), 6 deletions(-)
Signature · 1 line
2.5.0
#1 lore raw

PATCH v3 1/6 package/go: Build host tools with host CC

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 HOSTCC_NOCCACHE. See https://github.com/golang/go/issues/11685.

Fixes build errors like these:

host/usr/bin/go: No such file or directory

http://autobuild.buildroot.net/results/6664189a6f3a815978e8d0a1d7ef408ca47e2874/

---
 package/go/go.mk | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)
package/go/go.mk +25 -4
index a9e16dd..7ac2540 100644
@@ -35,6 +35,14 @@ endif
 HOST_GO_DEPENDENCIES = host-go-bootstrap
 HOST_GO_ROOT = $(HOST_DIR)/usr/lib/go
 
+# 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
+# HOSTCC_NOCCACHE.  See https://github.com/golang/go/issues/11685.
 HOST_GO_MAKE_ENV = \
 	GOROOT_BOOTSTRAP=$(HOST_GO_BOOTSTRAP_ROOT) \
 	GOROOT_FINAL=$(HOST_GO_ROOT) \
@@ -44,16 +52,29 @@ HOST_GO_MAKE_ENV = \
 	$(if $(GO_GOARM),GOARM=$(GO_GOARM)) \
 	GOOS=linux \
 	CGO_ENABLED=1 \
+	CC=$(HOSTCC_NOCCACHE)
+
+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=$(HOSTCC_NOCCACHE)
+
+HOST_GO_TMP = $(@D)/host-go-tmp
+
 define HOST_GO_BUILD_CMDS
-	cd $(@D)/src && $(HOST_GO_MAKE_ENV) ./make.bash
+	cd $(@D)/src && $(HOST_GO_MAKE_ENV) $(HOST_GO_HOST_CC) ./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) ./make.bash
 endef
 
 define HOST_GO_INSTALL_CMDS
-	$(INSTALL) -D -m 0755 $(@D)/bin/go $(HOST_GO_ROOT)/bin/go
-	$(INSTALL) -D -m 0755 $(@D)/bin/gofmt $(HOST_GO_ROOT)/bin/gofmt
+	$(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
 
 	ln -sf ../lib/go/bin/go $(HOST_DIR)/usr/bin/
 	ln -sf ../lib/go/bin/gofmt $(HOST_DIR)/usr/bin/
@@ -62,7 +83,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 $(@D)/pkg/tool $(HOST_GO_ROOT)/pkg/
+	cp -a $(HOST_GO_TMP)/tool $(HOST_GO_ROOT)/pkg/
 
 	# There is a known issue which requires the go sources to be installed
 	# https://golang.org/issue/2775
Signature · 1 line
2.5.0
#2 lore raw

PATCH v3 2/6 package/go: Add HOST_GO_TARGET_ENV

In reply to Geoff Levand

For the convenience of package makefiles define the new make variables HOST_GO_TOOLDIR and HOST_GO_TARGET_ENV.

---
 package/go/go.mk | 9 +++++++++
 1 file changed, 9 insertions(+)
package/go/go.mk +9 -0
index 7ac2540..090c5e4 100644
@@ -35,6 +35,15 @@ endif
 HOST_GO_DEPENDENCIES = host-go-bootstrap
 HOST_GO_ROOT = $(HOST_DIR)/usr/lib/go
 
+# For the convienience of target packages.
+HOST_GO_TOOLDIR = $(HOST_GO_ROOT)/pkg/tool/linux_$(GO_GOARCH)
+HOST_GO_TARGET_ENV = \
+	GOARCH=$(GO_GOARCH) \
+	GOROOT="$(HOST_GO_ROOT)" \
+	CC=$(TARGET_CC) \
+	CXX=$(TARGET_CXX) \
+	GOTOOLDIR="$(HOST_GO_TOOLDIR)"
+
 # 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
Signature · 1 line
2.5.0
#3 lore raw

PATCH v3 3/6 package/flannel: Use HOST_GO_TARGET_ENV

In reply to Geoff Levand

Use the newly added HOST_GO_TARGET_ENV variable to pickup the correct go environment for package builds.

---
 package/flannel/flannel.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
package/flannel/flannel.mk +1 -1
index 876efe6..b5f61a0 100644
@@ -14,9 +14,9 @@ FLANNEL_LICENSE_FILES = LICENSE
 FLANNEL_DEPENDENCIES = host-go
 
 FLANNEL_MAKE_ENV = \
+	$(HOST_GO_TARGET_ENV) \
 	GOBIN="$(@D)/bin" \
 	GOPATH="$(@D)/gopath" \
-	GOARCH=$(GO_GOARCH) \
 	CGO_ENABLED=1
 
 FLANNEL_GLDFLAGS = \
Signature · 1 line
2.5.0
#4 lore raw

PATCH v3 4/6 package/go: Add HOST_GO_CGO_ENABLED

In reply to Geoff Levand

The go compiler's cgo support uses threads. If BR2_TOOLCHAIN_HAS_THREADS is set, build in cgo support for any go programs that may need it. Note that any target package needing cgo support must include
'depends on BR2_TOOLCHAIN_HAS_THREADS' in its config file.

Fixes build errors like these:

error: #warning requested reentrant code

http://autobuild.buildroot.net/results/42a8d07101d8d954511d1c884ecb66e8d861899e

---
 package/go/go.mk | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
package/go/go.mk +11 -1
index 090c5e4..095c318 100644
@@ -44,6 +44,16 @@ HOST_GO_TARGET_ENV = \
 	CXX=$(TARGET_CXX) \
 	GOTOOLDIR="$(HOST_GO_TOOLDIR)"
 
+# The go compiler's cgo support uses threads.  If BR2_TOOLCHAIN_HAS_THREADS is
+# set, build in cgo support for any go programs that may need it.  Note that
+# any target package needing cgo support must include
+# 'depends on BR2_TOOLCHAIN_HAS_THREADS' in its config file.
+ifeq (BR2_TOOLCHAIN_HAS_THREADS,y)
+	HOST_GO_CGO_ENABLED = 1
+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
@@ -60,7 +70,7 @@ HOST_GO_MAKE_ENV = \
 	GOARCH=$(GO_GOARCH) \
 	$(if $(GO_GOARM),GOARM=$(GO_GOARM)) \
 	GOOS=linux \
-	CGO_ENABLED=1 \
+	CGO_ENABLED=$(HOST_GO_CGO_ENABLED) \
 	CC=$(HOSTCC_NOCCACHE)
 
 HOST_GO_TARGET_CC = \
Signature · 1 line
2.5.0
#5 lore raw

PATCH v3 4/6 package/go: Add HOST_GO_CGO_ENABLED

Hello,

package/go/go.mk HOST_GO_TARGET_ENV = \ · line 52

Quoted 6 lines · Geoff Levand
package/go/go.mk +6 -0
+# The go compiler's cgo support uses threads.  If BR2_TOOLCHAIN_HAS_THREADS is
+# set, build in cgo support for any go programs that may need it.  Note that
+# any target package needing cgo support must include
+# 'depends on BR2_TOOLCHAIN_HAS_THREADS' in its config file.
+ifeq (BR2_TOOLCHAIN_HAS_THREADS,y)
+	HOST_GO_CGO_ENABLED = 1

Such definitions are normally not indented, so I've fixed this here.

package/go/go.mk HOST_GO_TARGET_ENV = \ · line 54

Quoted 2 lines
package/go/go.mk +2 -0
+else
+	HOST_GO_CGO_ENABLED = 0

and here.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#6 lore raw

PATCH v3 4/6 package/go: Add HOST_GO_CGO_ENABLED

In reply to Geoff Levand

Dear Geoff, Thomas,

2016-05-26 20:21 GMT+02:00 Geoff Levand <[email protected]>:

Quoted 23 lines

The go compiler's cgo support uses threads. If BR2_TOOLCHAIN_HAS_THREADS is set, build in cgo support for any go programs that may need it. Note that any target package needing cgo support must include
'depends on BR2_TOOLCHAIN_HAS_THREADS' in its config file.

Fixes build errors like these:

error: #warning requested reentrant code

http://autobuild.buildroot.net/results/42a8d07101d8d954511d1c884ecb66e8d861899e

---
 package/go/go.mk | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
package/go/go.mk +0 -0
index 090c5e4..095c318 100644
@@ -44,6 +44,16 @@ HOST_GO_TARGET_ENV = \
        CXX=$(TARGET_CXX) \
        GOTOOLDIR="$(HOST_GO_TOOLDIR)"

package/go/go.mk HOST_GO_TARGET_ENV = \ · line 55

Quoted 10 lines
package/go/go.mk +9 -0
 
+# The go compiler's cgo support uses threads.  If BR2_TOOLCHAIN_HAS_THREADS is
+# set, build in cgo support for any go programs that may need it.  Note that
+# any target package needing cgo support must include
+# 'depends on BR2_TOOLCHAIN_HAS_THREADS' in its config file.
+ifeq (BR2_TOOLCHAIN_HAS_THREADS,y)
+       HOST_GO_CGO_ENABLED = 1
+else
+       HOST_GO_CGO_ENABLED = 0
+endif

I think this is buggy and should be something like that:

-ifeq (BR2_TOOLCHAIN_HAS_THREADS,y)
+ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)

Unfortunately, when I apply this fix, the package doesn't compile anymore. This is the build log:

##### Building packages and commands for linux/arm. runtime/internal/sys runtime/internal/atomic
runtime
errors
internal/race
sync/atomic
unicode
unicode/utf8
math
container/list
container/ring
crypto/subtle
crypto/internal/cipherhw
internal/nettrace
runtime/cgo vendor/golang_org/x/crypto/curve25519 encoding
sync
unicode/utf16

# runtime/cgo
gcc: error: unrecognized command line option '-marm'
image/color
vendor/golang_org/x/crypto/poly1305
internal/syscall/windows
internal/syscall/windows/registry
internal/syscall/windows/sysdll
runtime/race
cmd/compile/internal/test
cmd/vet/internal/whitelist
syscall
io
internal/singleflight
image/color/palette
hash
crypto/cipher
runtime/trace
bytes
strings
hash/adler32
hash/crc32
crypto/hmac
hash/crc64
hash/fnv
strconv
math/rand
math/cmplx
bufio
text/tabwriter
vendor/golang_org/x/text/transform
path
html
reflect
crypto
crypto/aes
crypto/rc4
encoding/base64
encoding/ascii85
encoding/base32
crypto/sha512
crypto/md5
crypto/sha1
crypto/sha256
image
internal/syscall/unix
time
image/internal/imageutil
image/draw
image/jpeg
os
os/signal
fmt
encoding/binary
sort
regexp/syntax
path/filepath
compress/bzip2
container/heap
encoding/pem
runtime/debug
cmd/internal/sys
crypto/des
vendor/golang_org/x/crypto/chacha20poly1305/internal/chacha20
vendor/golang_org/x/crypto/chacha20poly1305
io/ioutil
cmd/internal/dwarf
flag
log
debug/dwarf
compress/flate
debug/gosym
debug/plan9obj
cmd/vendor/golang.org/x/arch/arm/armasm
cmd/vendor/golang.org/x/arch/ppc64/ppc64asm
cmd/vendor/golang.org/x/arch/x86/x86asm
regexp
cmd/internal/obj
archive/tar
compress/zlib
archive/zip
compress/gzip
compress/lzw
context
math/big
debug/elf
debug/macho
debug/pe
encoding/hex
database/sql/driver
encoding/csv
encoding/gob
cmd/internal/goobj
encoding/json
encoding/xml
database/sql
vendor/golang_org/x/net/http2/hpack
vendor/golang_org/x/net/idna
vendor/golang_org/x/text/unicode/norm
cmd/internal/objfile
vendor/golang_org/x/text/width
crypto/dsa
crypto/elliptic
encoding/asn1
cmd/addr2line
crypto/rand
mime
mime/quotedprintable
crypto/rsa
crypto/ecdsa
crypto/x509/pkix
net/http/internal
net/url
go/token
text/template/parse
os/exec
text/scanner
image/gif
go/scanner
go/constant
image/png
index/suffixarray
internal/pprof/profile
testing
internal/trace
go/ast
net/internal/socktest
testing/iotest
testing/quick
text/template
cmd/internal/obj/arm
cmd/internal/obj/arm64
cmd/internal/obj/mips
cmd/internal/obj/ppc64
internal/testenv
cmd/internal/obj/s390x
go/parser
go/printer
runtime/pprof/internal/protopprof
cmd/internal/obj/x86
runtime/pprof
go/doc
html/template
testing/internal/testdeps
cmd/asm/internal/flags
go/types
cmd/asm/internal/lex
go/format
cmd/internal/bio
go/build
cmd/cgo
cmd/compile/internal/syntax
cmd/internal/gcprog
cmd/internal/browser
cmd/dist
cmd/fix
cmd/gofmt
cmd/asm/internal/arch
cmd/compile/internal/ssa
cmd/asm/internal/asm
cmd/cover
cmd/doc
cmd/link/internal/ld
cmd/asm
cmd/nm
cmd/objdump
cmd/pack
cmd/pprof/internal/plugin
go/internal/gccgoimporter
go/internal/gcimporter
cmd/api
cmd/pprof/internal/report
cmd/pprof/internal/svg
cmd/pprof/internal/tempfile
cmd/pprof/internal/symbolizer
go/importer
cmd/pprof/internal/symbolz
cmd/vet/internal/cfg
cmd/vet
cmd/pprof/internal/commands
cmd/pprof/internal/driver
cmd/link/internal/arm
cmd/link/internal/arm64
cmd/link/internal/amd64
cmd/link/internal/mips
cmd/link/internal/mips64
cmd/link/internal/ppc64
cmd/link/internal/s390x
cmd/link/internal/x86
cmd/link
cmd/compile/internal/gc
cmd/compile/internal/amd64
cmd/compile/internal/arm
cmd/compile/internal/arm64
cmd/compile/internal/mips
cmd/compile/internal/mips64
cmd/compile/internal/ppc64
cmd/compile/internal/s390x
cmd/compile/internal/x86
cmd/compile
package/pkg-generic.mk:234: recipe for target
'/media/angelo/WD/data/BUILDROOT/br_qemu_arm/build/host-go-1.8.3/.stamp_built'
failed
make[1]: *** [/media/angelo/WD/data/BUILDROOT/br_qemu_arm/build/host-go-1.8.3/.stamp_built]
Error 2

Geoff, have you any advice on how to debug the go build process? Unfortunately, I've not found anything like a log file that could help me.

Sincerely, Angelo

Quoted 21 lines
package/go/go.mk +2 -2
+
 # 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
@@ -60,7 +70,7 @@ HOST_GO_MAKE_ENV = \
        GOARCH=$(GO_GOARCH) \
        $(if $(GO_GOARM),GOARM=$(GO_GOARM)) \
        GOOS=linux \
-       CGO_ENABLED=1 \
+       CGO_ENABLED=$(HOST_GO_CGO_ENABLED) \
        CC=$(HOSTCC_NOCCACHE)
 
 HOST_GO_TARGET_CC = \
--

2.5.0

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

Signature · 1 line
Profile: http://it.linkedin.com/in/compagnucciangelo
#7 lore raw

PATCH v3 5/6 package/flannel: Add BR2_TOOLCHAIN_HAS_THREADS

In reply to Geoff Levand

flannel uses the cgo package, so needs a toolchain with thread support.

---
 package/flannel/Config.in | 4 ++++
 1 file changed, 4 insertions(+)
package/flannel/Config.in +4 -0
index c6a84ef..32d9f66 100644
@@ -1,6 +1,10 @@
+comment "flannel needs a toolchain w/ threads"
+	depends on !BR2_TOOLCHAIN_HAS_THREADS
+
 config BR2_PACKAGE_FLANNEL
 	bool "flannel"
 	depends on BR2_PACKAGE_HOST_GO_ARCH_SUPPORTS
+	depends on BR2_TOOLCHAIN_HAS_THREADS
 	help
 	  Flannel is a virtual network that gives a subnet to each
 	  host for use with container runtimes.
Signature · 1 line
2.5.0
#8 lore raw

PATCH v3 5/6 package/flannel: Add BR2_TOOLCHAIN_HAS_THREADS

Hello,

Quoted 13 lines · Geoff Levand

flannel uses the cgo package, so needs a toolchain with thread support.

---
 package/flannel/Config.in | 4 ++++
 1 file changed, 4 insertions(+)
package/flannel/Config.in +0 -0
index c6a84ef..32d9f66 100644

package/flannel/Config.in line 2

Quoted 2 lines
package/flannel/Config.in +2 -0
@@ -1,6 +1,10 @@
+comment "flannel needs a toolchain w/ threads"
+	depends on !BR2_TOOLCHAIN_HAS_THREADS

This also needs:

depends on BR2_PACKAGE_HOST_GO_ARCH_SUPPORTS

so that the comment doesn't show up on architectures that anyway don't support Go.

I've fixed that when applying.

Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#9 lore raw

PATCH v3 5/6 package/flannel: Add BR2_TOOLCHAIN_HAS_THREADS

In reply to Geoff Levand

Hello,

Quoted 7 lines · Geoff Levand

flannel uses the cgo package, so needs a toolchain with thread support.

---
 package/flannel/Config.in | 4 ++++
 1 file changed, 4 insertions(+)

There are still some issues with the flannel build:

http://autobuild.buildroot.org/results/d98/d98e1857590738313a293b58f02230539bbaa405/build-end.log

The error is:

/home/buildroot/autobuild/run/instance-2/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-buildroot-linux-uclibcgnueabi/4.9.3/../../../../arm-buildroot-linux-uclibcgnueabi/bin/ld: cannot find Scrt1.o: No such file or directory

My understanding is that this happens when trying to build PIE binaries that are statically linked. uClibc does not support that, or at least not with our current toolchain support. Would it be possible to not build PIE binaries with Go ? Or alternatively, investigate if it can be fixed in uClibc ?

Waldemar, maybe you have some input about this problem ?

Best regards,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#10 lore raw

PATCH v3 5/6 package/flannel: Add BR2_TOOLCHAIN_HAS_THREADS

Hi,
Thomas Petazzoni wrote,

Quoted 19 lines

Hello,

Quoted 7 lines · Geoff Levand

flannel uses the cgo package, so needs a toolchain with thread support.

---
 package/flannel/Config.in | 4 ++++
 1 file changed, 4 insertions(+)

There are still some issues with the flannel build:

http://autobuild.buildroot.org/results/d98/d98e1857590738313a293b58f02230539bbaa405/build-end.log

The error is:

/home/buildroot/autobuild/run/instance-2/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-buildroot-linux-uclibcgnueabi/4.9.3/../../../../arm-buildroot-linux-uclibcgnueabi/bin/ld: cannot find Scrt1.o: No such file or directory

Quoted 7 lines

My understanding is that this happens when trying to build PIE binaries that are statically linked. uClibc does not support that, or at least not with our current toolchain support. Would it be possible to not build PIE binaries with Go ? Or alternatively, investigate if it can be fixed in uClibc ?

Waldemar, maybe you have some input about this problem ?

Not more then you already told us.
The rule of thumb is: uClibc-ng + PIE + static = unsupported.

If anyone wnt to work on this, I am happy to include any patches. But I think some GCC magic must be done for this, too.

best regards
Waldemar

#11 lore raw

PATCH v3 5/6 package/flannel: Add BR2_TOOLCHAIN_HAS_THREADS

In reply to Thomas Petazzoni

Hi,

Quoted 6 lines · Thomas Petazzoni

There are still some issues with the flannel build:

http://autobuild.buildroot.org/results/d98/d98e1857590738313a293b58f02230539bbaa405/build-end.log

The error is:

Quoted 7 lines

/home/buildroot/autobuild/run/instance-2/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-buildroot-linux-uclibcgnueabi/4.9.3/../../../../arm-buildroot-linux-uclibcgnueabi/bin/ld: cannot find Scrt1.o: No such file or directory

My understanding is that this happens when trying to build PIE binaries that are statically linked. uClibc does not support that, or at least not with our current toolchain support. Would it be possible to not build PIE binaries with Go ? Or alternatively, investigate if it can be fixed in uClibc ?

Looking at the go sources, they force -pie when compiling cgo support for ARM. See line number 3188 in https://golang.org/src/cmd/go/build.go.

I think the only solution is to not build go packages that use cgo when BR2_arm && BR2_TOOLCHAIN_USES_UCLIBC, so something like this:

+# cgo on ARM requires PIE linkage, which is not compatable with uClibc. +comment "flannel is not available with uClibc-based toolchain on ARM architecture"

+       depends on BR2_PACKAGE_HOST_GO_ARCH_SUPPORTS
+       depends on BR2_TOOLCHAIN_HAS_THREADS
+       depends on BR2_arm && BR2_TOOLCHAIN_USES_UCLIBC

+
config BR2_PACKAGE_FLANNEL
bool "flannel"
depends on BR2_PACKAGE_HOST_GO_ARCH_SUPPORTS depends on BR2_TOOLCHAIN_HAS_THREADS
+ depends on !(BR2_arm && BR2_TOOLCHAIN_USES_UCLIBC)
help

If this looks OK, I'll submit a patch.

-Geoff

#12 lore raw

PATCH v3 5/6 package/flannel: Add BR2_TOOLCHAIN_HAS_THREADS

Hello,

Quoted 2 lines · Geoff Levand

Looking at the go sources, they force -pie when compiling cgo support for ARM. See line number 3188 in https://golang.org/src/cmd/go/build.go.

Can you get more details than the "get accurate imported sym" the code has?

Quoted 16 lines

I think the only solution is to not build go packages that use cgo when BR2_arm && BR2_TOOLCHAIN_USES_UCLIBC, so something like this:

(quoted diff) +7 -0
+# cgo on ARM requires PIE linkage, which is not compatable with uClibc.
+comment "flannel is not available with uClibc-based toolchain on ARM architecture"
+       depends on BR2_PACKAGE_HOST_GO_ARCH_SUPPORTS
+       depends on BR2_TOOLCHAIN_HAS_THREADS
+       depends on BR2_arm && BR2_TOOLCHAIN_USES_UCLIBC
+
 config BR2_PACKAGE_FLANNEL
        bool "flannel"
        depends on BR2_PACKAGE_HOST_GO_ARCH_SUPPORTS
        depends on BR2_TOOLCHAIN_HAS_THREADS
+       depends on !(BR2_arm && BR2_TOOLCHAIN_USES_UCLIBC)
        help
Quoted 1 line

If this looks OK, I'll submit a patch.

This is really annoying, as all Go packages that need cgo support will not work in what is probably Buildroot's most widely used
configuration: ARM with uClibc.

So I'd really like to push things a bit further, and either fix uClibc so that static+PIE works, or understand why Go wants PIE on ARM.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#13 lore raw

PATCH v3 5/6 package/flannel: Add BR2_TOOLCHAIN_HAS_THREADS

Hi,
Thomas Petazzoni wrote,

Quoted 26 lines

Hello,

Quoted 2 lines · Geoff Levand

Looking at the go sources, they force -pie when compiling cgo support for ARM. See line number 3188 in https://golang.org/src/cmd/go/build.go.

Can you get more details than the "get accurate imported sym" the code has?

Quoted 16 lines

I think the only solution is to not build go packages that use cgo when BR2_arm && BR2_TOOLCHAIN_USES_UCLIBC, so something like this:

(quoted diff) +7 -0
+# cgo on ARM requires PIE linkage, which is not compatable with uClibc.
+comment "flannel is not available with uClibc-based toolchain on ARM architecture"
+       depends on BR2_PACKAGE_HOST_GO_ARCH_SUPPORTS
+       depends on BR2_TOOLCHAIN_HAS_THREADS
+       depends on BR2_arm && BR2_TOOLCHAIN_USES_UCLIBC
+
 config BR2_PACKAGE_FLANNEL
        bool "flannel"
        depends on BR2_PACKAGE_HOST_GO_ARCH_SUPPORTS
        depends on BR2_TOOLCHAIN_HAS_THREADS
+       depends on !(BR2_arm && BR2_TOOLCHAIN_USES_UCLIBC)
        help
Quoted 8 lines
Quoted 1 line

If this looks OK, I'll submit a patch.

This is really annoying, as all Go packages that need cgo support will not work in what is probably Buildroot's most widely used
configuration: ARM with uClibc.

So I'd really like to push things a bit further, and either fix uClibc so that static+PIE works, or understand why Go wants PIE on ARM.

A first step would be to integrate Scrt1.o into the external toolchain packages. It is build when uClibc-ng SHARED is enabled together with crt1.o.

best regards
Waldemar

#14 lore raw

PATCH v3 6/6 package/go: Set file timestamp

In reply to Geoff Levand

Set all file timestamps to prevent the go compiler from rebuilding any built in packages when programs are built.

---
 package/go/go.mk | 4 ++++
 1 file changed, 4 insertions(+)
package/go/go.mk +4 -0
index 095c318..88d2316 100644
@@ -107,6 +107,10 @@ define HOST_GO_INSTALL_CMDS
 	# There is a known issue which requires the go sources to be installed
 	# https://golang.org/issue/2775
 	cp -a $(@D)/src $(HOST_GO_ROOT)/
+
+	# 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 {} \;
 endef
 
 $(eval $(host-generic-package))
Signature · 1 line
2.5.0
#15 lore raw

v3 cover Fixes for go language support

In reply to Geoff Levand

Hello,

Quoted 7 lines · Geoff Levand

Geoff Levand (6):
package/go: Build host tools with host CC package/go: Add HOST_GO_TARGET_ENV package/flannel: Use HOST_GO_TARGET_ENV package/go: Add HOST_GO_CGO_ENABLED package/flannel: Add BR2_TOOLCHAIN_HAS_THREADS package/go: Set file timestamp

Thanks, I've applied the series. I made a few changes on two patches (I'll comment on them directly), and I added an additional patch that adds double quotes around $(TARGET_CC) and $(TARGET_CXX). Indeed, when ccache support is enabled, those variables contain two words.

Thanks a lot!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com