Skip to content
11 changes: 8 additions & 3 deletions cross-checks/rust-checks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ members = [
"config-capi",
"derive-macros",
"runtime",
"rustc-plugin",
# TODO: rustc plugins are completely unsupported now,
# so replace it with another approach or fold it
# into the dynamic instrumentation wrapper. Keep the
# old code around for reference until that happens.
#"rustc-plugin",
"backends/libclevrbuf-sys",
"backends/libfakechecks-sys",
"backends/dynamic-dlsym",
Expand All @@ -14,10 +18,11 @@ default-members = [
"config",
"derive-macros",
"runtime",
"rustc-plugin",
#"rustc-plugin",
"backends/dynamic-dlsym",
"backends/zstd-logging",
]
exclude = [
"tests"
"tests",
"rustc-plugin",
]
3 changes: 1 addition & 2 deletions cross-checks/rust-checks/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ serde_yaml = "0.7"
globset = "0.4"
syn = { version = "0.11", features = ["full", "visit"], optional = true }
quote = { version = "0.3", optional = true }
failure = "0.1"
failure_derive = "0.1"
indexmap = { version = "1.0", features = ["serde-1"] }
regex = "1.1"
itertools = "0.8"
thiserror = "2"
2 changes: 1 addition & 1 deletion cross-checks/rust-checks/config/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl<K: Hash + Eq> ArgList<K> {
self.0.get(key)
}

pub fn iter<'a>(&'a self) -> impl Iterator<Item = (&K, &ArgValue<K>)> + 'a {
pub fn iter<'a>(&'a self) -> impl Iterator<Item = (&'a K, &'a ArgValue<K>)> + 'a {
self.0.iter()
}
}
16 changes: 7 additions & 9 deletions cross-checks/rust-checks/config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![cfg_attr(feature = "parse-syntax", feature(rustc_private))]
#![feature(box_patterns, is_sorted)]
#![feature(box_patterns)]

#[macro_use]
extern crate serde_derive;
Expand All @@ -9,10 +9,6 @@ extern crate serde_yaml;

extern crate globset;

extern crate failure;
#[macro_use]
extern crate failure_derive;

extern crate indexmap;

pub mod attr;
Expand All @@ -22,6 +18,7 @@ pub mod scopes;
use indexmap::IndexMap;
use itertools::Itertools;
use regex::RegexSet;
use thiserror::Error;

use std::cell::RefCell;
use std::collections::HashMap;
Expand Down Expand Up @@ -111,7 +108,7 @@ impl DefaultsConfig {
self.$field = other.$field.clone();
}
};
};
}
update_field!(disable_xchecks);
update_field!(entry);
update_field!(exit);
Expand Down Expand Up @@ -193,6 +190,7 @@ pub enum CustomHashFormat {
Extern,
}

#[allow(unused)]
#[derive(Debug)]
pub struct CustomHashFormatError(String);

Expand Down Expand Up @@ -524,10 +522,10 @@ impl Config {
}
}

#[derive(Fail, Debug)]
#[derive(Error, Debug)]
pub enum ParseError {
#[fail(display = "YAML parse error")]
YAML(#[cause] serde_yaml::Error),
#[error("YAML parse error")]
YAML(#[from] serde_yaml::Error),
}

pub fn parse_string(s: &str) -> Result<Config, ParseError> {
Expand Down
1 change: 0 additions & 1 deletion cross-checks/rust-checks/derive-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ features = ["parse-syn", "with-quote"]

[dev-dependencies]
c2rust-xcheck-runtime = { path = "../runtime", version = "0.9.0" }
c2rust-bitfields = { path = "../../../c2rust-bitfields", version = "0.3" }
2 changes: 0 additions & 2 deletions cross-checks/rust-checks/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ publish = false
[features]
xcheck-with-dlsym = []
xcheck-with-weak = []
djb2-ssse3 = ["simd"]
libc-hash = ["libc"]
fixed-length-array-hash = []

[dependencies]
simd = { version = "0.2", optional = true }
libc = { version = "0.2", optional = true, default-features = false }
18 changes: 9 additions & 9 deletions cross-checks/rust-checks/runtime/src/hash/djb2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ impl Hasher for Djb2Hasher {
self.0.into()
}

#[cfg(feature = "djb2-ssse3")]
#[cfg(target_feature = "ssse3")]
#[inline]
fn write(&mut self, bytes: &[u8]) {
use simd::u32x4;
use simd::x86::ssse3::Ssse3U32x4;
use core::simd::u32x4;

let mut u32_chunks = bytes.chunks(4);
let last_chunk = if bytes.len() % 4 != 0 {
Expand All @@ -37,14 +36,15 @@ impl Hasher for Djb2Hasher {
None
};
self.0 = u32_chunks.fold(self.0, |h, cb| {
let cvec = u32x4::new(cb[0] as u32, cb[1] as u32, cb[2] as u32, cb[3] as u32);
let cvec = u32x4::from_array([cb[0] as u32, cb[1] as u32, cb[2] as u32, cb[3] as u32]);
// The djb2 factors: powers of 33 from 33^3 to 33^0
const DJB2_FACTORS: u32x4 = u32x4::new(35937, 1089, 33, 1);
const DJB2_FACTORS: u32x4 = u32x4::from_array([35937, 1089, 33, 1]);
let cmul = cvec * DJB2_FACTORS;
let ch1 = Ssse3U32x4::hadd(cmul, cmul);
let ch2 = Ssse3U32x4::hadd(ch1, ch1);
let ch1 = unsafe { core::arch::x86_64::_mm_hadd_epi32(cmul.into(), cmul.into()) };
let ch2 = unsafe { core::arch::x86_64::_mm_hadd_epi32(ch1, ch1) };
let cval = unsafe { core::arch::x86_64::_mm_extract_epi32(ch2, 0) };
Comment on lines +43 to +45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to worry about aarch64 portability here, or is this gated to x86[_64] only at a higher level?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This specific function is gated on the djb2-ssse3 feature for SSSE3 which I assumed people wouldn't even try to enable on aarch64 (and we didn't even have that back then). I could add extra build time checks to error out on that corner case, but is it worth it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's critical, was just curious what scaffolding we had in place here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switched to a target_feature check per @kkysen 's suggestion. Doesn't that make the aarch64 check redundant?

// h = h * 33^4 + ch2[0]
h.wrapping_mul(1185921u32).wrapping_add(ch2.extract(0))
h.wrapping_mul(1185921u32).wrapping_add(cval as u32)
});
// Add in the last 1-3 bytes manually
if let Some(last_bytes) = last_chunk {
Expand All @@ -54,7 +54,7 @@ impl Hasher for Djb2Hasher {
}
}

#[cfg(not(feature = "djb2-ssse3"))]
#[cfg(not(target_feature = "ssse3"))]
#[inline]
fn write(&mut self, bytes: &[u8]) {
self.0 = bytes
Expand Down
24 changes: 13 additions & 11 deletions cross-checks/rust-checks/runtime/src/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,19 @@ fn try_pointer<'a, T: ?Sized>(p: *const T) -> Option<&'a T> {
let mut invalid: u8 = 0;
unsafe {
// Same implementation as clang-plugin/runtime/hash.c
asm!(" jmp 1f
.word 2f - 1f
.ascii \"C2RUST_INVPTR\\0\"
1: movb ($2), $0
jmp 3f
2: incb $1
3:"
: "=r" (_pv), "+r" (invalid)
: "r" (p)
: "cc"
: "volatile");
core::arch::asm!(
"jmp 1f",
".word 2f - 1f",
".asciz \"C2RUST_INVPTR\"",
"1: movb ({0}), {1}",
"jmp 3f",
"2: incb {2}",
"3:",
in(reg) p.cast::<u8>(),
out(reg_byte) _pv,
inout(reg_byte) invalid,
options(att_syntax),
);
if invalid == 0 {
Some(&*p)
} else {
Expand Down
5 changes: 1 addition & 4 deletions cross-checks/rust-checks/runtime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#![feature(never_type)]
#![feature(asm)]
#![cfg_attr(feature = "xcheck-with-dlsym", feature(const_fn))]
#![cfg_attr(feature = "xcheck-with-dlsym", feature(const_ptr_null_mut))]
#![cfg_attr(feature = "xcheck-with-dlsym", feature(libc))]
#![cfg_attr(feature = "xcheck-with-weak", feature(linkage))]
#![cfg_attr(feature = "libc-hash", feature(libc))]
#![cfg_attr(target_feature = "ssse3", feature(portable_simd))]
#![no_std]

#[cfg(feature = "djb2-ssse3")]
extern crate simd;

#[cfg(feature = "libc-hash")]
extern crate libc;

Expand Down
1 change: 0 additions & 1 deletion cross-checks/rust-checks/runtime/src/xcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ unsafe fn rb_xcheck(tag: u8, val: u64) {
// This is the only approach that requires that libclevrbuf.so is linked in
#[cfg(not(any(feature = "xcheck-with-dlsym", feature = "xcheck-with-weak")))]
extern "C" {
#[no_mangle]
fn rb_xcheck(tag: u8, val: u64);
}

Expand Down