From dc34c634bfa48f0de7838782e916a19d465c6f79 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Tue, 1 Dec 2026 18:27:27 +0100 Subject: [PATCH] x86_64: fix `destroyed_at_indirect_call` for the Win64 ABI In the ELF ABI, calls to variadic functions set the AL register. But in the Win64 ABI, it's registers CX, DX, R8 and R9 that may be destroyed, because some FP arguments are copied into them. (See file Asmexpand.ml.) --- x86/Machregs.v | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/x86/Machregs.v b/x86/Machregs.v index 2b6fc8ab5..fab90a99d 100644 --- a/x86/Machregs.v +++ b/x86/Machregs.v @@ -191,8 +191,15 @@ Definition destroyed_by_setstack (ty: typ): list mreg := | _ => nil end. +(** Calls to variadic functions set the AL register in the ELF ABI + and can copy FP arguments to the CX, DX, R8 and R9 registers in the Win64 ABI. + (See file Asmexpand.ml.) Mark those registers as destroyed, + so that the register containing the function address to call is preserved. *) + Definition destroyed_at_indirect_call: list mreg := - AX :: nil. + if Archi.win64 + then CX :: DX :: R8 :: R9 :: nil + else AX :: nil. Definition temp_for_parent_frame: mreg := AX.