cli icon indicating copy to clipboard operation
cli copied to clipboard

scripts/build/binary: disable pkcs11 on static builds with CGO_ENABLED=1

Open thaJeztah opened this issue 4 years ago • 2 comments

  • follow-up to https://github.com/docker/cli/pull/3490
  • static check is failing, similar to https://github.com/docker/docker-ce-packaging/pull/430
  • possibly can be fixed through / similar to changes in https://github.com/docker/docker-credential-helpers/pull/209

pkcs11 cannot be compiled statically if CGO is enabled (and glibc is used) see https://github.com/docker/cli/blob/3897c3fa544f1239c2bc2c3af2adcebcb3650c4d/vendor/github.com/miekg/pkcs11/pkcs11.go#L75 see https://github.com/docker/cli/pull/3490#issuecomment-1079711973

When trying to do otherwise, warnings are printed (and shouldn't be ignored, similar to the osusergo build-tag):

#32 [linux/amd64->s390x build 2/2] RUN --mount=type=bind,target=.,ro     --mount=type=cache,target=/root/.cache     --mount=from=dockercore/golang-cross:xx-sdk-extras,target=/xx-sdk,src=/xx-sdk     --mount=type=tmpfs,target=cli/winresources     xx-go --wrap &&     TARGET=/out ./scripts/build/binary &&     xx-verify $([ "static" = "static" ] && echo "--static") /out/docker
#32 467.0 # github.com/docker/cli/cmd/docker
#32 467.0 /usr/bin/s390x-linux-gnu-ld: /tmp/go-link-900380651/000018.o: in function `New':
#32 467.0 /go/src/github.com/docker/cli/vendor/github.com/miekg/pkcs11/pkcs11.go:75: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
#32 467.0 /usr/bin/s390x-linux-gnu-ld: /tmp/go-link-900380651/000004.o: in function `_cgo_26061493d47f_C2func_getaddrinfo':
#32 467.0 /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

Signed-off-by: Sebastiaan van Stijn [email protected]

- What I did

- How I did it

- How to verify it

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

thaJeztah avatar Mar 26 '22 17:03 thaJeztah

Codecov Report

Merging #3494 (df4531a) into master (984b580) will increase coverage by 0.00%. The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #3494   +/-   ##
=======================================
  Coverage   58.99%   59.00%           
=======================================
  Files         282      284    +2     
  Lines       23836    23839    +3     
=======================================
+ Hits        14062    14066    +4     
  Misses       8914     8914           
+ Partials      860      859    -1     

codecov-commenter avatar Mar 26 '22 17:03 codecov-commenter

Still need to look into this one. Reproduction steps;

docker run -it --rm golang:1.19.5-bullseye

go env CGO_ENABLED
1

git clone https://github.com/docker/cli /go/src/github.com/docker/cli
cd /go/src/github.com/docker/cli
git checkout v23.0.0
DISABLE_WARN_OUTSIDE_CONTAINER=1 make binary

Notice the warnings in the output;

./scripts/build/binary
Building static docker-linux-arm64
+ go build -o build/docker-linux-arm64 -tags  osusergo pkcs11 -ldflags  -X "github.com/docker/cli/cli/version.GitCommit=e92dd87c32" -X "github.com/docker/cli/cli/version.BuildTime=2023-02-06T10:53:47Z" -X "github.com/docker/cli/cli/version.Version=23.0.0" -extldflags -static -buildmode=pie github.com/docker/cli/cmd/docker
# github.com/docker/cli/cmd/docker
/usr/bin/ld: /tmp/go-link-1909522509/000020.o: in function `New':
/go/src/github.com/docker/cli/vendor/github.com/miekg/pkcs11/pkcs11.go:77: 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-1909522509/000004.o: in function `_cgo_2ac87069779a_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

Note that the binary is statically linked though;

ldd ./build/docker-linux-arm64
	not a dynamic executable

thaJeztah avatar Feb 06 '23 11:02 thaJeztah