dynasm-rs icon indicating copy to clipboard operation
dynasm-rs copied to clipboard

Handling out-of-bounds AArch64 immediates

Open mkeeter opened this issue 1 year ago • 1 comments

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.

mkeeter avatar Mar 11 '24 16:03 mkeeter

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.

CensoredUsername avatar Mar 13 '24 16:03 CensoredUsername

I've got this working on dev now, just going to do a bit more test for it.

CensoredUsername avatar Oct 09 '24 01:10 CensoredUsername

Fixed in v3.0.0!

CensoredUsername avatar Oct 09 '24 22:10 CensoredUsername

Awesome, thanks!

mkeeter avatar Oct 10 '24 00:10 mkeeter