Revert "redirect libc functions to their roc equivalents"

This reverts commit 4a75b5ad5827999592ebc0f66debe90f09e87bf5.
This commit is contained in:
Folkert 2022-10-26 16:36:10 +02:00
parent 73796f2b05
commit 5311d9a02b
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
4 changed files with 21 additions and 23 deletions

View file

@ -20,7 +20,6 @@ use crate::metadata::{self, Metadata, VirtualOffset};
use crate::{
align_by_constraint, align_to_offset_by_constraint, load_struct_inplace,
load_struct_inplace_mut, load_structs_inplace_mut, open_mmap, open_mmap_mut,
redirect_libc_functions,
};
const MIN_SECTION_ALIGNMENT: usize = 0x40;
@ -78,8 +77,12 @@ fn collect_roc_definitions<'a>(object: &object::File<'a, &'a [u8]>) -> MutMap<St
let address = sym.address() as u64;
// special exceptions for memcpy and memset.
if let Some(name) = redirect_libc_functions(name) {
vaddresses.insert(name.to_string(), address);
if name == "roc_memcpy" {
vaddresses.insert("memcpy".to_string(), address);
} else if name == "roc_memset" {
vaddresses.insert("memset".to_string(), address);
} else if name == "roc_memmove" {
vaddresses.insert("memmove".to_string(), address);
}
vaddresses.insert(name.to_string(), address);

View file

@ -377,16 +377,6 @@ fn surgery(
}
}
/// 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,
}
}
pub(crate) fn align_by_constraint(offset: usize, constraint: usize) -> usize {
if offset % constraint == 0 {
offset

View file

@ -18,7 +18,7 @@ use target_lexicon::Triple;
use crate::{
align_by_constraint, align_to_offset_by_constraint, load_struct_inplace,
load_struct_inplace_mut, load_structs_inplace, load_structs_inplace_mut, open_mmap,
open_mmap_mut, redirect_libc_functions,
open_mmap_mut,
};
const MIN_SECTION_ALIGNMENT: usize = 0x40;
@ -70,8 +70,10 @@ fn collect_roc_definitions<'a>(object: &object::File<'a, &'a [u8]>) -> MutMap<St
let address = sym.address() as u64;
// special exceptions for memcpy and memset.
if let Some(name) = redirect_libc_functions(name) {
vaddresses.insert(name.to_string(), address);
if name == "roc_memcpy" {
vaddresses.insert("memcpy".to_string(), address);
} else if name == "roc_memset" {
vaddresses.insert("memset".to_string(), address);
}
vaddresses.insert(name.to_string(), address);

View file

@ -21,7 +21,7 @@ use roc_error_macros::internal_error;
use crate::{
generate_dylib::APP_DLL, load_struct_inplace, load_struct_inplace_mut,
load_structs_inplace_mut, open_mmap, open_mmap_mut, redirect_libc_functions,
load_structs_inplace_mut, open_mmap, open_mmap_mut,
};
/// The metadata stores information about/from the host .exe because
@ -364,6 +364,7 @@ pub(crate) fn surgery_pe(executable_path: &Path, metadata_path: &Path, roc_app_b
} = app_relocation;
if let Some(destination) = md.exports.get(name) {
dbg!(name);
match relocation.kind() {
object::RelocationKind::Relative => {
// we implicitly only do 32-bit relocations
@ -1064,9 +1065,11 @@ impl AppSections {
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 = redirect_libc_functions(name).unwrap_or(name).to_string();
relocations.entry(name).or_default().push(AppRelocation {
relocations
.entry(name.to_string())
.or_default()
.push(AppRelocation {
offset_in_section,
address,
relocation,