package/go: fix cgo linking with uClibc linuxthreads
PATCH 1/1 package/go: fix cgo linking with uClibc linuxthreads
Since Go 1.21, the cgo runtime gets the stack bounds of the current thread with pthread_getattr_np() whenever __GLIBC__ is defined, which is also the case with uClibc-ng. However, uClibc-ng only implements pthread_getattr_np() with NPTL, not with linuxthreads (its declaration is under "#if 0 /* Not yet implemented in uClibc! */"), so building any cgo package fails with BR2_PTHREADS:
pthread_unix.c: In function 'x_cgo_getstackbound':
pthread_unix.c:96:9: error: implicit declaration of function 'pthread_getattr_np'; did you mean 'pthread_attr_init'? [-Werror=implicit-function-declaration]
Make BR2_PACKAGE_HOST_GO_TARGET_CGO_LINKING_SUPPORTS depend on BR2_TOOLCHAIN_HAS_THREADS_NPTL instead of BR2_TOOLCHAIN_HAS_THREADS. glibc and musl toolchains always select BR2_TOOLCHAIN_HAS_THREADS_NPTL, so only uClibc linuxthreads toolchains are affected: Go is then built without cgo, and packages that need cgo (e.g. delve) can no longer be selected.
This issue has been present since commit 06b2e496a0c4 ("package/go:
bump to version 1.21.0"), as Go 1.21 is the first version calling pthread_getattr_np() in its cgo runtime. It therefore affects 2023.11 and later, including all the current maintenance branches.
Fixes:
https://autobuild.buildroot.org/results/4dfe6753dab5d7b016210cbc11f0e137ecba09f9
--- package/go/Config.in.host | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
package/go/Config.in.host +3 -2
@@ -33,8 +33,9 @@ config BR2_PACKAGE_HOST_GO_TARGET_CGO_LINKING_SUPPORTS depends on !BR2_mips64 && !BR2_mips64el # go uses dlfcn.h + cgo for its plugin module depends on !BR2_STATIC_LIBS - # cgo supports uses threads - depends on BR2_TOOLCHAIN_HAS_THREADS + # cgo supports uses threads, and its runtime needs + # pthread_getattr_np(), which uClibc's linuxthreads lacks + depends on BR2_TOOLCHAIN_HAS_THREADS_NPTL # CGO linking for the host. Since we use the same compiler for target # and host, if the target can't do CGO linking, then the host can't.
Signature · 6 lines
2.34.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot