Skip to content

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

Closed
thaJeztah wants to merge 1 commit into
docker:masterfrom
thaJeztah:fix_pkcs11_static
Closed

scripts/build/binary: disable pkcs11 on static builds with CGO_ENABLED=1#3494
thaJeztah wants to merge 1 commit into
docker:masterfrom
thaJeztah:fix_pkcs11_static

Conversation

@thaJeztah

Copy link
Copy Markdown
Member

pkcs11 cannot be compiled statically if CGO is enabled (and glibc is used)
see

c->handle = dlopen(module, RTLD_LAZY);

see #3490 (comment)

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 github@gone.nl

- 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)

@codecov-commenter

codecov-commenter commented Mar 26, 2022

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@thaJeztah
thaJeztahforce-pushed the fix_pkcs11_static branch 2 times, most recently from 11bc888 to df4531aCompareApril 1, 2022 20:31
@thaJeztahthaJeztah modified the milestones: 23.0.0, 23.0.1Feb 2, 2023
@thaJeztah

thaJeztah commented Feb 6, 2023

Copy link
Copy Markdown
MemberAuthor

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: infunction`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: infunction`_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

@thaJeztahthaJeztah modified the milestones: 23.0.1, v-nextFeb 9, 2023
@thaJeztahthaJeztah modified the milestones: 24.0.0, 25.0.0Apr 27, 2023
@thaJeztahthaJeztah modified the milestones: 25.0.0, 26.0.0Jan 19, 2024
@vvolandvvoland modified the milestones: 26.0.0, 27.0.0Mar 14, 2024
@vvolandvvoland modified the milestones: 27.0.0, v-futureJun 20, 2024
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 docker#3490 (comment)
When trying to do otherwise, warnings are printed (and shouldn't be ignored,
similar to the `osusergo` build-tag):
docker#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
docker#32 467.0 # github.com/docker/cli/cmd/docker
docker#32 467.0 /usr/bin/s390x-linux-gnu-ld: /tmp/go-link-900380651/000018.o: in function `New':
docker#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
docker#32 467.0 /usr/bin/s390x-linux-gnu-ld: /tmp/go-link-900380651/000004.o: in function `_cgo_26061493d47f_C2func_getaddrinfo':
docker#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 <github@gone.nl>
@thaJeztahthaJeztah removed this from the v-future milestone May 14, 2026
@thaJeztah
thaJeztah deleted the fix_pkcs11_static branch May 14, 2026 01:56
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@thaJeztah@codecov-commenter@vvoland