Debugging Rustler on Illumos
8 days ago
- #illumos
- #DTrace
- #Rustler
- The author shares their journey of debugging Rustler on OmniOS, starting from their decision to use illumos over Linux for a personal project.
- They describe the setup involving Elixir, Rust NIFs (Native Implemented Functions), and the Rustler project for integrating Rust with Erlang/Elixir.
- Initial migration to illumos was smooth, but issues arose with NIFs not loading properly, prompting a deep dive into DTrace for debugging.
- The debugging process involved tracing system calls and understanding how Erlang loads NIFs, revealing that the NIF shared library was being opened but functions weren't being registered.
- Investigation into Rustler's internals showed it uses the Inventory crate for plugin registration, which relies on `.init_array` sections in ELF files for initialization.
- On illumos, the runtime linker wasn't processing the `.init_array` sections correctly due to duplicate sections created by Rust's `#[used]` attribute.
- A manual fix was applied by editing the ELF file to correct the `.init_array` section references, which resolved the issue.
- Further testing revealed that the `#[used]` attribute with `linker` argument was the culprit, leading to duplicate `.init_array` sections.
- The author concludes with insights into the problem's root cause and references related LLVM patches and discussions.