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

Disable cgo explicitly #2069

Merged
merged 1 commit into from
Sep 21, 2023
Merged

Conversation

mauriciovasquezbernal
Copy link
Member

According to the documentation [0]: "The cgo tool is enabled by default for native builds on systems where it is expected to work", hence we need to set CGO_ENABLED=0 to explicitly disable it.

It was causing a lot of warnings in make kubectl-gadget on my system:

$ make kubectl-gadget
export GO111MODULE=on && \
export GOOS=linux GOARCH=amd64 && \
go build -ldflags "-X main.version=`git describe --tags --always`-dirty -X main.gadgetimage=ghcr.io/inspektor-gadget/inspektor-gadget:latest -extldflags '-static'" \
	-tags withoutebpf \
	-o kubectl-gadget-${GOOS}-${GOARCH} \
	github.com/inspektor-gadget/inspektor-gadget/cmd/kubectl-gadget
/usr/bin/ld: /tmp/go-link-2694774814/000027.o: in function `pluginOpen':
/_/plugin/plugin_dlopen.go:19: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-2694774814/000008.o: in function `mygetgrouplist':
/_/os/user/getgrouplist_unix.go:15: 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-2694774814/000007.o: in function `mygetgrgid_r':
/_/os/user/cgo_lookup_cgo.go:45: 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-2694774814/000007.o: in function `mygetgrnam_r':
/_/os/user/cgo_lookup_cgo.go:54: 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-2694774814/000007.o: in function `mygetpwnam_r':
/_/os/user/cgo_lookup_cgo.go:36: 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-2694774814/000007.o: in function `mygetpwuid_r':
/_/os/user/cgo_lookup_cgo.go:27: 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-2694774814/000004.o: in function `_cgo_cbcce81e6342_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
cp kubectl-gadget-linux-amd64 kubectl-gadget

According to the documentation [0]: "The cgo tool is enabled by default
for native builds on systems where it is expected to work", hence we
need to set CGO_ENABLED=0 to explicitly disable it.

It was causing a lot of warnings in make kubectl-gadget on my system:

```
$ make kubectl-gadget
export GO111MODULE=on && \
export GOOS=linux GOARCH=amd64 && \
go build -ldflags "-X main.version=`git describe --tags --always`-dirty -X main.gadgetimage=ghcr.io/inspektor-gadget/inspektor-gadget:latest -extldflags '-static'" \
	-tags withoutebpf \
	-o kubectl-gadget-${GOOS}-${GOARCH} \
	github.com/inspektor-gadget/inspektor-gadget/cmd/kubectl-gadget
/usr/bin/ld: /tmp/go-link-2694774814/000027.o: in function `pluginOpen':
/_/plugin/plugin_dlopen.go:19: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: /tmp/go-link-2694774814/000008.o: in function `mygetgrouplist':
/_/os/user/getgrouplist_unix.go:15: 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-2694774814/000007.o: in function `mygetgrgid_r':
/_/os/user/cgo_lookup_cgo.go:45: 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-2694774814/000007.o: in function `mygetgrnam_r':
/_/os/user/cgo_lookup_cgo.go:54: 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-2694774814/000007.o: in function `mygetpwnam_r':
/_/os/user/cgo_lookup_cgo.go:36: 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-2694774814/000007.o: in function `mygetpwuid_r':
/_/os/user/cgo_lookup_cgo.go:27: 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-2694774814/000004.o: in function `_cgo_cbcce81e6342_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
cp kubectl-gadget-linux-amd64 kubectl-gadget
```

[0]: https://pkg.go.dev/cmd/cgo

Fixes: 2ecc9fa ("Removing libseccomp installations and CGO usage")

Signed-off-by: Mauricio Vásquez <mauriciov@microsoft.com>
@mauriciovasquezbernal mauriciovasquezbernal merged commit a6f003e into main Sep 21, 2023
49 checks passed
@mauriciovasquezbernal mauriciovasquezbernal deleted the mauricio/disable-cgo-explicitely branch September 21, 2023 16:43
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.

None yet

2 participants