4 ms·
> Right now, we depend on glibc, and it cannot be statically linked. Could you expand on this? Why can it not be statically linked?
by xyzzy_plugh 12y ago
> Right now, we depend on glibc, and it cannot be statically linked.
Could you expand on this? Why can it not be statically linked?
- spystath 12y agoName resolution libraries are loaded dynamically [1,2], so glibc can't be linked statically if you want NSS to work. I gather there might be a way to explicitly link to a specific resolution library but this is practically unsupported/poorly documented. [1]: https://sourceware.org/glibc/wiki/FAQ#Even_statically_linked_programs_need_some_shared_libraries_which_is_not_acceptable_for_me.__What_can_I_do.3F https://sourceware.org/glibc/wiki/FAQ#Even_statically_linked... [2]: http://stackoverflow.com/questions/3430400/linux-static-linking-is-dead http://stackoverflow.com/questions/3430400/linux-static-link...
- xyzzy_plugh 12y agoI understand this limitation. I can currently get around this by using --enable-static-nss. Does rust currently expose any way to do this? Could I perform linking myself as a workaround?
- steveklabnik 12y ago> Could I perform linking myself as a workaround? You can but it requires lots of black magic, and certainly a nightly rather than beta Rust ;) http://mainisusuallyafunction.blogspot.com/2015/01/151-byte-static-linux-binary-in-rust.html http://mainisusuallyafunction.blogspot.com/2015/01/151-byte-... is an old blog post that can get you started.
- xyzzy_plugh 12y agoWonderful -- thanks Steve! Best of luck on the upcoming release.
- hendzen 12y agoIf you statically link libc, and then another library you use (potentially transitively) dlopen(3)s a library, you are going to have a bad time.
- xyzzy_plugh 12y agoOf course, but that doesn't mean we shouldn't have the option, right?
- steveklabnik 12y agoIt's generally considered a poor idea to statically link glibc, but if you don't rely on certain features, you can do it. For example, NSS won't work unless you add a bunch of flags for other libraries you specifically use, see https://sourceware.org/glibc/wiki/FAQ#Even_statically_linked_programs_need_some_shared_libraries_which_is_not_acceptable_for_me.__What_can_I_do.3F https://sourceware.org/glibc/wiki/FAQ#Even_statically_linked... Most people who focus on 100% statically linking just use a different libc. For example, Stali Linux, [1] has this to say: http://sta.li/faq http://sta.li/faq > it [is] nearly impossible to use glibc for static linking in non-trivial programs. That said, if you want to give it a shot, it's technically possible, though we don't expose it for Rust yet, due to these kinds of landmines. 1: which got linked here a few times, most recently https://news.ycombinator.com/item?id=7261559 https://news.ycombinator.com/item?id=7261559
- xyzzy_plugh 12y agoI'm looking forward to using rust in a constrained embedded environment where I control 100% of the software. I don't have to worry about such problems.
- steveklabnik 12y agoAwesome, then yes, you have several advantages here :) You'll be using nightly Rust for a while, as several features that target this use case are still unstable, like inline assembly. But it's a use case we do care a lot about.
- nightpool 12y agoMost of the people I've seen targeting this use case stub out their own stdlib, although that obviously gets cumbersome the more stuff you want to do.