Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Statically link the toolbox binary #531

Closed

Conversation

HarryMichal
Copy link
Member

The Go implementation of Toolbox uses in few places code written in C
(not directly in the Toolbox code but in some library). This causes
Toolbox to be dynamically linked to the systems C library (libc). Under
other circumstances this would not be a problem but Toolbox itself is
being used as the entry-point of toolbox containers. The most widely
used implementation of libc is glibc. Its versions seem to be
backwards-compatible but not forward-compatible, making Toolbox unusable
in older distros that ship a previous version of glibc.

One of the solutions is to statically link libc (resp. glibc) which is
what this commit does. The size of the final binary seems to not be
affected.

https://golang.org/pkg/os/user/
https://golang.org/cmd/cgo/

HarryMichal added a commit to HarryMichal/toolbox that referenced this pull request Aug 20, 2020
The Go implementation of Toolbox uses in few places code written in C
(not directly in the Toolbox code but in some library). This causes
Toolbox to be dynamically linked to the systems C library (libc). Under
other circumstances this would not be a problem but Toolbox itself is
being used as the entry-point of toolbox containers. The most widely
used implementation of libc is glibc. Its versions seem to be
backwards-compatible but not forward-compatible, making Toolbox unusable
in older distros that ship a previous version of glibc.

One of the solutions is to statically link libc (resp. glibc) which is
what this commit does. The size of the final binary seems to not be
affected.

CGO_ENABLED=0 forces the build not to use cgo making it effectively
statically linked and '-tags osusergo' forces the use of purely Go
implementation of os/user.

https://golang.org/pkg/os/user/
https://golang.org/cmd/cgo/

containers#531
@HarryMichal HarryMichal force-pushed the statically-link-toolbox branch from e4755b3 to b09fa3a Compare August 20, 2020 08:16
@softwarefactory-project-zuul
Copy link

Build failed.

The Go implementation of Toolbox uses in few places code written in C
(not directly in the Toolbox code but in some library). This causes
Toolbox to be dynamically linked to the systems C library (libc). Under
other circumstances this would not be a problem but Toolbox itself is
being used as the entry-point of toolbox containers. The most widely
used implementation of libc is glibc. Its versions seem to be
backwards-compatible but not forward-compatible, making Toolbox unusable
in older distros that ship a previous version of glibc.

One of the solutions is to statically link libc (resp. glibc) which is
what this commit does. The size of the final binary seems to not be
affected.

CGO_ENABLED=0 forces the build not to use cgo making it effectively
statically linked.

https://golang.org/pkg/os/user/
https://golang.org/cmd/cgo/

containers#531
@HarryMichal HarryMichal force-pushed the statically-link-toolbox branch from b09fa3a to 6da30b6 Compare August 20, 2020 09:58
@softwarefactory-project-zuul
Copy link

Build failed.

Copy link
Member

@debarshiray debarshiray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for coming up with a solution so fast, @HarryMichal !

What worries me is that the pure Go alternative in the os/user package doesn't have all the bells and whistles as the one using the standard C library. I am thinking of enterprise set-ups where the user and group information might not be coming from /etc/passwd and /etc/group but from some directory service.

The net package also uses the standard C library for name resolution. Disabling the C code with CGO_ENABLED=0 means that we will end up with the more limited pure Go resolver that directly uses /etc/resolv.conf instead of going through the C APIs. This won't be very future-proof because upstream systemd-resolved suggests deprecating /etc/resolv.conf as seen in the switch in Fedora.

As far as I can make out, we don't actually use the net package right now. However, since Toolbox is in the business of fetching images, it's possible that it might end up picking up a dependency further down the road.

Therefore, I am slightly leaning towards #534 at the moment, if it holds up in testing.

@debarshiray
Copy link
Member

Let's close this for the time being. However we can revisit if the approach in #534 doesn't pan out.

@debarshiray
Copy link
Member

#832 contains the discussion around static builds and disabling CGO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants