I am writing a kernel with a kernel module loader. I wish to share a crate between the kernel and kernel modules, and to make sure that bootloader can write bootinfo into the correct global variable, I have to link this crate to the kernel, and I create a symbol table by scanning the kernel file. However, the rust compiler seems to only export symbols that are used in the kernel, so some symbols required by the modules are not found. How should I solve this problem?
The main problem is that the compiler does not compile dead code, since linker arguments don't work.
If you compile your project into an object file which, then you should mark exported items like this:
#[unsafe(no_mangle)]
pub extern "C" fn foo() {}
I don't want to do this, because it requires a lot of extra-work. However, I have given up on sharing the crate between the kernel and modules. Another ideal version should be sharing global variables only. But this solution may use too much memory to store the symbols.
There is no ABI for the default of mangled. If you need fixed symbols in object file you have to specify so with an attribute.