-
Notifications
You must be signed in to change notification settings - Fork 544
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
WIP: use static linking with cgo #1218
Conversation
This is really to just serve as discussion. As far as I can tell, statically linking to glibc is at best fragile and not supported well.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jpeeler The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
build-linux: clean $(CMDS) | ||
|
||
build-wait: clean bin/wait | ||
|
||
bin/wait: | ||
CGO_ENABLED=1 CGO_DEBUG=1 GOOS=linux GOARCH=386 go build -o $@ $(PKG)/test/e2e/wait | ||
|
||
$(CMDS): version_flags=-ldflags "-X $(PKG)/pkg/version.GitCommit=$(GIT_COMMIT) -X $(PKG)/pkg/version.OLMVersion=`cat OLM_VERSION`" | ||
$(CMDS): version_flags=-ldflags "-linkmode external -extldflags '-Wl,-Bstatic -lpthread -lc -static' -X $(PKG)/pkg/version.GitCommit=$(GIT_COMMIT) -X $(PKG)/pkg/version.OLMVersion=`cat OLM_VERSION`" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these flags are related to using gcc as the linker (which I bet nobody wants as a build dependency)
@@ -67,17 +67,17 @@ build-coverage: build_cmd=test -c -covermode=count -coverpkg ./pkg/controller/.. | |||
build-coverage: clean $(CMDS) | |||
|
|||
build-linux: build_cmd=build | |||
build-linux: arch_flags=GOOS=linux GOARCH=386 | |||
build-linux: arch_flags=GOOS=linux # GOARCH=386 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was done only because I don't have 32 bit libraries on my system to link to (I think). In theory could be made to work though.
@jpeeler: The following tests failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
#1219 is a better way forward. |
This is really to just serve as discussion. As far as I can tell, statically linking to glibc is at best fragile and not supported well.
With the recent change to turn on cgo, binaries started being linked dynamically instead of statically as before. This might not be a problem when using a glibc based container, but obviously increases compatibility concerns. However, in our alpine local test images, the binaries no longer run since it is musl based.
This PR enables static linking and works in alpine, but I don't think it's a good solution. Here's the build output with warnings: