From c8ccecc783671fb699a33f432c34e3c1cd1dc801 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Thu, 23 Sep 2021 15:33:06 +0200 Subject: For __builtin_memcpy_aligned, watch out for alignment of stack offsets Stack offsets must be multiple of 8 when using ldp/stp instructions and multiple of the transferred size when using other load/store instructions with offsets greater than 256. For simplicity, always require that the offset is multiple of 8. Fixes: #410 --- aarch64/Asmexpand.ml | 1 + 1 file changed, 1 insertion(+) (limited to 'aarch64') diff --git a/aarch64/Asmexpand.ml b/aarch64/Asmexpand.ml index d24a9ef6..6c58e075 100644 --- a/aarch64/Asmexpand.ml +++ b/aarch64/Asmexpand.ml @@ -185,6 +185,7 @@ let memcpy_small_arg sz arg tmp = | BA_addrstack ofs -> if offset_in_range ofs && offset_in_range (Ptrofs.add ofs (Ptrofs.repr (Z.of_uint sz))) + && Int64.rem (Z.to_int64 ofs) 8L = 0L then (XSP, ofs) else begin expand_addimm64 (RR1 tmp) XSP ofs; (RR1 tmp, _0) end | _ -> -- cgit From c34d25e011402aedad62b3fe9b7b04989df4522e Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Thu, 23 Sep 2021 12:52:11 +0200 Subject: Fix wrong expansion of __builtin_memcpy_aligned In the "small" case, there was an error in the choice of temporary registers to use when one argument is a stack location and the other is a register. The chosen temporary could conflict with the argument that resides in a register. Fixes: #412 --- aarch64/Asmexpand.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'aarch64') diff --git a/aarch64/Asmexpand.ml b/aarch64/Asmexpand.ml index 6c58e075..573e8b92 100644 --- a/aarch64/Asmexpand.ml +++ b/aarch64/Asmexpand.ml @@ -192,8 +192,8 @@ let memcpy_small_arg sz arg tmp = assert false let expand_builtin_memcpy_small sz al src dst = - let (tsrc, tdst) = - if dst <> BA (IR X17) then (X17, X29) else (X29, X17) in + let tsrc = if dst <> BA (IR X17) then X17 else X29 in + let tdst = if src <> BA (IR X29) then X29 else X17 in let (rsrc, osrc) = memcpy_small_arg sz src tsrc in let (rdst, odst) = memcpy_small_arg sz dst tdst in let rec copy osrc odst sz = -- cgit