Rust on RISC-V, a case study - Jorge Prendes and James Wainwright
What makes Rust on embedded hardware exciting and challenging is that we want to realize two conflicting objectives. On the one hand, we want to use safe and convenient high-level abstractions. This is particularly true for Tock OS, an embedded OS whose security model is built around Rust’s type safety guarantees. On the other hand, we want to efficiently use the platform’s resources, particularly regarding code size and memory usage. This becomes especially challenging when we account for all of the requirements that Tock OS imposes, including supporting dynamically-loaded applications and running the OS and the applications from arbitrary positions in ROM and RAM in devices without support for virtual memory. In this case study, we discuss how lowRISC is improving Rust support for RISC-V embedded platforms, driven by Tock OS. We describe our efforts for adding support for RISC-V position-independent code optimized for embedded applications, including the changes needed in the toolchain, rustc, the ABI, Tock OS and its libraries. We also detail how we are trying to optimize the Rust abstractions used in Tock OS, including the compiler transformations involved, metrics for the binary size improvements, and the current status of those optimizations.