I've been hacking on bolos-rs which is a Rust based SDK for Ledger security devices (thumbv6m-none-eabi target). Sadly there are no debug options available to me, other than seeing the app crash the device and trying to narrow down the issues by commenting out code and seeing when it crashes and when it stops crashing.
Anyway, I've had some weird crashes that I have a gut feeling is due to the ROPI relocation model. For instance, this works:
pub fn event() -> Response {
let params = [
UxType::Event as u8,
0,
];
invoke_ux(¶ms)
}
But this crashes:
pub fn event() -> Response {
invoke_ux(&[
UxType::Event as u8,
0,
])
}
And at some point, I started getting crashes that went away after #[inline(never)]
hint was added to the function above.
I know that clang ROPI support doesn't support C globals too well. But I haven't really deep-dived into the Rust compiler nor the clang codebase, but I have come to a hypothesis based on what I've observed. A hypothesis that I would like to bounce off of someone more knowledgeable regarding the inner workings of the compiler.
I'm thinking there might be some optimization somewhere in the compilation pipeline, that optimizes certain variables into globals, which end up not playing too well with ROPI relocation model. Does anyone know if such a thing exists somewhere in rustc or clang? Or maybe I'm barking up the wrong tree completely?
I haven't yet been able to make a bare-bones test case where the generated assembly could easily be analysed.