From 81afc23b75f48bfd46df8a2f7ac75394e4956e6f Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Tue, 22 Feb 2022 10:22:16 +0100 Subject: [PATCH 01/10] Re-enable some singlepass/dylib test on linux and macos --- tests/ignores.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ignores.txt b/tests/ignores.txt index a2efd9dbb3a..6d7ad3a3462 100644 --- a/tests/ignores.txt +++ b/tests/ignores.txt @@ -2,7 +2,7 @@ singlepass spec::multi_value # Singlepass has not implemented multivalue (functions that returns "structs"/"tuples") singlepass spec::simd # Singlepass doesn't support yet SIMD (no one asked for this feature) -singlepass+dylib * # It needs to add support for PIC in Singlepass. Not implemented at the moment +singlepass+dylib+aarch64 * windows+dylib * # This might be trivial to fix? musl+dylib * # Dynamic loading not supported in Musl From b7d705ab893d41f51aff7c4f13b509582a8f4d0c Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Tue, 22 Feb 2022 17:01:58 +0100 Subject: [PATCH 02/10] Changed how relocations are handled in singlepass/aarch64 --- lib/compiler-singlepass/src/codegen.rs | 9 +-- lib/compiler-singlepass/src/emitter_arm64.rs | 17 ++++++ lib/compiler-singlepass/src/machine.rs | 6 +- lib/compiler-singlepass/src/machine_arm64.rs | 38 +++---------- lib/compiler-singlepass/src/machine_x64.rs | 9 ++- lib/engine-universal/src/link.rs | 2 +- lib/object/src/module.rs | 60 +++++++++++++++++++- lib/vm/src/trap/handlers.c | 2 +- tests/ignores.txt | 2 +- 9 files changed, 101 insertions(+), 44 deletions(-) diff --git a/lib/compiler-singlepass/src/codegen.rs b/lib/compiler-singlepass/src/codegen.rs index 2e68a8fc0d9..5a7e43edefb 100644 --- a/lib/compiler-singlepass/src/codegen.rs +++ b/lib/compiler-singlepass/src/codegen.rs @@ -2598,17 +2598,18 @@ impl<'a, M: Machine> FuncGen<'a, M> { function_index - self.module.num_imported_functions, )) }; - self.machine - .move_with_reloc(reloc_target, &mut self.relocations); + let calling_convention = self.calling_convention; self.emit_call_native( |this| { let offset = this .machine .mark_instruction_with_trap_code(TrapCode::StackOverflow); - this.machine - .emit_call_register(this.machine.get_grp_for_call()); + let mut relocations = this + .machine + .emit_call_with_reloc(calling_convention, reloc_target); this.machine.mark_instruction_address_end(offset); + this.relocations.append(&mut relocations); }, params.iter().copied(), param_types.iter().copied(), diff --git a/lib/compiler-singlepass/src/emitter_arm64.rs b/lib/compiler-singlepass/src/emitter_arm64.rs index bb899c0a33e..bd29a6642a5 100644 --- a/lib/compiler-singlepass/src/emitter_arm64.rs +++ b/lib/compiler-singlepass/src/emitter_arm64.rs @@ -157,8 +157,10 @@ pub trait EmitterARM64 { fn emit_clz(&mut self, sz: Size, src: Location, dst: Location); fn emit_rbit(&mut self, sz: Size, src: Location, dst: Location); + fn emit_nop(&mut self); fn emit_label(&mut self, label: Label); fn emit_load_label(&mut self, reg: GPR, label: Label); + fn emit_ldr_label(&mut self, size: Size, reg: GPR, label: Label); fn emit_b_label(&mut self, label: Label); fn emit_cbz_label(&mut self, sz: Size, reg: Location, label: Label); fn emit_cbnz_label(&mut self, sz: Size, reg: Location, label: Label); @@ -1892,6 +1894,9 @@ impl EmitterARM64 for Assembler { } } + fn emit_nop(&mut self) { + dynasm!(self ; nop); + } fn emit_label(&mut self, label: Label) { dynasm!(self ; => label); } @@ -1899,6 +1904,18 @@ impl EmitterARM64 for Assembler { let reg = reg.into_index() as u32; dynasm!(self ; adr X(reg), =>label); } + fn emit_ldr_label(&mut self, size: Size, reg: GPR, label: Label) { + let reg = reg.into_index() as u32; + match size { + Size::S32 => dynasm!(self ; ldr W(reg), =>label), + Size::S64 => dynasm!(self ; ldr X(reg), =>label), + _ => panic!( + "singlepass can't emit LDR {:?} {:?} => {:?} ", + size, reg, label + ), + } + } + fn emit_b_label(&mut self, label: Label) { dynasm!(self ; b =>label); } diff --git a/lib/compiler-singlepass/src/machine.rs b/lib/compiler-singlepass/src/machine.rs index d7359342e9f..a1b55e88626 100644 --- a/lib/compiler-singlepass/src/machine.rs +++ b/lib/compiler-singlepass/src/machine.rs @@ -1038,11 +1038,11 @@ pub trait Machine { ); /// emit a move function address to GPR ready for call, using appropriate relocation - fn move_with_reloc( + fn emit_call_with_reloc( &mut self, + calling_convention: CallingConvention, reloc_target: RelocationTarget, - relocations: &mut Vec, - ); + ) -> Vec; /// Add with location directly from the stack fn emit_binop_add64( &mut self, diff --git a/lib/compiler-singlepass/src/machine_arm64.rs b/lib/compiler-singlepass/src/machine_arm64.rs index 98254944b47..747ceeb6645 100644 --- a/lib/compiler-singlepass/src/machine_arm64.rs +++ b/lib/compiler-singlepass/src/machine_arm64.rs @@ -3229,43 +3229,23 @@ impl Machine for MachineARM64 { unimplemented!(); } - fn move_with_reloc( + fn emit_call_with_reloc( &mut self, + _calling_convention: CallingConvention, reloc_target: RelocationTarget, - relocations: &mut Vec, - ) { - let reloc_at = self.assembler.get_offset().0; - relocations.push(Relocation { - kind: RelocationKind::Arm64Movw0, - reloc_target, - offset: reloc_at as u32, - addend: 0, - }); - self.assembler.emit_movz(Location::GPR(GPR::X27), 0); - let reloc_at = self.assembler.get_offset().0; - relocations.push(Relocation { - kind: RelocationKind::Arm64Movw1, - reloc_target, - offset: reloc_at as u32, - addend: 0, - }); - self.assembler.emit_movk(Location::GPR(GPR::X27), 0, 16); - let reloc_at = self.assembler.get_offset().0; - relocations.push(Relocation { - kind: RelocationKind::Arm64Movw2, - reloc_target, - offset: reloc_at as u32, - addend: 0, - }); - self.assembler.emit_movk(Location::GPR(GPR::X27), 0, 32); + ) -> Vec { + let mut relocations = vec![]; + let next = self.get_label(); let reloc_at = self.assembler.get_offset().0; + self.assembler.emit_call_label(next); + self.emit_label(next); relocations.push(Relocation { - kind: RelocationKind::Arm64Movw3, + kind: RelocationKind::Arm64Call, reloc_target, offset: reloc_at as u32, addend: 0, }); - self.assembler.emit_movk(Location::GPR(GPR::X27), 0, 48); + relocations } fn emit_binop_add64(&mut self, loc_a: Location, loc_b: Location, ret: Location) { diff --git a/lib/compiler-singlepass/src/machine_x64.rs b/lib/compiler-singlepass/src/machine_x64.rs index a463a010f32..b826f03cbf3 100644 --- a/lib/compiler-singlepass/src/machine_x64.rs +++ b/lib/compiler-singlepass/src/machine_x64.rs @@ -3869,13 +3869,14 @@ impl Machine for MachineX86_64 { self.release_gpr(compare); } - fn move_with_reloc( + fn emit_call_with_reloc( &mut self, + _calling_convention: CallingConvention, reloc_target: RelocationTarget, - relocations: &mut Vec, - ) { + ) -> Vec { let reloc_at = self.assembler.get_offset().0 + self.assembler.arch_mov64_imm_offset(); + let mut relocations = vec![]; relocations.push(Relocation { kind: RelocationKind::Abs8, reloc_target, @@ -3890,6 +3891,8 @@ impl Machine for MachineX86_64 { Location::Imm64(std::u64::MAX), Location::GPR(GPR::RAX), ); + self.assembler.emit_call_register(GPR::RAX); + relocations } fn emit_binop_add64(&mut self, loc_a: Location, loc_b: Location, ret: Location) { diff --git a/lib/engine-universal/src/link.rs b/lib/engine-universal/src/link.rs index 4f2dd083399..773349d2f70 100644 --- a/lib/engine-universal/src/link.rs +++ b/lib/engine-universal/src/link.rs @@ -80,7 +80,7 @@ fn apply_relocation( ) } let reloc_delta = (((reloc_delta / 4) as u32) & 0x3ff_ffff) - | read_unaligned(reloc_address as *mut u32); + | (read_unaligned(reloc_address as *mut u32) & 0xfc00_0000); write_unaligned(reloc_address as *mut u32, reloc_delta); }, RelocationKind::Arm64Movw0 => unsafe { diff --git a/lib/object/src/module.rs b/lib/object/src/module.rs index 65fd8b490a2..643ef57614f 100644 --- a/lib/object/src/module.rs +++ b/lib/object/src/module.rs @@ -275,6 +275,8 @@ pub fn emit_compilation( let (_symbol_id, section_offset) = obj.symbol_section_and_offset(symbol_id).unwrap(); for r in relocations { + let relocation_address = section_offset + r.offset as u64; + let (relocation_kind, relocation_encoding, relocation_size) = match r.kind { Reloc::Abs4 => (RelocationKind::Absolute, RelocationEncoding::Generic, 32), Reloc::Abs8 => (RelocationKind::Absolute, RelocationEncoding::Generic, 64), @@ -309,6 +311,62 @@ pub fn emit_compilation( RelocationEncoding::Generic, 32, ), + Reloc::Arm64Movw0 => ( + match obj.format() { + object::BinaryFormat::Elf => { + RelocationKind::Elf(elf::R_AARCH64_MOVW_UABS_G0) + } + fmt => panic!( + "unsupported binary format {:?} for relocation {:?}", + fmt, + obj.format() + ), + }, + RelocationEncoding::Generic, + 16, + ), + Reloc::Arm64Movw1 => ( + match obj.format() { + object::BinaryFormat::Elf => { + RelocationKind::Elf(elf::R_AARCH64_MOVW_UABS_G1) + } + fmt => panic!( + "unsupported binary format {:?} for relocation {:?}", + fmt, + obj.format() + ), + }, + RelocationEncoding::Generic, + 16, + ), + Reloc::Arm64Movw2 => ( + match obj.format() { + object::BinaryFormat::Elf => { + RelocationKind::Elf(elf::R_AARCH64_MOVW_UABS_G2) + } + fmt => panic!( + "unsupported binary format {:?} for relocation {:?}", + fmt, + obj.format() + ), + }, + RelocationEncoding::Generic, + 16, + ), + Reloc::Arm64Movw3 => ( + match obj.format() { + object::BinaryFormat::Elf => { + RelocationKind::Elf(elf::R_AARCH64_MOVW_UABS_G3) + } + fmt => panic!( + "unsupported binary format {:?} for relocation {:?}", + fmt, + obj.format() + ), + }, + RelocationEncoding::Generic, + 16, + ), other => { return Err(ObjectError::UnsupportedArchitecture(format!( "{} (relocation: {}", @@ -317,8 +375,6 @@ pub fn emit_compilation( } }; - let relocation_address = section_offset + r.offset as u64; - match r.reloc_target { RelocationTarget::LocalFunc(index) => { let (_, target_symbol) = function_symbol_ids.get(index).unwrap(); diff --git a/lib/vm/src/trap/handlers.c b/lib/vm/src/trap/handlers.c index 3273353acc2..80fb92da1aa 100644 --- a/lib/vm/src/trap/handlers.c +++ b/lib/vm/src/trap/handlers.c @@ -42,7 +42,7 @@ int wasmer_register_setjmp( void **buf_storage, void (*body)(void*), void *payload) { - #if 0 && defined(CFG_TARGET_OS_MACOS) + #if 1 && defined(CFG_TARGET_OS_MACOS) // Enable this block to ba able to debug Segfault with lldb // This will mask the EXC_BAD_ACCESS from lldb... static int allow_bad_access = 0; diff --git a/tests/ignores.txt b/tests/ignores.txt index 6d7ad3a3462..e6a6b845b59 100644 --- a/tests/ignores.txt +++ b/tests/ignores.txt @@ -2,7 +2,7 @@ singlepass spec::multi_value # Singlepass has not implemented multivalue (functions that returns "structs"/"tuples") singlepass spec::simd # Singlepass doesn't support yet SIMD (no one asked for this feature) -singlepass+dylib+aarch64 * +singlepass+dylib+aarch64+macos * windows+dylib * # This might be trivial to fix? musl+dylib * # Dynamic loading not supported in Musl From 4f710acb7abb28a078ec18286a481e1b00ff32b5 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Wed, 23 Feb 2022 10:33:46 +0100 Subject: [PATCH 03/10] Fixed dylib-singlepass on macos/Arm64 --- lib/compiler-singlepass/src/machine_arm64.rs | 2 +- tests/ignores.txt | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/compiler-singlepass/src/machine_arm64.rs b/lib/compiler-singlepass/src/machine_arm64.rs index 747ceeb6645..1069c5e31a4 100644 --- a/lib/compiler-singlepass/src/machine_arm64.rs +++ b/lib/compiler-singlepass/src/machine_arm64.rs @@ -3237,8 +3237,8 @@ impl Machine for MachineARM64 { let mut relocations = vec![]; let next = self.get_label(); let reloc_at = self.assembler.get_offset().0; + self.emit_label(next); // this is to be sure the current imm26 value is 0 self.assembler.emit_call_label(next); - self.emit_label(next); relocations.push(Relocation { kind: RelocationKind::Arm64Call, reloc_target, diff --git a/tests/ignores.txt b/tests/ignores.txt index e6a6b845b59..e86e537e98e 100644 --- a/tests/ignores.txt +++ b/tests/ignores.txt @@ -2,7 +2,6 @@ singlepass spec::multi_value # Singlepass has not implemented multivalue (functions that returns "structs"/"tuples") singlepass spec::simd # Singlepass doesn't support yet SIMD (no one asked for this feature) -singlepass+dylib+aarch64+macos * windows+dylib * # This might be trivial to fix? musl+dylib * # Dynamic loading not supported in Musl From 3e35e825e04f59d795dd955fb7701ef1a82f0bdf Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Wed, 23 Feb 2022 14:03:28 +0100 Subject: [PATCH 04/10] Try to fix macOS/x86_64 for dylib+singlepass --- lib/engine-dylib/src/artifact.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/engine-dylib/src/artifact.rs b/lib/engine-dylib/src/artifact.rs index 525b931f97b..ad448b2ccb4 100644 --- a/lib/engine-dylib/src/artifact.rs +++ b/lib/engine-dylib/src/artifact.rs @@ -384,7 +384,7 @@ impl DylibArtifact { // We are explicit on the target when the host system is // Apple Silicon, otherwise compilation fails. if target_triple_str == "arm64-apple-darwin" { - vec![format!("--target={}", target_triple_str)] + vec![form at!("--target={}", target_triple_str)] } else { vec![] } @@ -402,6 +402,7 @@ impl DylibArtifact { let notext = match (target_triple.operating_system, target_triple.architecture) { (OperatingSystem::Linux, Architecture::X86_64) => vec!["-Wl,-z,notext"], + (OperatingSystem::MacOSX, Architecture::X86_64) => vec!["-Wl,-read_only_relocs,suppress"], _ => vec![], }; From ffc559a2bbe289fcd768b9f53bb78f6d00086a5c Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Wed, 23 Feb 2022 15:21:26 +0100 Subject: [PATCH 05/10] Change the relocation type for x86_64 on Singlepass and removed the command on linker that enable write to text section --- lib/compiler-singlepass/src/machine_x64.rs | 19 ++++++------------- lib/engine-dylib/src/artifact.rs | 9 +-------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/lib/compiler-singlepass/src/machine_x64.rs b/lib/compiler-singlepass/src/machine_x64.rs index b826f03cbf3..646ae520e4e 100644 --- a/lib/compiler-singlepass/src/machine_x64.rs +++ b/lib/compiler-singlepass/src/machine_x64.rs @@ -3874,24 +3874,17 @@ impl Machine for MachineX86_64 { _calling_convention: CallingConvention, reloc_target: RelocationTarget, ) -> Vec { - let reloc_at = self.assembler.get_offset().0 + self.assembler.arch_mov64_imm_offset(); - let mut relocations = vec![]; + let next = self.get_label(); + let reloc_at = self.assembler.get_offset().0 + 1; // skip E8 + self.assembler.emit_call_label(next); + self.emit_label(next); relocations.push(Relocation { - kind: RelocationKind::Abs8, + kind: RelocationKind::X86CallPCRel4, reloc_target, offset: reloc_at as u32, - addend: 0, + addend: -4, }); - - // RAX is preserved on entry to `emit_call_native` callback. - // The Imm64 value is relocated by the JIT linker. - self.assembler.emit_mov( - Size::S64, - Location::Imm64(std::u64::MAX), - Location::GPR(GPR::RAX), - ); - self.assembler.emit_call_register(GPR::RAX); relocations } diff --git a/lib/engine-dylib/src/artifact.rs b/lib/engine-dylib/src/artifact.rs index ad448b2ccb4..88392e2cc6f 100644 --- a/lib/engine-dylib/src/artifact.rs +++ b/lib/engine-dylib/src/artifact.rs @@ -384,7 +384,7 @@ impl DylibArtifact { // We are explicit on the target when the host system is // Apple Silicon, otherwise compilation fails. if target_triple_str == "arm64-apple-darwin" { - vec![form at!("--target={}", target_triple_str)] + vec![format!("--target={}", target_triple_str)] } else { vec![] } @@ -400,12 +400,6 @@ impl DylibArtifact { Triple::host().to_string(), ); - let notext = match (target_triple.operating_system, target_triple.architecture) { - (OperatingSystem::Linux, Architecture::X86_64) => vec!["-Wl,-z,notext"], - (OperatingSystem::MacOSX, Architecture::X86_64) => vec!["-Wl,-read_only_relocs,suppress"], - _ => vec![], - }; - let linker = engine_inner.linker().executable(); let output = Command::new(linker) .arg(&filepath) @@ -415,7 +409,6 @@ impl DylibArtifact { .args(&target_args) // .args(&wasmer_symbols) .arg("-shared") - .args(¬ext) .args(&cross_compiling_args) .arg("-v") .output() From a69e9445cbc637dbfd14420cfdeff3f59fd26bae Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Wed, 23 Feb 2022 16:32:55 +0100 Subject: [PATCH 06/10] Put back no-text flags, it's still needed --- lib/engine-dylib/src/artifact.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/engine-dylib/src/artifact.rs b/lib/engine-dylib/src/artifact.rs index 88392e2cc6f..525b931f97b 100644 --- a/lib/engine-dylib/src/artifact.rs +++ b/lib/engine-dylib/src/artifact.rs @@ -400,6 +400,11 @@ impl DylibArtifact { Triple::host().to_string(), ); + let notext = match (target_triple.operating_system, target_triple.architecture) { + (OperatingSystem::Linux, Architecture::X86_64) => vec!["-Wl,-z,notext"], + _ => vec![], + }; + let linker = engine_inner.linker().executable(); let output = Command::new(linker) .arg(&filepath) @@ -409,6 +414,7 @@ impl DylibArtifact { .args(&target_args) // .args(&wasmer_symbols) .arg("-shared") + .args(¬ext) .args(&cross_compiling_args) .arg("-v") .output() From 17138fe9bb38cf6e2e17fab47d293ebef67dae2d Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Tue, 15 Mar 2022 14:14:19 +0100 Subject: [PATCH 07/10] Removed debug leftofver --- lib/vm/src/trap/handlers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vm/src/trap/handlers.c b/lib/vm/src/trap/handlers.c index 80fb92da1aa..3273353acc2 100644 --- a/lib/vm/src/trap/handlers.c +++ b/lib/vm/src/trap/handlers.c @@ -42,7 +42,7 @@ int wasmer_register_setjmp( void **buf_storage, void (*body)(void*), void *payload) { - #if 1 && defined(CFG_TARGET_OS_MACOS) + #if 0 && defined(CFG_TARGET_OS_MACOS) // Enable this block to ba able to debug Segfault with lldb // This will mask the EXC_BAD_ACCESS from lldb... static int allow_bad_access = 0; From 80cee07df9f067f9c5c2b318ea85616581b1dc75 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Tue, 15 Mar 2022 14:14:52 +0100 Subject: [PATCH 08/10] Removed unused emit_ldr_label and emit_nop arm64 emiter --- lib/compiler-singlepass/src/emitter_arm64.rs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/lib/compiler-singlepass/src/emitter_arm64.rs b/lib/compiler-singlepass/src/emitter_arm64.rs index bd29a6642a5..33588d7d148 100644 --- a/lib/compiler-singlepass/src/emitter_arm64.rs +++ b/lib/compiler-singlepass/src/emitter_arm64.rs @@ -157,10 +157,8 @@ pub trait EmitterARM64 { fn emit_clz(&mut self, sz: Size, src: Location, dst: Location); fn emit_rbit(&mut self, sz: Size, src: Location, dst: Location); - fn emit_nop(&mut self); fn emit_label(&mut self, label: Label); fn emit_load_label(&mut self, reg: GPR, label: Label); - fn emit_ldr_label(&mut self, size: Size, reg: GPR, label: Label); fn emit_b_label(&mut self, label: Label); fn emit_cbz_label(&mut self, sz: Size, reg: Location, label: Label); fn emit_cbnz_label(&mut self, sz: Size, reg: Location, label: Label); @@ -1894,9 +1892,6 @@ impl EmitterARM64 for Assembler { } } - fn emit_nop(&mut self) { - dynasm!(self ; nop); - } fn emit_label(&mut self, label: Label) { dynasm!(self ; => label); } @@ -1904,17 +1899,6 @@ impl EmitterARM64 for Assembler { let reg = reg.into_index() as u32; dynasm!(self ; adr X(reg), =>label); } - fn emit_ldr_label(&mut self, size: Size, reg: GPR, label: Label) { - let reg = reg.into_index() as u32; - match size { - Size::S32 => dynasm!(self ; ldr W(reg), =>label), - Size::S64 => dynasm!(self ; ldr X(reg), =>label), - _ => panic!( - "singlepass can't emit LDR {:?} {:?} => {:?} ", - size, reg, label - ), - } - } fn emit_b_label(&mut self, label: Label) { dynasm!(self ; b =>label); From ed7a672740aa2110c954e0cdae07b78e9b3a49fc Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Wed, 16 Mar 2022 16:34:15 +0100 Subject: [PATCH 09/10] Removed the '-notext' flags to dylib-engine linker command --- lib/engine-dylib/src/artifact.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/engine-dylib/src/artifact.rs b/lib/engine-dylib/src/artifact.rs index 525b931f97b..88392e2cc6f 100644 --- a/lib/engine-dylib/src/artifact.rs +++ b/lib/engine-dylib/src/artifact.rs @@ -400,11 +400,6 @@ impl DylibArtifact { Triple::host().to_string(), ); - let notext = match (target_triple.operating_system, target_triple.architecture) { - (OperatingSystem::Linux, Architecture::X86_64) => vec!["-Wl,-z,notext"], - _ => vec![], - }; - let linker = engine_inner.linker().executable(); let output = Command::new(linker) .arg(&filepath) @@ -414,7 +409,6 @@ impl DylibArtifact { .args(&target_args) // .args(&wasmer_symbols) .arg("-shared") - .args(¬ext) .args(&cross_compiling_args) .arg("-v") .output() From 31c9e622f7193d35222a10b013ddea2f8e768a6f Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Thu, 17 Mar 2022 10:41:04 +0100 Subject: [PATCH 10/10] Removed Arm64MovwX relocs --- lib/compiler-llvm/src/object_file.rs | 20 ---------- lib/compiler/src/relocation.rs | 18 +-------- lib/engine-universal/src/link.rs | 24 ------------ lib/object/src/module.rs | 56 ---------------------------- 4 files changed, 1 insertion(+), 117 deletions(-) diff --git a/lib/compiler-llvm/src/object_file.rs b/lib/compiler-llvm/src/object_file.rs index 794cd6a52f7..d037e804118 100644 --- a/lib/compiler-llvm/src/object_file.rs +++ b/lib/compiler-llvm/src/object_file.rs @@ -169,26 +169,6 @@ where object::RelocationKind::Elf(object::elf::R_X86_64_PC64), 0, ) => RelocationKind::X86PCRel8, - ( - object::Architecture::Aarch64, - object::RelocationKind::Elf(object::elf::R_AARCH64_MOVW_UABS_G0_NC), - 0, - ) => RelocationKind::Arm64Movw0, - ( - object::Architecture::Aarch64, - object::RelocationKind::Elf(object::elf::R_AARCH64_MOVW_UABS_G1_NC), - 0, - ) => RelocationKind::Arm64Movw1, - ( - object::Architecture::Aarch64, - object::RelocationKind::Elf(object::elf::R_AARCH64_MOVW_UABS_G2_NC), - 0, - ) => RelocationKind::Arm64Movw2, - ( - object::Architecture::Aarch64, - object::RelocationKind::Elf(object::elf::R_AARCH64_MOVW_UABS_G3), - 0, - ) => RelocationKind::Arm64Movw3, (object::Architecture::Aarch64, object::RelocationKind::PltRelative, 26) => { RelocationKind::Arm64Call } diff --git a/lib/compiler/src/relocation.rs b/lib/compiler/src/relocation.rs index 8e73d8c34a2..7c3382719b3 100644 --- a/lib/compiler/src/relocation.rs +++ b/lib/compiler/src/relocation.rs @@ -50,14 +50,6 @@ pub enum RelocationKind { Arm32Call, /// Arm64 call target Arm64Call, - /// Arm64 movk/z part 0 - Arm64Movw0, - /// Arm64 movk/z part 1 - Arm64Movw1, - /// Arm64 movk/z part 2 - Arm64Movw2, - /// Arm64 movk/z part 3 - Arm64Movw3, // /// RISC-V call target // RiscvCall, /// Elf x86_64 32 bit signed PC relative offset to two GOT entries for GD symbol. @@ -80,10 +72,6 @@ impl fmt::Display for RelocationKind { Self::X86CallPLTRel4 => write!(f, "CallPLTRel4"), Self::X86GOTPCRel4 => write!(f, "GOTPCRel4"), Self::Arm32Call | Self::Arm64Call => write!(f, "Call"), - Self::Arm64Movw0 => write!(f, "Arm64MovwG0"), - Self::Arm64Movw1 => write!(f, "Arm64MovwG1"), - Self::Arm64Movw2 => write!(f, "Arm64MovwG2"), - Self::Arm64Movw3 => write!(f, "Arm64MovwG3"), Self::ElfX86_64TlsGd => write!(f, "ElfX86_64TlsGd"), // Self::MachOX86_64Tlv => write!(f, "MachOX86_64Tlv"), } @@ -133,11 +121,7 @@ impl Relocation { /// The function returns the relocation address and the delta. pub fn for_address(&self, start: usize, target_func_address: u64) -> (usize, u64) { match self.kind { - RelocationKind::Abs8 - | RelocationKind::Arm64Movw0 - | RelocationKind::Arm64Movw1 - | RelocationKind::Arm64Movw2 - | RelocationKind::Arm64Movw3 => { + RelocationKind::Abs8 => { let reloc_address = start + self.offset as usize; let reloc_addend = self.addend as isize; let reloc_abs = target_func_address diff --git a/lib/engine-universal/src/link.rs b/lib/engine-universal/src/link.rs index 773349d2f70..85c801bfccd 100644 --- a/lib/engine-universal/src/link.rs +++ b/lib/engine-universal/src/link.rs @@ -83,30 +83,6 @@ fn apply_relocation( | (read_unaligned(reloc_address as *mut u32) & 0xfc00_0000); write_unaligned(reloc_address as *mut u32, reloc_delta); }, - RelocationKind::Arm64Movw0 => unsafe { - let (reloc_address, reloc_delta) = r.for_address(body, target_func_address as u64); - let reloc_delta = - (((reloc_delta & 0xffff) as u32) << 5) | read_unaligned(reloc_address as *mut u32); - write_unaligned(reloc_address as *mut u32, reloc_delta); - }, - RelocationKind::Arm64Movw1 => unsafe { - let (reloc_address, reloc_delta) = r.for_address(body, target_func_address as u64); - let reloc_delta = ((((reloc_delta >> 16) & 0xffff) as u32) << 5) - | read_unaligned(reloc_address as *mut u32); - write_unaligned(reloc_address as *mut u32, reloc_delta); - }, - RelocationKind::Arm64Movw2 => unsafe { - let (reloc_address, reloc_delta) = r.for_address(body, target_func_address as u64); - let reloc_delta = ((((reloc_delta >> 32) & 0xffff) as u32) << 5) - | read_unaligned(reloc_address as *mut u32); - write_unaligned(reloc_address as *mut u32, reloc_delta); - }, - RelocationKind::Arm64Movw3 => unsafe { - let (reloc_address, reloc_delta) = r.for_address(body, target_func_address as u64); - let reloc_delta = ((((reloc_delta >> 48) & 0xffff) as u32) << 5) - | read_unaligned(reloc_address as *mut u32); - write_unaligned(reloc_address as *mut u32, reloc_delta); - }, kind => panic!( "Relocation kind unsupported in the current architecture {}", kind diff --git a/lib/object/src/module.rs b/lib/object/src/module.rs index 643ef57614f..d2d7c0b5167 100644 --- a/lib/object/src/module.rs +++ b/lib/object/src/module.rs @@ -311,62 +311,6 @@ pub fn emit_compilation( RelocationEncoding::Generic, 32, ), - Reloc::Arm64Movw0 => ( - match obj.format() { - object::BinaryFormat::Elf => { - RelocationKind::Elf(elf::R_AARCH64_MOVW_UABS_G0) - } - fmt => panic!( - "unsupported binary format {:?} for relocation {:?}", - fmt, - obj.format() - ), - }, - RelocationEncoding::Generic, - 16, - ), - Reloc::Arm64Movw1 => ( - match obj.format() { - object::BinaryFormat::Elf => { - RelocationKind::Elf(elf::R_AARCH64_MOVW_UABS_G1) - } - fmt => panic!( - "unsupported binary format {:?} for relocation {:?}", - fmt, - obj.format() - ), - }, - RelocationEncoding::Generic, - 16, - ), - Reloc::Arm64Movw2 => ( - match obj.format() { - object::BinaryFormat::Elf => { - RelocationKind::Elf(elf::R_AARCH64_MOVW_UABS_G2) - } - fmt => panic!( - "unsupported binary format {:?} for relocation {:?}", - fmt, - obj.format() - ), - }, - RelocationEncoding::Generic, - 16, - ), - Reloc::Arm64Movw3 => ( - match obj.format() { - object::BinaryFormat::Elf => { - RelocationKind::Elf(elf::R_AARCH64_MOVW_UABS_G3) - } - fmt => panic!( - "unsupported binary format {:?} for relocation {:?}", - fmt, - obj.format() - ), - }, - RelocationEncoding::Generic, - 16, - ), other => { return Err(ObjectError::UnsupportedArchitecture(format!( "{} (relocation: {}",