3 ms·
A module system is always worth it because every program needs to use library functions. Even if you think you don't, LLVM will generate calls to library functi
by pcwalton 11y ago
A module system is always worth it because every program needs to use library functions. Even if you think you don't, LLVM will generate calls to library functions for ordinary code; for example, if you move structures around on the stack, LLVM might just decide to call memcpy(), even if you didn't ever import string.h. (Checking your code after the fact to verify there are no library calls doesn't get around this because a new version of the compiler might add a library call where there wasn't one before.) Now you want some mechanism to isolate your code's names from the library's names. That's a module system.
- nitrogen 11y agoDoes bare metal Rust also use memcpy() or other library functions? If so, how are those linked into the final binary?
- steveklabnik 11y agoYes, LLVM will assume three or four functions exist regardless. The rlibc crate provides a Rust implementation of them, so you just add it and you're done. https://github.com/alexcrichton/rlibc https://github.com/alexcrichton/rlibc
- kzrdude 11y agoThey are usually provided by libc, but if you do low level stuff they are provided by other means.