diff --git a/cranelift/codegen/src/isa/aarch64/inst/mod.rs b/cranelift/codegen/src/isa/aarch64/inst/mod.rs index 563a2fa151..f3bf2c4e82 100644 --- a/cranelift/codegen/src/isa/aarch64/inst/mod.rs +++ b/cranelift/codegen/src/isa/aarch64/inst/mod.rs @@ -1032,9 +1032,10 @@ fn aarch64_get_operands VReg>(inst: &Inst, collector: &mut Operan &Inst::VirtualSPOffsetAdj { .. } => {} &Inst::ElfTlsGetAddr { .. } => { - collector.reg_clobbers(AArch64MachineDeps::get_regs_clobbered_by_call( - CallConv::SystemV, - )); + collector.reg_def(Writable::from_reg(regs::xreg(0))); + let mut clobbers = AArch64MachineDeps::get_regs_clobbered_by_call(CallConv::SystemV); + clobbers.remove(regs::xreg_preg(0)); + collector.reg_clobbers(clobbers); } &Inst::Unwind { .. } => {} &Inst::EmitIsland { .. } => {} @@ -2723,7 +2724,7 @@ impl Inst { &Inst::EmitIsland { needed_space } => format!("emit_island {}", needed_space), &Inst::ElfTlsGetAddr { ref symbol } => { - format!("elf_tls_get_addr {}", symbol) + format!("x0 = elf_tls_get_addr {}", symbol) } &Inst::Unwind { ref inst } => { format!("unwind {:?}", inst) diff --git a/cranelift/codegen/src/isa/x64/inst/emit_tests.rs b/cranelift/codegen/src/isa/x64/inst/emit_tests.rs index b2a88ad7c0..06166a55bd 100644 --- a/cranelift/codegen/src/isa/x64/inst/emit_tests.rs +++ b/cranelift/codegen/src/isa/x64/inst/emit_tests.rs @@ -4840,7 +4840,7 @@ fn test_x64_emit() { }, }, "66488D3D00000000666648E800000000", - "elf_tls_get_addr User { namespace: 0, index: 0 }", + "%rax = elf_tls_get_addr User { namespace: 0, index: 0 }", )); insns.push(( @@ -4851,7 +4851,7 @@ fn test_x64_emit() { }, }, "488B3D00000000FF17", - "macho_tls_get_addr User { namespace: 0, index: 0 }", + "%rax = macho_tls_get_addr User { namespace: 0, index: 0 }", )); // ======================================================== diff --git a/cranelift/codegen/src/isa/x64/inst/mod.rs b/cranelift/codegen/src/isa/x64/inst/mod.rs index c27b1f9d80..f6250859a2 100644 --- a/cranelift/codegen/src/isa/x64/inst/mod.rs +++ b/cranelift/codegen/src/isa/x64/inst/mod.rs @@ -1672,11 +1672,11 @@ impl PrettyPrint for Inst { Inst::Ud2 { trap_code } => format!("ud2 {}", trap_code), Inst::ElfTlsGetAddr { ref symbol } => { - format!("elf_tls_get_addr {:?}", symbol) + format!("%rax = elf_tls_get_addr {:?}", symbol) } Inst::MachOTlsGetAddr { ref symbol } => { - format!("macho_tls_get_addr {:?}", symbol) + format!("%rax = macho_tls_get_addr {:?}", symbol) } Inst::Unwind { inst } => { @@ -2083,15 +2083,16 @@ fn x64_get_operands VReg>(inst: &Inst, collector: &mut OperandCol } Inst::ElfTlsGetAddr { .. } | Inst::MachOTlsGetAddr { .. } => { + collector.reg_def(Writable::from_reg(regs::rax())); // All caller-saves are clobbered. // // We use the SysV calling convention here because the // pseudoinstruction (and relocation that it emits) is specific to // ELF systems; other x86-64 targets with other conventions (i.e., // Windows) use different TLS strategies. - collector.reg_clobbers(X64ABIMachineSpec::get_regs_clobbered_by_call( - CallConv::SystemV, - )); + let mut clobbers = X64ABIMachineSpec::get_regs_clobbered_by_call(CallConv::SystemV); + clobbers.remove(regs::gpr_preg(regs::ENC_RAX)); + collector.reg_clobbers(clobbers); } Inst::Unwind { .. } => {} diff --git a/cranelift/filetests/filetests/isa/aarch64/tls-elf-gd.clif b/cranelift/filetests/filetests/isa/aarch64/tls-elf-gd.clif index 7cc42b191b..d1657b231a 100644 --- a/cranelift/filetests/filetests/isa/aarch64/tls-elf-gd.clif +++ b/cranelift/filetests/filetests/isa/aarch64/tls-elf-gd.clif @@ -19,7 +19,7 @@ block0(v0: i32): ; stp d8, d9, [sp, #-16]! ; block0: ; mov x25, x0 -; elf_tls_get_addr u1:0 +; x0 = elf_tls_get_addr u1:0 ; mov x1, x0 ; mov x0, x25 ; ldp d8, d9, [sp], #16 diff --git a/cranelift/filetests/filetests/isa/x64/tls_elf.clif b/cranelift/filetests/filetests/isa/x64/tls_elf.clif index 58b21308da..c7286e159f 100644 --- a/cranelift/filetests/filetests/isa/x64/tls_elf.clif +++ b/cranelift/filetests/filetests/isa/x64/tls_elf.clif @@ -13,7 +13,7 @@ block0(v0: i32): ; pushq %rbp ; movq %rsp, %rbp ; block0: -; elf_tls_get_addr User { namespace: 1, index: 0 } +; %rax = elf_tls_get_addr User { namespace: 1, index: 0 } ; movq %rbp, %rsp ; popq %rbp ; ret