9 ms·
How does Rust handle multiple object files and dynamic linking? It seems to me that pretty much all of these guarantees break down if the compiler can't see the
by wfunction 12y ago
How does Rust handle multiple object files and dynamic linking? It seems to me that pretty much all of these guarantees break down if the compiler can't see the source code for the whole program at once.
- adrusi 12y agoAll the information needed to make these guarantees is the type information of all visible items in a translation unit ("crate").
- wfunction 12y agoI'm skeptical. Did they really make the type information stored in the ABI that advanced? Storing that kind of information outside of name mangling is a nontrivial feat (i.e. they'd need to rewrite the linker) and there's not a whole lot of information you can pack into name mangling.
- wtetzner 12y agoI believe it's stored as the value of a special symbol in the object. I'm pretty sure I read about it somewhere, but I can't find the link now. Does anyone know where to read about how Rust handles this?
- tomjakubowski 12y agoThey aren't stored in the mangled names. Types and other metadata on items are encoded into a special metadata file that lives in the archive.
- adrusi 12y agoIt basically generates a header file from the source code and then stores it alongside the object data containing the type information of all public items.
- wfunction 12y agoSo there's no run-time dynamic linking? Or is it possible, but only with additional metadata files present? Or maybe the assumptions are statically verified according to the interface and it is assumed that they are never broken by clients?
- thwest 12y agoLike C++ interfaces that contain std::unique_ptr, you can encode Rust types in your mangled names during linking.