Skip to content

Commit

Permalink
build: Statically link the toolbox binary
Browse files Browse the repository at this point in the history
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/

#531
  • Loading branch information
HarryMichal committed Aug 20, 2020
1 parent ff1fab0 commit b09fa3a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/go-build-wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ if ! cd "$1"; then
exit 1
fi

go build -trimpath -ldflags "-X github.com/containers/toolbox/pkg/version.currentVersion=$3" -o "$2"
CGO_ENABLED=0 go build -tags osusergo -trimpath -ldflags "-X github.com/containers/toolbox/pkg/version.currentVersion=$3" -o "$2"
exit "$?"

0 comments on commit b09fa3a

Please sign in to comment.