afonso360 opened PR #4782 from interp-libcalls
to main
:
:wave: Hey,
This does not fix any of the issues reported by the fuzzer so far, but I think that is just a coincidence, since at some point it will generate a libcall and we cannot handle those either.
This allows the interpreter to register libcall handlers and invoke them when called.
I switched the fuzzer generated libcall from Udiv to Ishl, reason being that we don't want libcalls that can trap. Both functions have identical signatures so we shouldn't have any input format changes to the fuzzer.
afonso360 updated PR #4782 from interp-libcalls
to main
.
afonso360 submitted PR review.
afonso360 created PR review comment:
I saw some sources online that point to this being the correct behaviour, but nothing definitive. Does anyone know if this is correct?
afonso360 updated PR #4782 from interp-libcalls
to main
.
afonso360 deleted PR review comment.
afonso360 created PR review comment:
I saw some sources online that point to this being the correct behaviour, but nothing definitive. Does anyone know if this is correct?
afonso360 submitted PR review.
afonso360 edited PR review comment.
afonso360 edited PR #4782 from interp-libcalls
to main
:
:wave: Hey,
This does not fix any of the issues reported by the fuzzer so far, but I think that is just a coincidence, since at some point it will generate a libcall and we cannot handle those either.
Edit: Actually this may have already been reported, but have returned the same error as #4758 so it wasn't reported separately.
This allows the interpreter to register libcall handlers and invoke them when called.
I switched the fuzzer generated libcall from Udiv to Ishl, reason being that we don't want libcalls that can trap. Both functions have identical signatures so we shouldn't have any input format changes to the fuzzer.
afonso360 created PR review comment:
I think it might also be a good idea to return
Result<SmallVec<[V; 1]>, TrapCode>
and allow these to trap controllably.
afonso360 submitted PR review.
afonso360 edited PR review comment.
afonso360 edited PR review comment.
afonso360 submitted PR review.
afonso360 created PR review comment:
I think this is undefined behaviour, so I've added trap codes to the libcall handlers and reverted back to div
afonso360 updated PR #4782 from interp-libcalls
to main
.
afonso360 updated PR #4782 from interp-libcalls
to main
.
afonso360 updated PR #4782 from interp-libcalls
to main
.
jameysharp submitted PR review.
jameysharp created PR review comment:
I'm not sure I understand. We've recently defined shifts to be computed modulo the bit width. So I think
Ishl64
is a fine choice, but it should evaluate toa << (b % 64)
for all values ofb
. That in turn means that we don't need to check the preconditions on Rust's implementation of left-shift: it would panic in debug builds if the shift amount is 64 or higher, but we'll never hit that case.
afonso360 submitted PR review.
afonso360 created PR review comment:
These libcalls end up being linked to the platform's runtime library if the interpreted version succeeds, so we need to make sure that they match the behaviour agreed by the runtime libraries and not our own.
We also can't really panic here since it would cause a fuzz error.
afonso360 submitted PR review.
afonso360 created PR review comment:
Another option would be to define our own symbol for the JIT as well, and then we control both sides, the interpreted version and the compiled version.
afonso360 edited PR review comment.
afonso360 updated PR #4782 from interp-libcalls
to main
.
afonso360 updated PR #4782 from interp-libcalls
to main
.
jameysharp submitted PR review.
jameysharp submitted PR review.
jameysharp created PR review comment:
Since this
SmallVec
type ends up appearing in other modules, I'd suggest introducing a type alias for it. That way it's easy later either to change it to a regularVec
, or to put more elements in the inline array.Also,
&dyn Fn
is probably more general than necessary. A closure that doesn't capture anything from its environment is compatible with afn
type, and I'd be surprised if interpreter libcall handlers ever needed context.pub type LibCallValues<V> = SmallVec<[V; 1]>; pub type LibCallHandler<V> = fn(LibCall, LibCallValues<V>) -> Result<LibCallValues<V>, TrapCode>;
jameysharp created PR review comment:
What do you think of defining this function in
function_generator.rs
next to the array of allowed libcalls?
afonso360 created PR review comment:
The only reason I'm hesitant to do this is that
fuzzgen
is supposed to be executor agnostic (i.e. icache needs none of this), so it feels kinda weird to have a interpreter specific function there.
afonso360 submitted PR review.
afonso360 updated PR #4782 from interp-libcalls
to main
.
afonso360 has marked PR #4782 as ready for review.
jameysharp submitted PR review.
jameysharp created PR review comment:
Ah, that makes sense. But this is weird for the same reason that the function references are: only outer fuzz target knows which functions and which libcalls are okay to call. So I think the set of allowed libcalls (and functions) should be provided by the fuzz target. But I also don't think that needs to block merging this PR, it's just something I think we should revisit soon.
afonso360 submitted PR review.
afonso360 created PR review comment:
So I think the set of allowed libcalls (and functions) should be provided by the fuzz target.
I like that!
But I also don't think that needs to block merging this PR, it's just something I think we should revisit soon.
:+1:
jameysharp merged PR #4782.
Last updated: Nov 22 2024 at 16:03 UTC