Skip to contentSkip to conversation

go-runtime: prevent host leakage into target objects

PATCH Superseded Matt Madison 4 participants 5 messages Sep 29, 2017 – Oct 4, 2017

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 go-runtime: prevent host leakage into target objects

When building for a target whose architecture matches the build host's, the second pass through make.bash to build the shareable runtime would also overwrite the target's static cgo library with host-compatibile binaries.

Fix this by running the host-side build once and target-only passes of make.bash twice, for static and shareable. This ensures that what gets installed is target-compatible.

[YOCTO #12136]

---
 meta/recipes-devtools/go/go-runtime.inc | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
meta/recipes-devtools/go/go-runtime.inc +8 -3
index 934d1aa..bd26e2e 100644
@@ -23,9 +23,13 @@ do_compile() {
 	rm -rf ${GOBIN} ${B}/pkg
 	mkdir ${GOBIN}
 	cd src
-	GO_FLAGS="" ./make.bash
+	./make.bash --host-only
+	cp ${B}/pkg/tool/${BUILD_GOTUPLE}/go_bootstrap ${B}
+	rm -rf ${B}/pkg/${TARGET_GOTUPLE}
+	./make.bash --target-only
 	if [ -n "${GO_DYNLINK}" ]; then
-		GO_FLAGS="-buildmode=shared" GO_LDFLAGS="-extldflags \"${LDFLAGS}\"" ./make.bash
+		cp ${B}/go_bootstrap ${B}/pkg/tool/${BUILD_GOTUPLE}
+		GO_FLAGS="-buildmode=shared" GO_LDFLAGS="-extldflags \"${LDFLAGS}\"" ./make.bash --target-only
 	fi
 	cd ${B}
 }
@@ -41,8 +45,9 @@ do_install() {
 	rm -rf ${D}${libdir}/go/pkg/obj
 	rm -rf ${D}${libdir}/go/pkg/bootstrap
 	find src -mindepth 1 -maxdepth 1 -type d | while read srcdir; do
-		[ "$srcdir" = "./cmd" ] || cp --preserve=mode,timestamps -R $srcdir ${D}${libdir}/go/src/
+		cp --preserve=mode,timestamps -R $srcdir ${D}${libdir}/go/src/
 	done
+	rm -f ${D}${libdir}/go/src/cmd/dist/dist
 }
 
 # Remove test binaries that cannot be relocated
Signature · 1 line
2.7.4
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Matt Madison

When building for a target whose architecture matches the build host's, the second pass through make.bash to build the shareable runtime would also overwrite the target's static cgo library with host-compatibile binaries.

Quoted 8 lines

Fix this by running the host-side build once and target-only passes of make.bash twice, for static and shareable. This ensures that what gets installed is target-compatible.

[YOCTO #12136]

Signature · 3 lines
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://code.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750
#2 lore raw
In reply to Matt Madison
Quoted 6 lines · Matt Madison

When building for a target whose architecture matches the build host's, the second pass through make.bash to build the shareable runtime would also overwrite the target's static cgo library with host-compatibile binaries.

Quoted 7 lines

Fix this by running the host-side build once and target-only passes of make.bash twice, for static and shareable. This ensures that what gets installed is target-compatible.

[YOCTO #12136]

This does not appear to actually fix the bug mentioned here, I just found the failure again with intel-corei7-64 (from meta-intel) and then confirmed that it fails with qemux86-64 and genericx86-64 when using TCLIBC = "musl"

Can you please verify and test with MUSL.

Thanks
Sau!

Quoted 45 lines
---
 meta/recipes-devtools/go/go-runtime.inc | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
meta/recipes- renamed from meta/recipes-devtools/go/go-runtime.inc +0 -0

devtools/go/go-runtime.inc
index 934d1aa..bd26e2e 100644

meta/recipes-devtools/go/go-runtime.inc +4 -2
@@ -23,9 +23,13 @@ do_compile() {
 	rm -rf ${GOBIN} ${B}/pkg
 	mkdir ${GOBIN}
 	cd src
-	GO_FLAGS="" ./make.bash
+	./make.bash --host-only
+	cp ${B}/pkg/tool/${BUILD_GOTUPLE}/go_bootstrap ${B}
+	rm -rf ${B}/pkg/${TARGET_GOTUPLE}
+	./make.bash --target-only
 	if [ -n "${GO_DYNLINK}" ]; then
-		GO_FLAGS="-buildmode=shared" GO_LDFLAGS="-extldflags 

\"${LDFLAGS}\"" ./make.bash

meta/recipes-devtools/go/go-runtime.inc +2 -0
+		cp ${B}/go_bootstrap ${B}/pkg/tool/${BUILD_GOTUPLE}
+		GO_FLAGS="-buildmode=shared" GO_LDFLAGS="-extldflags 

\"${LDFLAGS}\"" ./make.bash --target-only

meta/recipes-devtools/go/go-runtime.inc +0 -0
 	fi
 	cd ${B}
 }
@@ -41,8 +45,9 @@ do_install() {
 	rm -rf ${D}${libdir}/go/pkg/obj
 	rm -rf ${D}${libdir}/go/pkg/bootstrap
 	find src -mindepth 1 -maxdepth 1 -type d | while read

srcdir; do

meta/recipes-devtools/go/go-runtime.inc +0 -1
-		[ "$srcdir" = "./cmd" ] || cp --

preserve=mode,timestamps -R $srcdir ${D}${libdir}/go/src/

meta/recipes-devtools/go/go-runtime.inc +1 -0
+		cp --preserve=mode,timestamps -R $srcdir

${D}${libdir}/go/src/

meta/recipes-devtools/go/go-runtime.inc +1 -0
 	done
+	rm -f ${D}${libdir}/go/src/cmd/dist/dist
 }
 
 # Remove test binaries that cannot be relocated
Signature · 1 line
2.7.4
#4 lore raw
In reply to Matt Madison
Quoted 6 lines · Matt Madison

When building for a target whose architecture matches the build host's, the second pass through make.bash to build the shareable runtime would also overwrite the target's static cgo library with host-compatibile binaries.

Quoted 7 lines

Fix this by running the host-side build once and target-only passes of make.bash twice, for static and shareable. This ensures that what gets installed is target-compatible.

[YOCTO #12136]

This does not appear to actually fix the bug mentioned here, I just found the failure again with intel-corei7-64 (from meta-intel) and then confirmed that it fails with qemux86-64 and genericx86-64 when using TCLIBC = "musl"

Can you please verify and test with MUSL.

Thanks
Sau!

Quoted 46 lines
---
 meta/recipes-devtools/go/go-runtime.inc | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
meta/recipes- renamed from meta/recipes-devtools/go/go-runtime.inc +0 -0

devtools/go/go-runtime.inc
index 934d1aa..bd26e2e 100644

meta/recipes-devtools/go/go-runtime.inc +4 -2
@@ -23,9 +23,13 @@ do_compile() {
 	rm -rf ${GOBIN} ${B}/pkg
 	mkdir ${GOBIN}
 	cd src
-	GO_FLAGS="" ./make.bash
+	./make.bash --host-only
+	cp ${B}/pkg/tool/${BUILD_GOTUPLE}/go_bootstrap ${B}
+	rm -rf ${B}/pkg/${TARGET_GOTUPLE}
+	./make.bash --target-only
 	if [ -n "${GO_DYNLINK}" ]; then
-		GO_FLAGS="-buildmode=shared" GO_LDFLAGS="-

extldflags
\"${LDFLAGS}\"" ./make.bash

meta/recipes-devtools/go/go-runtime.inc +2 -0
+		cp ${B}/go_bootstrap ${B}/pkg/tool/${BUILD_GOTUPLE}
+		GO_FLAGS="-buildmode=shared" GO_LDFLAGS="-

extldflags
\"${LDFLAGS}\"" ./make.bash --target-only

meta/recipes-devtools/go/go-runtime.inc +0 -0
 	fi
 	cd ${B}
 }
@@ -41,8 +45,9 @@ do_install() {
 	rm -rf ${D}${libdir}/go/pkg/obj
 	rm -rf ${D}${libdir}/go/pkg/bootstrap
 	find src -mindepth 1 -maxdepth 1 -type d | while read

srcdir; do

meta/recipes-devtools/go/go-runtime.inc +0 -1
-		[ "$srcdir" = "./cmd" ] || cp --

preserve=mode,timestamps -R $srcdir ${D}${libdir}/go/src/

meta/recipes-devtools/go/go-runtime.inc +1 -0
+		cp --preserve=mode,timestamps -R $srcdir

${D}${libdir}/go/src/

meta/recipes-devtools/go/go-runtime.inc +1 -0
 	done
+	rm -f ${D}${libdir}/go/src/cmd/dist/dist
 }
 
 # Remove test binaries that cannot be relocated
Signature · 1 line
2.7.4
#3 lore raw
In reply to Wold, Saul
Quoted 12 lines · Saul
Quoted 11 lines · Matt Madison

When building for a target whose architecture matches the build host's, the second pass through make.bash to build the shareable runtime would also overwrite the target's static cgo library with host-compatibile binaries.

Fix this by running the host-side build once and target-only passes of make.bash twice, for static and shareable. This ensures that what gets installed is target-compatible.

Quoted 8 lines
Quoted 2 lines

[YOCTO #12136]

This does not appear to actually fix the bug mentioned here, I just found the failure again with intel-corei7-64 (from meta-intel) and then confirmed that it fails with qemux86-64 and genericx86-64 when using TCLIBC = "musl"

Can you please verify and test with MUSL.

Hmm. I had tested with MUSL before sending that patch, but I'll try it again to see what I might have missed.

-Matt

Quoted 50 lines

Thanks
Sau!

Quoted 45 lines
---
 meta/recipes-devtools/go/go-runtime.inc | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
meta/recipes- renamed from meta/recipes-devtools/go/go-runtime.inc +0 -0

devtools/go/go-runtime.inc
index 934d1aa..bd26e2e 100644

meta/recipes-devtools/go/go-runtime.inc +4 -2
@@ -23,9 +23,13 @@ do_compile() {
      rm -rf ${GOBIN} ${B}/pkg
      mkdir ${GOBIN}
      cd src
-     GO_FLAGS="" ./make.bash
+     ./make.bash --host-only
+     cp ${B}/pkg/tool/${BUILD_GOTUPLE}/go_bootstrap ${B}
+     rm -rf ${B}/pkg/${TARGET_GOTUPLE}
+     ./make.bash --target-only
      if [ -n "${GO_DYNLINK}" ]; then
-             GO_FLAGS="-buildmode=shared" GO_LDFLAGS="-extldflags

\"${LDFLAGS}\"" ./make.bash

meta/recipes-devtools/go/go-runtime.inc +2 -0
+             cp ${B}/go_bootstrap ${B}/pkg/tool/${BUILD_GOTUPLE}
+             GO_FLAGS="-buildmode=shared" GO_LDFLAGS="-extldflags

\"${LDFLAGS}\"" ./make.bash --target-only

      fi
      cd ${B}

}

meta/recipes-devtools/go/go-runtime.inc +0 -0
@@ -41,8 +45,9 @@ do_install() {
      rm -rf ${D}${libdir}/go/pkg/obj
      rm -rf ${D}${libdir}/go/pkg/bootstrap
      find src -mindepth 1 -maxdepth 1 -type d | while read

srcdir; do
- [ "$srcdir" = "./cmd" ] || cp --
preserve=mode,timestamps -R $srcdir ${D}${libdir}/go/src/
+ cp --preserve=mode,timestamps -R $srcdir
${D}${libdir}/go/src/
done
+ rm -f ${D}${libdir}/go/src/cmd/dist/dist
}

# Remove test binaries that cannot be relocated
--
2.7.4