From 3275c45993a3a3e9a2305795c5064c7a00db0123 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 5 Apr 2023 10:28:18 -0500 Subject: [PATCH] Use an unaligned write for resolving libcall relocations (#6147) This commit changes resolution of libcall relocations from writing a `usize` into a raw pointer to specifically performing an unaligned write. The addresses of libcalls to write to are not guaranteed to be aligned, so this could technically have caused issues on some platforms perhaps. This was discovered now that Rust nightly will panic on unaligned writes to pointers, and fuzzing ran into this case when compiled with a more recent Nightly build. --- crates/jit/src/code_memory.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/jit/src/code_memory.rs b/crates/jit/src/code_memory.rs index 128c3acec3..b2272195f9 100644 --- a/crates/jit/src/code_memory.rs +++ b/crates/jit/src/code_memory.rs @@ -299,7 +299,11 @@ impl CodeMemory { obj::LibCall::FmaF32 => libcalls::relocs::fmaf32 as usize, obj::LibCall::FmaF64 => libcalls::relocs::fmaf64 as usize, }; - *self.mmap.as_mut_ptr().add(offset).cast::() = libcall; + self.mmap + .as_mut_ptr() + .add(offset) + .cast::() + .write_unaligned(libcall); } Ok(()) }