All of 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

* Re: [Buildroot] [PATCH] package/pkg-golang.mk: add osusergo and netgo tags in static builds
  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
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Arnout Vandecappelle @ 2022-09-18 12:23 UTC (permalink / raw)
  To: buildroot



On 18/09/2022 14:22, Arnout Vandecappelle wrote:
> 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>

  I sent too fast of course, I still wanted to add a reference to this[1] 
"docuemntation" of Go and static builds.


  Regards,
  Arnout

[1] https://www.arp242.net/static-go.html


> ---
>   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
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* Re: [Buildroot] [PATCH] package/pkg-golang.mk: add osusergo and netgo tags in static builds
  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
  3 siblings, 0 replies; 5+ messages in thread
From: Fabio Estevam @ 2022-11-16 12:57 UTC (permalink / raw)
  To: Arnout Vandecappelle; +Cc: buildroot

Hi Arnout,

On Sun, Sep 18, 2022 at 9:23 AM Arnout Vandecappelle <arnout@mind.be> wrote:
>
> 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/

I am still getting reports about crucible failure.

Do you plan to apply this patch?

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

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

* Re: [Buildroot] [PATCH] package/pkg-golang.mk: add osusergo and netgo tags in static builds
  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
  3 siblings, 0 replies; 5+ messages in thread
From: Yann E. MORIN @ 2023-04-16 19:59 UTC (permalink / raw)
  To: Arnout Vandecappelle; +Cc: buildroot

Arnout, All,

On 2022-09-18 14:22 +0200, Arnout Vandecappelle spake thusly:
> 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>

Applied to master, after adding the link to the docuemntation you
pointed to in your reply (without any typo, I hope), thanks.

Regards,
Yann E. MORIN.

> ---
>  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

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* Re: [Buildroot] [PATCH] package/pkg-golang.mk: add osusergo and netgo tags in static builds
  2022-09-18 12:22 [Buildroot] [PATCH] package/pkg-golang.mk: add osusergo and netgo tags in static builds Arnout Vandecappelle
                   ` (2 preceding siblings ...)
  2023-04-16 19:59 ` Yann E. MORIN
@ 2023-04-23 10:32 ` Peter Korsgaard
  3 siblings, 0 replies; 5+ messages in thread
From: Peter Korsgaard @ 2023-04-23 10:32 UTC (permalink / raw)
  To: Arnout Vandecappelle; +Cc: buildroot

>>>>> "Arnout" == Arnout Vandecappelle <arnout@mind.be> writes:

 > 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>

Committed to 2023.02.x, thanks.

-- 
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.