by fwsgonzo · 6y ago · 0 comments
For rust I had to add some custom linker flags, use global_asm for the startup code, and then with no_std I could just call my own main function. The only really annoying part of the whole thing is that there is no feature in Rust to force a function to not be removed. I could override the global allocator to make allocations very fast.
For C/C++, it's the same as in Rust, except you can use __attribute__((used)) to make a function not get removed. It's also easy to override memory- and string-functions if you have system calls that do these things faster. Overall the C/C++ environment was the fastest.
For Nim, I only had to use C++ as a backend, and then call NimMain(), add a few extra flags, and it would just work. I only wish that Nim was more popular.
comptime{
asm("nop"); //Your asm here
}
Calling Main From an arbitrary point: const root = @import("root");
//....
root.main();Can we use `pub` to make it public and not to be removed ?
The only thing that worked was adding a linker argumment: "-C", "link_args=--undefined=<name_of_function>"
That will force the linker to assume it's referenced.
There's also an `#[used]`[1] attribute, but only for static items. If your use case is special, consider open a feature request in Rust repo.
[1]: https://doc.rust-lang.org/nightly/reference/abi.html#the-use...