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

Static builds #132

Closed
kris-watts-gravwell opened this issue Apr 28, 2023 · 1 comment
Closed

Static builds #132

kris-watts-gravwell opened this issue Apr 28, 2023 · 1 comment

Comments

@kris-watts-gravwell
Copy link

I am finding that its not possible to build static binaries with the purego linked in and CGO disabled.

Trying to use an external linker causes relocation and symbol lookup errors.

Is it possible to eliminate the linkages to libc, libpthread, libdl, etc... either through a musl CC or other techniques?

@TotallyGamerJet
Copy link
Collaborator

It is not. Purego dynamically links to dlopen and other libc functions which it uses to get access to C functions. There is no way to access those symbols unless you want to rewrite the dynamic linker in Go. However, such a feat would only be beneficial on Linux since macOS and Windows require you to use the system linker. This rewrite would be difficult and error prone which is why I did not go that route.

As for why you are getting linking errors when using an external linker with CGO_ENABLED=0. This is because the way purego links the dynamic symbols is with go:cgo_import_dynamic which only affects the internal linker. To make it work for the external linker you'd have to use cgo_import_static and an undocumented flag to build it. Using undocumented features is not user friendly. Therefore it is recommended that you enable Cgo when using an external linker and purego.

@TotallyGamerJet TotallyGamerJet closed this as not planned Won't fix, can't repro, duplicate, stale May 1, 2023
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

No branches or pull requests

2 participants