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

WIP: use static linking with cgo #1218

Closed
wants to merge 1 commit into from

Conversation

jpeeler
Copy link

@jpeeler jpeeler commented Jan 9, 2020

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:

CGO_ENABLED=1  go build -mod=vendor -ldflags "-linkmode external -extldflags '-Wl,-Bstatic -lpthread -lc -static' -X github.com/operator-framework/operator-lifecycle-manager/pkg/version.GitCommit=04b659c6850eb87eab461213e77a94079ea42114 -X github.com/operator-framework/operator-lifecycle-manager/pkg/version.OLMVersion=`cat OLM_VERSION`" -o bin/catalog github.com/operator-framework/operator-lifecycle-manager/cmd/catalog
# github.com/operator-framework/operator-lifecycle-manager/cmd/catalog
/usr/bin/ld: /tmp/go-link-274462539/000019.o: in function `mygetgrouplist':
/workdir/go/src/os/user/getgrouplist_unix.go:16: warning: Using 'getgrouplist' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-274462539/000018.o: in function `mygetgrgid_r':
/workdir/go/src/os/user/cgo_lookup_unix.go:38: warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-274462539/000018.o: in function `mygetgrnam_r':
/workdir/go/src/os/user/cgo_lookup_unix.go:43: warning: Using 'getgrnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-274462539/000018.o: in function `mygetpwnam_r':
/workdir/go/src/os/user/cgo_lookup_unix.go:33: warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-274462539/000018.o: in function `mygetpwuid_r':
/workdir/go/src/os/user/cgo_lookup_unix.go:28: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-274462539/000004.o: in function `_cgo_26061493d47f_C2func_getaddrinfo':
/tmp/go-build/cgo-gcc-prolog:58: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
CGO_ENABLED=1  go build -mod=vendor -ldflags "-linkmode external -extldflags '-Wl,-Bstatic -lpthread -lc -static' -X github.com/operator-framework/operator-lifecycle-manager/pkg/version.GitCommit=04b659c6850eb87eab461213e77a94079ea42114 -X github.com/operator-framework/operator-lifecycle-manager/pkg/version.OLMVersion=`cat OLM_VERSION`" -o bin/olm github.com/operator-framework/operator-lifecycle-manager/cmd/olm
# github.com/operator-framework/operator-lifecycle-manager/cmd/olm
/usr/bin/ld: /tmp/go-link-425091651/000007.o: in function `mygetgrouplist':
/workdir/go/src/os/user/getgrouplist_unix.go:16: warning: Using 'getgrouplist' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-425091651/000006.o: in function `mygetgrgid_r':
/workdir/go/src/os/user/cgo_lookup_unix.go:38: warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-425091651/000006.o: in function `mygetgrnam_r':
/workdir/go/src/os/user/cgo_lookup_unix.go:43: warning: Using 'getgrnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-425091651/000006.o: in function `mygetpwnam_r':
/workdir/go/src/os/user/cgo_lookup_unix.go:33: warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-425091651/000006.o: in function `mygetpwuid_r':
/workdir/go/src/os/user/cgo_lookup_unix.go:28: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-425091651/000004.o: in function `_cgo_26061493d47f_C2func_getaddrinfo':
/tmp/go-build/cgo-gcc-prolog:58: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
CGO_ENABLED=1  go build -mod=vendor -ldflags "-linkmode external -extldflags '-Wl,-Bstatic -lpthread -lc -static' -X github.com/operator-framework/operator-lifecycle-manager/pkg/version.GitCommit=04b659c6850eb87eab461213e77a94079ea42114 -X github.com/operator-framework/operator-lifecycle-manager/pkg/version.OLMVersion=`cat OLM_VERSION`" -o bin/package-server github.com/operator-framework/operator-lifecycle-manager/cmd/package-server
# github.com/operator-framework/operator-lifecycle-manager/cmd/package-server
/usr/bin/ld: /tmp/go-link-877205879/000007.o: in function `mygetgrouplist':
/workdir/go/src/os/user/getgrouplist_unix.go:16: warning: Using 'getgrouplist' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-877205879/000006.o: in function `mygetgrgid_r':
/workdir/go/src/os/user/cgo_lookup_unix.go:38: warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-877205879/000006.o: in function `mygetgrnam_r':
/workdir/go/src/os/user/cgo_lookup_unix.go:43: warning: Using 'getgrnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-877205879/000006.o: in function `mygetpwnam_r':
/workdir/go/src/os/user/cgo_lookup_unix.go:33: warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-877205879/000006.o: in function `mygetpwuid_r':
/workdir/go/src/os/user/cgo_lookup_unix.go:28: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-877205879/000004.o: in function `_cgo_26061493d47f_C2func_getaddrinfo':
/tmp/go-build/cgo-gcc-prolog:58: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

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.
@openshift-ci-robot openshift-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 9, 2020
@openshift-ci-robot
Copy link
Collaborator

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 9, 2020
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`"
Copy link
Author

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
Copy link
Author

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.

@openshift-ci-robot
Copy link
Collaborator

@jpeeler: The following tests failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
ci/prow/e2e-aws-olm 1d84ff9 link /test e2e-aws-olm
ci/prow/e2e-gcp 1d84ff9 link /test e2e-gcp

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.

@jpeeler
Copy link
Author

jpeeler commented Jan 14, 2020

#1219 is a better way forward.

@jpeeler jpeeler closed this Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants