-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect UB due to target feature caller/callee mismatch #3095
Comments
I have a demo of the UB. Note that it requires 2 crates (or perhaps crate+some name mangling magic) to demonstrate: https://godbolt.org/z/3j4YhnzK5 |
Can't it be done in a single crate with the per-function target_feature attribute? |
It can indeed. https://godbolt.org/z/Tj3Gj43sq I thought llvm was even weirder with function-specific |
I tried turning this into a Miri test case: use std::arch::x86_64::*;
use std::mem::transmute;
#[no_mangle]
#[target_feature(enable="avx")]
pub unsafe extern "C" fn foo(_y: f32, x: __m256) -> __m256{
x
}
pub fn bar(x: __m256) -> __m256 {
// The first and second argument get mixed up here since caller
// and callee do not have the same feature flags.
unsafe{foo(0.0,x)}
}
fn assert_eq_m256(a: __m256, b: __m256) {
unsafe {
assert_eq!(transmute::<_, [f32; 8]>(a), transmute::<_, [f32; 8]>(b))
}
}
fn main() {
let input = unsafe { _mm256_set1_ps(1.0) };
let copy = bar(input);
assert_eq_m256(input, copy);
} However, this already gets rejected:
Does that mean we are good, or are there other ways to trigger this ABI mismatch? |
You can construct it using an explicit #[target_feature] attribute, or core::mem::transmute. Also, I'd probably compare [u32;8] or [u64;4] (since f32 bit patterns can be interpreted as a NaN). |
What do you mean by constructing it with a transmute?
|
Unless the issue is |
I am completely lost. Can you show some code that somehow uses Miri dynamically considers exactly those features to be available that are enabled via |
Ok yeah, you'd need to have a way to separate statically enabled and dynamically enabled features to check this particular UB. |
Okay so I think Miri is good here for UB detection for now, but eventually it could be nice to support |
I'm mostly worried about code that will check |
Yeah, I understand. In Miri |
add test for a function ABI mismatch due to target features Cc #3095
add test for a function ABI mismatch due to target features Cc rust-lang/miri#3095
add test for a function ABI mismatch due to target features Cc rust-lang/miri#3095
@chorman0773 points out that one can cause ABI incompatibility UB by having a mismatch between the target features in the caller and callee. We should come up with a test case for this and then ensure that Miri can detect that UB.
The text was updated successfully, but these errors were encountered: