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

Golang packages are dynamically linked #9

Open
utrack opened this issue Jul 31, 2015 · 2 comments
Open

Golang packages are dynamically linked #9

utrack opened this issue Jul 31, 2015 · 2 comments

Comments

@utrack
Copy link

utrack commented Jul 31, 2015

Because of root Docker's golang image, static builds are not available.

Dynamically linked gotools from Docker's golang image are unable to produce static builds.
Example ldd output from freshly created binary:

oldie% ldd bin/server
        linux-vdso.so.1 (0x00007ffc0f4f9000)
        libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f10b9e54000)
        libc.so.6 => /usr/lib/libc.so.6 (0x00007f10b9ab2000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f10ba071000)
@bdehamer
Copy link
Collaborator

Not sure what might be going on here, we don't seem to have any problems creating statically linked binaries. Compare this:

bdehamer:watchtower $ go build
bdehamer:watchtower $ ldd watchtower 
        linux-vdso.so.1 =>  (0x00007fff325ce000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fcfad358000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fcfacf93000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fcfad57f000)

with this:

bdehamer:watchtower $ docker run --rm -v $(pwd):/src centurylink/golang-builder
Building github.com/CenturyLinkLabs/watchtower
bdehamer:watchtower $ ldd watchtower 
        not a dynamic executable

@utrack
Copy link
Author

utrack commented Aug 1, 2015

@bdehamer I read some stuff on the matter... It looks like dynamic builds are produced when the binary uses net package or something from os.
http://grokbase.com/t/gg/golang-nuts/137jbj44wt/go-nuts-re-go-program-isnt-compiled-to-static-binary-if-uses-net-package
Build fails if I pass -d ldflag (which discards dynamic links). I guess I'll just fork golang container and build go tools in it statically for now.

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