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

Compile statically linked with musl as an alternative to the non cgo version #113

Open
gmbuell opened this issue Feb 5, 2016 · 4 comments

Comments

@gmbuell
Copy link

gmbuell commented Feb 5, 2016

I would love to use this under alpine linux which does not have glibc. Unfortunately, the resolver mode does not work in the non-cgo version. Linking with musl libc should provide the needed functionality but currently a musl built version will segfault.

@hlandau
Copy link
Owner

hlandau commented Feb 6, 2016

"Currently a musl built version will segfault".

I've tried this myself and it works if built on Alpine Linux (see APKBUILD linked in README), so I assume you're talking about building using musl from another distro. Which does indeed appear to crash. But you can work around this by passing -fno-PIC or -static to the linker. Indeed Alpine's Go packaging patches Go to always pass -fno-PIC.

Currently I have this for dynamically linked builds:

CC=/usr/bin/musl-gcc go build --ldflags \
  '-linkmode external -extldflags "-fno-PIC -L /path/to/directory/containing/libcap.a/taken/from/alpine"' \
  github.com/hlandau/acme/cmd/acmetool

Replace -fno-PIC with -static for static builds. Confusingly Alpine's ldd says that the dynamically linked version is not a dynamically linked executable even though it definitely is.

Might be able to provide these binaries in the future.

@hlandau hlandau self-assigned this Feb 6, 2016
@hlandau
Copy link
Owner

hlandau commented Feb 7, 2016

I figure things should be rearranged to provide the following possibilities:

linux_amd64.tar.gz -- musl static
linux_amd64_musl.tar.gz -- musl dynamic
linux_amd64_glibc.tar.gz -- glibc dynamic
linux_amd64_nocgo.tar.gz -- nocgo
openbsd_amd64_nocgo.tar.gz -- nocgo

Probably don't want to provide all of these, that would be excessive.

@gmbuell
Copy link
Author

gmbuell commented Feb 8, 2016

I don't think there's much use in a dynamic musl build but I would certainly love a provided musl static build.

@kkofler
Copy link

kkofler commented Feb 17, 2016

You also need to link libcap statically if you want to do a true static build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants