CensoredUsername / dynasm-rs

A dynasm-like tool for rust.
https://censoredusername.github.io/dynasm-rs/language/index.html
Mozilla Public License 2.0
705 stars 52 forks source link

Handling out-of-bounds AArch64 immediates #89

Open mkeeter opened 3 months ago

mkeeter commented 3 months ago

Good morning,

I've been bitten a few times by out-of-bounds AArch64 immediates, e.g.

stp Dn, Dm, [Xa|SP], #simm

is only valid for (-512 <= #simm < 512, #simm = 8 * N)

This is nicely documented in the Instruction Reference, but it would be convenient to panic either at compile time (if #simm is a constant) or a run-time (if it's an expression).

If that sounds like a good idea, I could probably put together a PR given some rough guidance on where to start looking.

CensoredUsername commented 3 months ago

Hey! glad to hear someone else using this!

Such a check is already in place for things that can be resolved at compile time. At run-time it's a bit more complex, especially for aarch64 due to the sheer amount of immediates it uses.

It might also be a bit of a perf hit, so I'm wondering if it could be enabled conditionally. Thinking about a design for that, but I don't have immediate answers.

Either way, a good starting point would be here. This is where immediates are handled, compile-time checks are often done, and the runtime code is generated.

There's also likely a bit of run-time support necessary. There's already some precedent for that in the aarch64 module in the handling of special immediates.