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.
This commit is contained in:
Alex Crichton
2023-04-05 10:28:18 -05:00
committed by GitHub
parent 3a92aa3d0a
commit 3275c45993

View File

@@ -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::<usize>() = libcall;
self.mmap
.as_mut_ptr()
.add(offset)
.cast::<usize>()
.write_unaligned(libcall);
}
Ok(())
}