rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
99.05k stars 12.8k forks source link

`-Crelocation-model=rwpi` (and possibly others) are unsound due to affecting the ABI #131300

Open RalfJung opened 1 month ago

RalfJung commented 1 month ago

This is based on the discussion here; I don't understand much of the underlying technical details unfortunately.

It seems like setting -Crelocation-model=rwpi on an ARM target compiles code in a way that it expects a particular register to be reserved for data addressing. However, the standard library is not built with that in mind and can use the register for other purposes. That's clearly unsound, we can now get arbitrary misbehavior because the same register is used in conflicting ways.

thejpster commented 1 month ago

Compiling code with RWPI currently produces a linker error. See https://github.com/thejpster/relocatable-experiments

I was told by Arm they will send a fix to LLVM for this but it might not make the next release.

thejpster commented 1 month ago

And in case anyone was wondering, they're apparently pronounced "ropey" and "rupee".

thejpster commented 1 month ago

Also, AFAIK the RWPI issue still blocks TockOS from being able to execute applications written in Rust, because the run-time RW address isn’t known at compile time.

https://tockos.org/blog/2017/talking-tock-17/

https://github.com/tock/libtock-rs/issues/28

https://github.com/rust-lang/rust/issues/54431

You can see it’s been known about for a very long time and no-one has fixed LLVM yet. Well I think Arm fixed their copy of LLVM but they only use it with clang and they only support C code.

apiraino commented 1 month ago

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium