Skip to content

Commit 4e18ec8

Browse files
committed
Small linker fixes
1 parent dd19b99 commit 4e18ec8

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

cilly/src/v2/asm.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ impl Assembly {
938938
.collect();
939939
for index in 0..mref_count {
940940
// Get the full method refernce
941-
let mref = &self.method_refs.0[index];
941+
let mref = self.method_refs.0[index].clone();
942942
// Check if this method reference's class has an assembly. If it has, then the method is extern. If it has not, then it is defined in this assembly
943943
// and must have some kind of implementation
944944
let class = self.class_ref(mref.class());
@@ -993,13 +993,19 @@ impl Assembly {
993993
let arg_names = (0..(self[mref.sig()].inputs().len()))
994994
.map(|_| None)
995995
.collect();
996+
let imp = if self[mref.name()].contains("__rust_alloc") && !self[mref.name()].contains("__rust_alloc_error_handler"){
997+
let mref = MethodRef::aligned_alloc(self);
998+
MethodImpl::wrapper(self.alloc_methodref(mref),self)
999+
}else{
1000+
MethodImpl::Missing
1001+
};
9961002
let method_def = MethodDef::new(
9971003
Access::Public,
9981004
ClassDefIdx(mref.class()),
9991005
mref.name(),
10001006
mref.sig(),
10011007
mref.kind(),
1002-
MethodImpl::Missing,
1008+
imp,
10031009
arg_names,
10041010
);
10051011
assert!(

cilly/src/v2/c_exporter/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,11 +1049,19 @@ impl CExporter {
10491049
writeln!(type_defs, "{field_tpe} {fname};")?;
10501050
}
10511051
if last_offset != class.explict_size().unwrap().get() {
1052-
writeln!(
1053-
type_defs,
1054-
"uint8_t pad_{pad_count}[{}];\n",
1055-
class.explict_size().unwrap().get() - last_offset
1056-
)?;
1052+
let size = class.explict_size().unwrap().get();
1053+
if let Some((tpe,name,_)) = fields.last(){
1054+
//assert!(size >= last_offset, "Type {class_name} has field offset {last_offset} larger than {size}. {} {}",tpe.mangle(asm),&asm[*name]);
1055+
writeln!(
1056+
type_defs,
1057+
"uint8_t pad_{pad_count}[{}];\n",
1058+
size.checked_sub(last_offset).unwrap_or_else(||{
1059+
eprintln!("Type {class_name} has field offset {last_offset} larger than {size}. {} {}",tpe.mangle(asm),&asm[*name]);
1060+
0
1061+
})
1062+
)?;
1063+
}
1064+
10571065
}
10581066
writeln!(type_defs, "}} {class_name};")?;
10591067
} else {

cilly/src/v2/method.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ use serde::{Deserialize, Serialize};
33

44
use super::{
55
bimap::{BiMapIndex, IntoBiMapIndex},
6-
cilnode::MethodKind,
6+
cilnode::{IsPure, MethodKind},
77
Access, Assembly, BasicBlock, CILIterElem, CILNode, ClassDefIdx, ClassRef, ClassRefIdx, Int,
88
SigIdx, StringIdx, Type, TypeIdx,
99
};
10-
use crate::v2::iter::TpeIter;
10+
use crate::{cil_node::CallOpArgs, v2::iter::TpeIter};
1111
use crate::v2::CILRoot;
1212
pub type LocalId = u32;
1313
#[derive(Hash, PartialEq, Eq, Clone, Debug, Serialize, Deserialize)]
@@ -722,6 +722,19 @@ impl MethodImpl {
722722
// Swap new and locals
723723
std::mem::swap(locals, new_locals.get_mut().unwrap());
724724
}
725+
726+
pub(crate) fn wrapper(mref: MethodRefIdx, asm: &mut Assembly) -> MethodImpl {
727+
let sig = asm[asm[mref].sig()].clone();
728+
let args = sig.inputs().iter().enumerate().map(|(idx,_)|asm.alloc_node(CILNode::LdArg(idx.try_into().unwrap()))).collect();
729+
let roots = if asm.sizeof_type(*sig.output()) == 0{
730+
let call = asm.alloc_root(CILRoot::Call(Box::new((mref,args, IsPure::NOT))));
731+
vec![call,asm.alloc_root(CILRoot::VoidRet)]
732+
} else{
733+
let val = asm.alloc_node(CILNode::Call(Box::new((mref,args, IsPure::NOT))));
734+
vec![asm.alloc_root(CILRoot::Ret(val))]
735+
};
736+
MethodImpl::MethodBody { blocks: vec![BasicBlock::new(roots,0,None)], locals: vec![].into() }
737+
}
725738
}
726739
#[derive(Hash, PartialEq, Eq, Clone, Copy, Debug, Serialize, Deserialize)]
727740
pub struct MethodDefIdx(pub MethodRefIdx);

cilly/src/v2/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![allow(clippy::module_name_repetitions)]
33
// This lint includes tests for some bizzare reason, so ignoring it seems like the best course of action
44
#![allow(clippy::missing_panics_doc)]
5+
56
use std::path::Path;
67

78
pub use access::Access;

rustc_codegen_clr_type/src/utilis.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ pub fn tuple_name(elements: &[Type], asm: &Assembly) -> String {
156156
/// Creates a tuple with no more than 8 elements.
157157
#[must_use]
158158
pub fn simple_tuple(elements: &[cilly::v2::Type], asm: &mut Assembly) -> ClassRefIdx {
159-
// Since no intering can happen at this stage, we can pass an empty AsmStringContainer safely.
160159
let name = tuple_name(elements, asm);
161160
let name = asm.alloc_string(name);
162161
asm.alloc_class_ref(ClassRef::new(name, None, true, [].into()))

0 commit comments

Comments
 (0)