Skip to content

Commit

Permalink
fix: windows llvm.used imcompatibal with visitor function name
Browse files Browse the repository at this point in the history
  • Loading branch information
Chronostasys committed Sep 22, 2023
1 parent 2935140 commit ec7e836
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 1 addition & 3 deletions immix/src/mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ mod _win {
}

pub fn commit(&self, page: *mut u8, size: usize) -> bool {
unsafe {
VirtualAlloc(page.cast(), size, MEM_COMMIT, PAGE_READWRITE) != std::ptr::null_mut()
}
unsafe { VirtualAlloc(page.cast(), size, MEM_COMMIT, PAGE_READWRITE).is_null() }
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/ast/builder/llvmbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
/// 2. 所有涉及llvm类型的函数(包括参数或返回值)都应该是private的
use std::{
cell::{Cell, RefCell},
collections::hash_map::DefaultHasher,
hash::{Hash, Hasher},
path::Path,
sync::{
atomic::{AtomicI64, Ordering},
Expand Down Expand Up @@ -546,7 +548,11 @@ impl<'a, 'ctx> LLVMBuilder<'a, 'ctx> {
let ty = ptrtp.get_element_type().into_struct_type();
let ftp = self.mark_fn_tp(ptrtp);
let arr_tp = ty.get_field_type_at_index(1).unwrap();
let fname = &(arr_tp.to_string() + "@" + &ctx.plmod.path);
// windows linker won't recognize flags with special caracters (llvm.used will add linker flags
// to prevent symbol trim), so we need to do a hash here to remove the special caracters
let mut hasher = DefaultHasher::new();
(arr_tp.to_string() + "@" + &ctx.plmod.path).hash(&mut hasher);
let fname = &format!("{:x}", hasher.finish());
if let Some(f) = self.module.get_function(fname) {
return f;
}
Expand Down

0 comments on commit ec7e836

Please sign in to comment.