when encountering memcpy, actually look for roc_memcpy

This commit is contained in:
Folkert 2022-10-26 16:37:59 +02:00
parent 5311d9a02b
commit 7c91aa79c9
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C

View file

@ -1065,11 +1065,9 @@ impl AppSections {
let address = symbol.as_ref().map(|s| s.address()).unwrap_or_default(); let address = symbol.as_ref().map(|s| s.address()).unwrap_or_default();
let name = symbol.and_then(|s| s.name()).unwrap_or_default(); let name = symbol.and_then(|s| s.name()).unwrap_or_default();
let name = redirect_libc_functions(name).unwrap_or(name).to_string();
relocations relocations.entry(name).or_default().push(AppRelocation {
.entry(name.to_string())
.or_default()
.push(AppRelocation {
offset_in_section, offset_in_section,
address, address,
relocation, relocation,
@ -1415,6 +1413,16 @@ fn relocate_dummy_dll_entries(executable: &mut [u8], md: &PeMetadata) {
dir.size.set(LE, new_reloc_directory_size as u32); dir.size.set(LE, new_reloc_directory_size as u32);
} }
/// Redirect `memcpy` and similar libc functions to their roc equivalents
pub(crate) fn redirect_libc_functions(name: &str) -> Option<&str> {
match name {
"memcpy" => Some("roc_memcpy"),
"memset" => Some("roc_memset"),
"memmove" => Some("roc_memmove"),
_ => None,
}
}
#[cfg(test)] #[cfg(test)]
mod test { mod test {
const PE_DYNHOST: &[u8] = include_bytes!("../dynhost_benchmarks_windows.exe") as &[_]; const PE_DYNHOST: &[u8] = include_bytes!("../dynhost_benchmarks_windows.exe") as &[_];