Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] package/pkg-golang.mk: add osusergo and netgo tags in static builds
@ 2022-09-18 12:22 Arnout Vandecappelle
  2022-09-18 12:23 ` Arnout Vandecappelle
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Arnout Vandecappelle @ 2022-09-18 12:22 UTC (permalink / raw)
  To: buildroot

CGO (the Go language C bindings) normally links dynamically with the C
libraries. It seems that passing -extldflags=-static is not sufficient
to make sure they link statically. As a result, a build using CGO will
fail with

runtime.gcdata: missing Go type information for global symbol .dynsym: size 72

There are two modules in the standard Go library that can use CGO:
os/user and net. Both of these have pure Go versions, however, which can
be selected with the osusergo and netgo tags. Since these two are
standard library modules that get used in almost all Go programs, pass
those flags in the common infrastructure.

It's not entirely clear if this is always the case or only depending on
the specific way CGO is used. In the former case, we could instead
disable CGO globally if static libs are enabled. However, it turns out
that this doesn't solve the problem completely anyway (delve still fails
to link, with different errors). Also, it is possible that other cgo
modules do still work. Therefore, just stick to adding the osusergo and
netgo tags.

Fixes:
 - crucible:
   http://autobuild.buildroot.net/results/c2f/c2f29f55b461899e8e15c0494578304e6f74bf51/
 - containerd:
   http://autobuild.buildroot.net/results/699/69910fc6b9f474a7eb0ca7ffa27ac5512cc1bb37/
 - delve:
   http://autobuild.buildroot.net/results/552/55225d5da17e85271943f7adce6f07d014d9717d/
 - probably others...

Signed-off-by: Arnout Vandecappelle <arnout@mind.be>
---
 package/pkg-golang.mk | 1 +
 1 file changed, 1 insertion(+)

diff --git a/package/pkg-golang.mk b/package/pkg-golang.mk
index 0b3dc3d32f..a4fc353e78 100644
--- a/package/pkg-golang.mk
+++ b/package/pkg-golang.mk
@@ -100,6 +100,7 @@ ifeq ($(4),target)
 
 ifeq ($(BR2_STATIC_LIBS),y)
 $(2)_LDFLAGS += -extldflags '-static'
+$(2)_TAGS += osusergo netgo
 endif
 
 # Build package for target
-- 
2.37.3

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-04-23 10:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-18 12:22 [Buildroot] [PATCH] package/pkg-golang.mk: add osusergo and netgo tags in static builds Arnout Vandecappelle
2022-09-18 12:23 ` Arnout Vandecappelle
2022-11-16 12:57 ` Fabio Estevam
2023-04-16 19:59 ` Yann E. MORIN
2023-04-23 10:32 ` Peter Korsgaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox