3 ms·
> As for static linking being a competitive advantage of musl: I don't know where you got that idea. That's how I've been told to build fully statically linked
by gpm 7y ago
> As for static linking being a competitive advantage of musl: I don't know where you got that idea.
That's how I've been told to build fully statically linked rust binaries, I can't say I've dug into why glibc isn't used for those.
- glandium 7y agoThe usual reason is that if you want a binary that can be used "everywhere", you can't just build on your machine without more thought if you use the glibc because chances are you're going to be using symbols that aren't available in older versions of the glibc, making your binary incompatible with many (older) distros. musl is an easy way out of that. Another is to build against an old glibc.
- quotemstr 7y agoThe right way to solve this problem would be to teach the linker to link against the set of glibc symbols that existed as of a particular version number or date. Then you'd just pass a flag (along with a preprocessor macro, so the headers would know to define the right version of the linker symbols) specifying this version target when you built your program. For want of this relatively simple toolchain feature, we have people statically linking entire C libraries. It's a shame. You can do a moral version of the same thing using linker scripts, but nobody bothers with linker scripts.
- glandium 7y agoThe macOS SDK does this better. It is indeed a shame that the glibc doesn't care.
- JoshTriplett 7y agoThe primary reason is that a statically linked glibc can't use NSS (Name Service Switch) modules from a different glibc version, so if you statically link glibc you can't reliably resolve names with getaddrinfo. You can do DNS with other libraries, and many applications do anyway because they want asynchronous DNS and NSS uses static DNS, but you can't really do anything other than DNS or static hosts files. musl, on the other hand, never supports NSS, whether static or dynamic, and exclusively supports DNS. You can't resolve things like mDNS names, or even resolve localhost if on a system that doesn't hardcode it in /etc/hosts. So either way, static linking and name resolution don't mix well, and musl and non-DNS name resolution don't mix well.