go-cross: Fix host contamination for x86_64 host to x86_64 target
PATCH v2 1/1 go-cross: Fix host contamination for x86_64 host to x86_64 target
The go-cross package is explicitly for compiling target libraries on the host system. When the target architecture matches the host architecture it will actually use the host's linker and compiler however which can result in the generation of the cgo.a library having linker symbols which might not work properly when compiling other packages.
A typical error looks like this when building consul-migrate:
/opt/build-intel-x86/tmp/sysroots/x86_64-linux/usr/lib/x86_64-linux/go/pkg/tool/linux_amd64/link: running x86_64-yocto-linux-gcc failed: exit status 1 /opt/build-intel-x86/tmp/sysroots/x86_64-linux/usr/libexec/x86_64-yocto-linux/gcc/x86_64-yocto-linux/5.2.0/ld: /opt/build-intel-x86/tmp/work/core2-64-yocto-linux/consul-migrate/git-r0/build-tmp/go-link-956548052/000002.o: unrecognized relocation (0x2a) in section `.text' /opt/build-intel-x86/tmp/sysroots/x86_64-linux/usr/libexec/x86_64-yocto-linux/gcc/x86_64-yocto-linux/5.2.0/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
The fix is to use the make.bash --target-only option to properly build the libraries with the target toolchain.
When the host architecture does not match the target architecture we must also force build the target libraries or they get dynamically populated into the sysroot in an uncontrolled manner by the first package that uses go-cross to compile code.
--- recipes-devtools/go-cross/go-cross.inc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
recipes-devtools/go-cross/go-cross.inc +9 -1
@@ -2,6 +2,10 @@ inherit cross DEPENDS += "go-native" +# Prevent runstrip from running because you get errors when the host arch != target arch +#INHIBIT_PACKAGE_STRIP = "1" +STRIP = "echo" + export GOHOSTOS = "${BUILD_GOOS}" export GOHOSTARCH = "${BUILD_GOARCH}" export GOOS = "${TARGET_GOOS}"
@@ -26,6 +30,8 @@ do_compile() { cd src ./make.bash --host-only + # Ensure cgo.a is built with the target toolchain + GO_FLAGS="-a" ./make.bash --target-only } do_install() {
@@ -38,7 +44,9 @@ do_install() { install -d ${D}${bindir} for f in ${B}/bin/* do - install -m755 $f ${D}${bindir} + if [ ! -d "$f" ] ; then + install -m755 $f ${D}${bindir} + fi done }
Signature · 1 line
1.9.1
Quoted 17 lines · Jason Wessel
The go-cross package is explicitly for compiling target libraries on the host system. When the target architecture matches the host architecture it will actually use the host's linker and compiler however which can result in the generation of the cgo.a library having linker symbols which might not work properly when compiling other packages.
A typical error looks like this when building consul-migrate:
/opt/build-intel-x86/tmp/sysroots/x86_64-linux/usr/lib/x86_64-linux/go/pkg/tool/linux_amd64/link: running x86_64-yocto-linux-gcc failed: exit status 1/opt/build-intel-x86/tmp/sysroots/x86_64-linux/usr/libexec/x86_64-yocto-linux/gcc/x86_64-yocto-linux/5.2.0/ld:/opt/build-intel-x86/tmp/work/core2-64-yocto-linux/consul-migrate/git-r0/build-tmp/go-link-956548052/000002.o: unrecognized relocation (0x2a) in section `.text'/opt/build-intel-x86/tmp/sysroots/x86_64-linux/usr/libexec/x86_64-yocto-linux/gcc/x86_64-yocto-linux/5.2.0/ld: final link failed: Bad value
collect2: error: ld returned 1 exit statusThe fix is to use the make.bash --target-only option to properly build the libraries with the target toolchain.
Quoted 7 lines
When the host architecture does not match the target architecture we must also force build the target libraries or they get dynamically populated into the sysroot in an uncontrolled manner by the first package that uses go-cross to compile code.
Signed-off-by Jason Wessel <[email protected]>---
For the record book, V2 looks good.
Mark
Quoted 46 lines
recipes-devtools/go-cross/go-cross.inc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)recipes-devtools/go-cross/go-cross.inc +9
-2@@ -2,6 +2,10 @@ inherit cross DEPENDS += "go-native" +# Prevent runstrip from running because you get errors when the host arch != target arch +#INHIBIT_PACKAGE_STRIP = "1" +STRIP = "echo" + export GOHOSTOS = "${BUILD_GOOS}" export GOHOSTARCH = "${BUILD_GOARCH}" export GOOS = "${TARGET_GOOS}"@@ -26,6 +30,8 @@ do_compile() { cd src ./make.bash --host-only + # Ensure cgo.a is built with the target toolchain + GO_FLAGS="-a" ./make.bash --target-only } do_install() {@@ -38,7 +44,9 @@ do_install() { install -d ${D}${bindir} for f in ${B}/bin/* do - install -m755 $f ${D}${bindir} + if [ ! -d "$f" ] ; then + install -m755 $f ${D}${bindir} + fi done } --1.9.1
--
_______________________________________________
meta-virtualization mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/meta-virtualization
merged.
Bruce
Quoted 81 lines · Jason Wessel
The go-cross package is explicitly for compiling target libraries on the host system. When the target architecture matches the host architecture it will actually use the host's linker and compiler however which can result in the generation of the cgo.a library having linker symbols which might not work properly when compiling other packages.
A typical error looks like this when building consul-migrate:
/opt/build-intel-x86/tmp/sysroots/x86_64-linux/usr/lib/x86_64-linux/go/pkg/tool/linux_amd64/link: running x86_64-yocto-linux-gcc
failed: exit status 1/opt/build-intel-x86/tmp/sysroots/x86_64-linux/usr/libexec/x86_64-yocto-linux/gcc/x86_64-yocto-linux/5.2.0/ld:/opt/build-intel-x86/tmp/work/core2-64-yocto-linux/consul-migrate/git-r0/build-tmp/go-link-956548052/000002.o: unrecognized relocation (0x2a) in section `.text'/opt/build-intel-x86/tmp/sysroots/x86_64-linux/usr/libexec/x86_64-yocto-linux/gcc/x86_64-yocto-linux/5.2.0/ld: final link
failed: Bad value
collect2: error: ld returned 1 exit statusThe fix is to use the make.bash --target-only option to properly build the libraries with the target toolchain.
When the host architecture does not match the target architecture we must also force build the target libraries or they get dynamically populated into the sysroot in an uncontrolled manner by the first package that uses go-cross to compile code.
Signed-off-by Jason Wessel <[email protected]>--- recipes-devtools/go-cross/go-cross.inc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)recipes-devtools/go-cross/go-cross.inc +1
-0@@ -2,6 +2,10 @@ inherit cross DEPENDS += "go-native" +# Prevent runstrip from running because you get errors when the host arch!= target arch
recipes-devtools/go-cross/go-cross.inc +8
-2+#INHIBIT_PACKAGE_STRIP = "1" +STRIP = "echo" + export GOHOSTOS = "${BUILD_GOOS}" export GOHOSTARCH = "${BUILD_GOARCH}" export GOOS = "${TARGET_GOOS}"@@ -26,6 +30,8 @@ do_compile() { cd src ./make.bash --host-only + # Ensure cgo.a is built with the target toolchain + GO_FLAGS="-a" ./make.bash --target-only } do_install() {@@ -38,7 +44,9 @@ do_install() { install -d ${D}${bindir} for f in ${B}/bin/* do - install -m755 $f ${D}${bindir} + if [ ! -d "$f" ] ; then + install -m755 $f ${D}${bindir} + fi done } --1.9.1
--
_______________________________________________
meta-virtualization mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/meta-virtualization
Signature · 2 lines
"Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end"
Quoted 3 lines · Bruce Ashfield
merged.
bad news. This broke the build of go-cross on my machines (and on others .. which
is why I went to look into it).
Errors like this:
------------------------------
| /home/bruce/poky/build/tmp/work/core2-64-poky-linux/docker/1.12.0+git34d9a8240914d30f3a8fe28c1b7d1d4e36d0657b-r0/git/hack/make/.go-autogen:
line 23: /home/bruce/poky/build/tmp/sysroots/x86_64-linux/usr/bin/x86_64-pok
y-linux/go: No such file or directory
| ./hack/make.sh: line 221:/home/bruce/poky/build/tmp/sysroots/x86_64-linux/usr/bin/x86_64-poky-linux/go:
No such file or directory
| bundles/1.12.0-dev already exists. Removing.
|
| ./hack/make.sh: line 361:/home/bruce/poky/build/tmp/sysroots/x86_64-linux/usr/bin/x86_64-poky-linux/go:
No such file or directory
| ---> Making bundle: dynbinary (in bundles/1.12.0-dev/dynbinary)
| ./hack/make.sh: line 288:/home/bruce/poky/build/tmp/sysroots/x86_64-linux/usr/bin/x86_64-poky-linux/go:
No such file or directory
| /home/bruce/poky/build/tmp/work/core2-64-poky-linux/docker/1.12.0+git34d9a8240914d30f3a8fe28c1b7d1d4e36d0657b-r0/git/hack/make/.go-autogen:
line 23: /home/bruce/poky/build/tmp/sysroots/x86_64-linux/usr/bin/x86_64-pok
y-linux/go: No such file or directory
| /home/bruce/poky/build/tmp/work/core2-64-poky-linux/docker/1.12.0+git34d9a8240914d30f3a8fe28c1b7d1d4e36d0657b-r0/git/hack/make/.binary:
line 13:/home/bruce/poky/build/tmp/sysroots/x86_64-linux/usr/bin/x86_64-poky-li
nux/go: No such file or directory
| /home/bruce/poky/build/tmp/work/core2-64-poky-linux/docker/1.12.0+git34d9a8240914d30f3a8fe28c1b7d1d4e36d0657b-r0/git/hack/make/.binary:
line 13:/home/bruce/poky/build/tmp/sysroots/x86_64-linux/usr/bin/x86_64-poky-linux/go:
No such file or directory
| /home/bruce/poky/build/tmp/work/core2-64-poky-linux/docker/1.12.0+git34d9a8240914d30f3a8fe28c1b7d1d4e36d0657b-r0/git/hack/make/.binary:
line 13:/home/bruce/poky/build/tmp/sysroots/x86_64-linux/usr/bin/x86_64-poky-linux/go:
No such file or directory
| /home/bruce/poky/build/tmp/work/core2-64-poky-linux/docker/1.12.0+git34d9a8240914d30f3a8fe28c1b7d1d4e36d0657b-r0/git/hack/make/.binary:
line 13:/home/bruce/poky/build/tmp/sysroots/x86_64-linux/usr/bin/x86_64-poky-linux/go:
No such file or directory
| /home/bruce/poky/build/tmp/work/core2-64-poky-linux/docker/1.12.0+git34d9a8240914d30f3a8fe28c1b7d1d4e36d0657b-r0/git/hack/make/.binary:
line 23:/home/bruce/poky/build/tmp/sysroots/x86_64-linux/usr/bin/x86_64-poky-linux/go:
No such file or directory
| Building: bundles/1.12.0-dev/dynbinary-client/docker-1.12.0-dev
| /home/bruce/poky/build/tmp/work/core2-64-poky-linux/docker/1.12.0+git34d9a8240914d30f3a8fe28c1b7d1d4e36d0657b-r0/git/hack/make/.binary:
line 51:/home/bruce/poky/build/tmp/sysroots/x86_64-linux/usr/bin/x86_64-poky-linux/go:
No such file or directory
------------------
and this:
---------------
Log data follows:
| DEBUG: Executing shell function do_compile
| NOTE: make -j 20 static
| ERROR: oe_runmake failed
| /home/bruce/poky/build/tmp/work/core2-64-poky-linux/containerd/0.2.2+git0ac3cd1be170d180b2baed755e8f0da547ceb267-r0/git
| cd ctr && go build -ldflags "-w -extldflags -static -X github.com/docker/containerd.GitCommit=0ac3cd1be170d180b2baed755e8f0da547ceb267 " -tags "" -o ../bin/ctr
| cd containerd && go build -ldflags "-w -extldflags -static -X github.com/docker/containerd.GitCommit=0ac3cd1be170d180b2baed755e8f0da547ceb267 " -tags "" -o ../bin/containerd
| cd containerd-shim && go build -ldflags "-w -extldflags -static -X github.com/docker/containerd.GitCommit=0ac3cd1be170d180b2baed755e8f0da547ceb267 " -tags "" -o ../bin/containerd-shim
| # github.com/docker/docker/pkg/term
| cannot load DWARF output from $WORK/ github.com/docker/docker/pkg/term/_obj//_cgo_.o: decoding dwarf section info at offset 0x4: unsupported version 0
| make: *** [shim-static] Error 2
| make: *** Waiting for unfinished jobs....
| # github.com/docker/docker/pkg/term
| cannot load DWARF output from $WORK/ github.com/docker/docker/pkg/term/_obj//_cgo_.o: decoding dwarf section info at offset 0x4: unsupported version 0
| # github.com/opencontainers/runc/libcontainer/system
| cannot load DWARF output from $WORK/ github.com/opencontainers/runc/libcontainer/system/_obj//_cgo_
-------------------------------------------
In the spirit of keeping things buildable for the most part, I reverted the change and we can have another look at this.
Bruce
Quoted 93 lines
Bruce
Quoted 75 lines · Jason Wessel
The go-cross package is explicitly for compiling target libraries on the host system. When the target architecture matches the host architecture it will actually use the host's linker and compiler however which can result in the generation of the cgo.a library having linker symbols which might not work properly when compiling other packages.
A typical error looks like this when building consul-migrate:
/opt/build-intel-x86/tmp/sysroots/x86_64-linux/usr/lib/x86_64-linux/go/pkg/tool/linux_amd64/link: running x86_64-yocto-linux-gcc
failed: exit status 1/opt/build-intel-x86/tmp/sysroots/x86_64-linux/usr/libexec/x86_64-yocto-linux/gcc/x86_64-yocto-linux/5.2.0/ld:/opt/build-intel-x86/tmp/work/core2-64-yocto-linux/consul-migrate/git-r0/build-tmp/go-link-956548052/000002.o: unrecognized relocation (0x2a) in section `.text'/opt/build-intel-x86/tmp/sysroots/x86_64-linux/usr/libexec/x86_64-yocto-linux/gcc/x86_64-yocto-linux/5.2.0/ld: final link failed:
Bad value
collect2: error: ld returned 1 exit statusThe fix is to use the make.bash --target-only option to properly build the libraries with the target toolchain.
When the host architecture does not match the target architecture we must also force build the target libraries or they get dynamically populated into the sysroot in an uncontrolled manner by the first package that uses go-cross to compile code.
Signed-off-by Jason Wessel <[email protected]>--- recipes-devtools/go-cross/go-cross.inc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)recipes-devtools/go-cross/go-cross.inc +1
-0@@ -2,6 +2,10 @@ inherit cross DEPENDS += "go-native" +# Prevent runstrip from running because you get errors when the hostarch != target arch
recipes-devtools/go-cross/go-cross.inc +8
-2+#INHIBIT_PACKAGE_STRIP = "1" +STRIP = "echo" + export GOHOSTOS = "${BUILD_GOOS}" export GOHOSTARCH = "${BUILD_GOARCH}" export GOOS = "${TARGET_GOOS}"@@ -26,6 +30,8 @@ do_compile() { cd src ./make.bash --host-only + # Ensure cgo.a is built with the target toolchain + GO_FLAGS="-a" ./make.bash --target-only } do_install() {@@ -38,7 +44,9 @@ do_install() { install -d ${D}${bindir} for f in ${B}/bin/* do - install -m755 $f ${D}${bindir} + if [ ! -d "$f" ] ; then + install -m755 $f ${D}${bindir} + fi done } --1.9.1
Quoted 6 lines
--
_______________________________________________
meta-virtualization mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/meta-virtualization--
"Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end"
Signature · 2 lines
"Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end"