Skip to contentSkip to conversation

package/go: cgo linking on riscv64 needs the lp64d ABI

PATCH New Yegor Yefremov via buildroot 1 participant 1 message Nov 17

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/go: cgo linking on riscv64 needs the lp64d ABI

Building balena-engine for riscv64 with the lp64 ABI fails at link time:

ld: /tmp/go-link-3269995158/go.o: can't link double-float modules with soft-float modules
ld: failed to merge target specific data of file /tmp/go-link-3269995158/go.o

The same happens with lp64f ("can't link double-float modules with single-float modules").

The Go linker always marks riscv64 objects as using the lp64d ABI (ehdr.Flags = 0x4 in cmd/link/internal/ld/elf.go). Packages with cgo code are linked externally, so the C toolchain must use the same ABI. Programs without C code are linked internally by Go and are not affected.

Make BR2_PACKAGE_HOST_GO_TARGET_CGO_LINKING_SUPPORTS depend on BR2_RISCV_ABI_LP64D on riscv. Packages that need cgo can then no longer be selected with the lp64 or lp64f ABIs, and the remaining Go packages are built with CGO_ENABLED=0.

This issue has been present since commit 8a1158f89f15 ("package/go:
add support for riscv64 architecture"), which enabled Go for riscv64 without restricting cgo to the lp64d ABI. It therefore affects 2022.05 and later, including all maintained branches.

Fixes:
https://autobuild.buildroot.org/results/4c70d9294c31ba4d0bcc84829f8ff7294e03e3dc

Fixes 8a1158f89f15fbb7448f39a118e4882bd1b44c81 ("package/go: add support for riscv64 architecture")
Assisted-by Claude:claude-opus-5-5
---
 package/go/Config.in.host | 3 +++
 1 file changed, 3 insertions(+)
package/go/Config.in.host +3 -0
index 47c7e5d075..875eecab85 100644
@@ -31,6 +31,9 @@ config BR2_PACKAGE_HOST_GO_TARGET_CGO_LINKING_SUPPORTS
 	# Go doesn't support CGO linking on MIPS64x platforms
 	# See: https://github.com/karalabe/xgo/issues/46
 	depends on !BR2_mips64 && !BR2_mips64el
+	# Go objects for riscv64 always use the lp64d ABI, which can't
+	# be linked with objects using another floating-point ABI
+	depends on !BR2_riscv || BR2_RISCV_ABI_LP64D
 	# go uses dlfcn.h + cgo for its plugin module
 	depends on !BR2_STATIC_LIBS
 	# cgo supports uses threads
Signature · 6 lines
2.34.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot