From f27cfe71a244e940fd942dd8e7b5b28a7ac2b5ff Mon Sep 17 00:00:00 2001 From: TheCPP Date: Tue, 27 Aug 2024 17:21:30 +0200 Subject: [PATCH] [FIX] i think i fixed #8 for windows but it isn't fixed for linux + [FIX] fixing test --- src/Obj/wrapper.rs | 16 ++++++++++------ src/Target/target_descr.rs | 2 +- tests/x64_instruction_encoding.rs | 2 ++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Obj/wrapper.rs b/src/Obj/wrapper.rs index c6be5115..b29dddbf 100644 --- a/src/Obj/wrapper.rs +++ b/src/Obj/wrapper.rs @@ -172,7 +172,7 @@ impl ObjectBuilder { let secData = obj.add_section(vec![], ".data".as_bytes().to_vec(), SectionKind::Data); let secConsts = obj.add_section(vec![], ".rodata".as_bytes().to_vec(), SectionKind::ReadOnlyData); - let mut syms: BTreeMap, Option, SymbolId)> = BTreeMap::new(); + let mut syms: BTreeMap, Option, SymbolId, Decl)> = BTreeMap::new(); for (name, data) in &self.defines { let name = name.to_owned(); @@ -247,21 +247,25 @@ impl ObjectBuilder { Decl::Constant => obj.add_symbol_data(sym, secConsts, &data, align), }; - syms.insert(name.clone(), (None, Some(def_offset), sym)); + syms.insert(name.clone(), (None, Some(def_offset), sym, *decl)); } else { - syms.insert(name.clone(), (None, None, sym)); + syms.insert(name.clone(), (None, None, sym, *decl)); } } for link in &self.links { - let (_, off, _) = syms.get(&link.from).unwrap(); - let (_, _, to_sym) = syms.get(&link.to).unwrap(); + let (_, off, _, _) = syms.get(&link.from).unwrap(); + let (_, _, to_sym, ty) = syms.get(&link.to).unwrap(); let mut addend = 0; let mut offset = 0; if self.triple.getCallConv() == Ok(CallConv::WindowsFastCall) { - addend = -1; + addend = match ty { + Decl::Function => 0, + Decl::Data => -1, + Decl::Constant => -1, + }; offset = -4; } else if self.triple.getCallConv() == Ok(CallConv::SystemV) { addend = 0; diff --git a/src/Target/target_descr.rs b/src/Target/target_descr.rs index ebcb8744..6de1d8b9 100644 --- a/src/Target/target_descr.rs +++ b/src/Target/target_descr.rs @@ -68,7 +68,7 @@ impl BackendInfos { for (var, store) in &self.varsStorage { if let VarStorage::Register(var_reg) = store { - if var_reg == ® { + if var_reg.sub64() == reg.sub64() { out = Some(var); } } diff --git a/tests/x64_instruction_encoding.rs b/tests/x64_instruction_encoding.rs index cf611f83..ad491fd0 100644 --- a/tests/x64_instruction_encoding.rs +++ b/tests/x64_instruction_encoding.rs @@ -29,12 +29,14 @@ pub fn test_ret() { #[test] pub fn test_optimization() { let mut instrs = vec![ + Instr::with0(Mnemonic::StartOptimization), Instr::with2(Mnemonic::Mov, Operand::Reg(x64Reg::Rax.boxed()), Operand::Reg(x64Reg::Rcx.boxed())), Instr::with2(Mnemonic::Add, Operand::Reg(x64Reg::Rax.boxed()), Operand::Reg(x64Reg::Rdx.boxed())), Instr::with2(Mnemonic::Mov, Operand::Reg(x64Reg::Rcx.boxed()), Operand::Reg(x64Reg::Rax.boxed())), ]; let expected_optimized = vec![ + Instr::with0(Mnemonic::StartOptimization), Instr::with2(Mnemonic::Lea, Operand::Reg(x64Reg::Rax.boxed()), Operand::Mem(x64Reg::Rcx + x64Reg::Rdx)), Instr::with2(Mnemonic::Mov, Operand::Reg(x64Reg::Rcx.boxed()), Operand::Reg(x64Reg::Rax.boxed())), ];