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

statically link everything but libc #3392

Closed
tamird opened this issue Dec 10, 2015 · 7 comments
Closed

statically link everything but libc #3392

tamird opened this issue Dec 10, 2015 · 7 comments

Comments

@tamird
Copy link
Contributor

tamird commented Dec 10, 2015

Right now, we are statically linking everything, including libc. This forces us to use musl, because statically linking glibc is insane.

We would like to statically link everything but libc, so that we aren't forced to use such an exotic configuration. This may require us to rethink our current collection of c-* repositories so that we can use upstream build systems to build static binaries which we link against, while letting the go tool dynamically link everything else (which we hope is just libc).

@petermattis
Copy link
Collaborator

Why do you think the c-* repositories are related to this? Those repositories result in the generation of static libs.

@tamird
Copy link
Contributor Author

tamird commented Dec 10, 2015

Not so; static libs are only created if the top level cockroach build is static.

EDIT: I only verified this with c-rocksdb, but I don't see why it would different for the other repos.

@petermattis
Copy link
Collaborator

Eh, c-rocksdb is not linked dynamically into my cockroach binaries on Mac OS X. Does this differ on Linux?

@mberhault
Copy link
Contributor

nope:

$ ldd cockroach 
    linux-vdso.so.1 =>  (0x00007fff7654d000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f3647c1d000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f36479ff000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f36476fb000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f36473f5000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f36471df000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f3646e1a000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f3647e25000)

where cockroach is from a plain make build

@tamird
Copy link
Contributor Author

tamird commented Dec 10, 2015

I guess I'm fuzzy on the semantics; I expect that libstdc++ is dynamically linked into cockroach as a result of rocksdb's inclusion (and how it was built), but perhaps that is incorrect.

@petermattis
Copy link
Collaborator

The decision to link libstdc++ statically or dynamically is made when the final cockroach binary is linked and is purely determine by the presence or absence of the -static flag being passed to the external linker (e.g. clang++ or g++). I'm about 99% certain that the c-* repositories do not affect this.

@petermattis
Copy link
Collaborator

My readings on the internet suggest that glibc = {librt,libpthread,libm,libc} and that all of those libraries should be dynamically linked. linux-vdso.so.1 (virtual dynamic shared object) comes from the kernel. And ld-linux-x86-64.so is the dynamic loader and is required by any program that is linked against shared libraries. That leaves libstdc++ and libgcc that we would like to link statically. Luckily, there is a flag for that (actually 2 flags): -static-libgcc and -static-libstdc++. I suggest we replace usage of -static with those two flags.

petermattis added a commit that referenced this issue Dec 11, 2015
ldd cockroach
    linux-vdso.so.1 (0x00007ffe34163000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f0eef3f7000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f0eef1da000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f0eeeed9000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0eeeb30000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f0eef5ff000)

Fixes #3392.
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

3 participants