From a34adc8e005447e7fa44ca3b71db35ceb7facb4c Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Fri, 24 Jun 2022 18:55:21 +0200 Subject: Expand "j_s symb" to "jump symb, x31" assembly pseudo-instruction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As suggested by Léo Gourdin in #437. The previous expansion as a plain "j" instruction fails when the jump offset is too large to be represented (issue #436). Fixes: #436 Closes: #437 --- Changelog | 4 +++- riscV/Asm.v | 2 +- riscV/Asmgenproof.v | 1 + riscV/TargetPrinter.ml | 4 +--- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Changelog b/Changelog index 4fae07e2..f0cc7ac9 100644 --- a/Changelog +++ b/Changelog @@ -18,7 +18,7 @@ Usability: trigger only if parameters were declared.) - Check (and warn if requested) for arguments of struct/union types passed to a variable-argument function. - + Bug fixes: - RISC-V: fixed an error in the modeling of float32 <-> float64 conversions when the argument is a NaN (#428). @@ -29,6 +29,8 @@ Bug fixes: in correct but different allocations.) - Hardened the configure script against Cygwin installations that produce \r\n for end-of-lines (#434). +- RISC-V: tail calls to far-away functions were causing link-time errors + (#436, #437). Coq development: - Updated the Flocq library to version 4.1. diff --git a/riscV/Asm.v b/riscV/Asm.v index a47573a2..cbe3476a 100644 --- a/riscV/Asm.v +++ b/riscV/Asm.v @@ -751,7 +751,7 @@ Definition exec_instr (f: function) (i: instruction) (rs: regset) (m: mem) : out | Pj_l l => goto_label f l rs m | Pj_s s sg => - Next (rs#PC <- (Genv.symbol_address ge s Ptrofs.zero)) m + Next (rs#PC <- (Genv.symbol_address ge s Ptrofs.zero) #X31 <- Vundef) m | Pj_r r sg => Next (rs#PC <- (rs#r)) m | Pjal_s s sg => diff --git a/riscV/Asmgenproof.v b/riscV/Asmgenproof.v index 798dad9f..0d3c8042 100644 --- a/riscV/Asmgenproof.v +++ b/riscV/Asmgenproof.v @@ -816,6 +816,7 @@ Local Transparent destroyed_by_op. (* match states *) econstructor; eauto. apply agree_set_other; auto with asmgen. + apply agree_set_other; auto with asmgen. Simpl. unfold Genv.symbol_address. rewrite symbols_preserved. rewrite H. auto. - (* Mbuiltin *) diff --git a/riscV/TargetPrinter.ml b/riscV/TargetPrinter.ml index d8137f84..366dc02e 100644 --- a/riscV/TargetPrinter.ml +++ b/riscV/TargetPrinter.ml @@ -315,12 +315,10 @@ module Target : TARGET = fprintf oc " sra %a, %a, %a\n" ireg rd ireg0 rs1 ireg0 rs2 (* Unconditional jumps. Links are always to X1/RA. *) - (* TODO: fix up arguments for calls to variadics, to move *) - (* floating point arguments to integer registers. How? *) | Pj_l(l) -> fprintf oc " j %a\n" print_label l | Pj_s(s, sg) -> - fprintf oc " j %a\n" symbol s + fprintf oc " jump %a, x31\n" symbol s | Pj_r(r, sg) -> fprintf oc " jr %a\n" ireg r | Pjal_s(s, sg) -> -- cgit