Skip to content

Commit ad4934a

Browse files
authored
Merge pull request #595 from AbsInt/x86_64-jmptbl
x86-64 `Pjmptbl`: normalize the argument before indexing into the jump table
2 parents 11aa59a + 1e42571 commit ad4934a

4 files changed

Lines changed: 6 additions & 2 deletions

File tree

‎Changelog.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Bug fixes:
1212
- Thread the current typing environment through `Elab.elab_initializer`.
1313
- Printing of assembly files: quote command-line arguments when needed (#586)
1414
- Printing of assembly files: revised string quoting in debugging information (#588)
15+
- x86 64 bits, `Pjmptbl` instruction: make sure the 32-bit argument is zero-extended to 64 bits before indexing in the jump table (#595)
1516

1617
Usability:
1718
- AArch64 asm clobbers: recognize more register names (#576)

‎riscV/TargetPrinter.ml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ module Target : TARGET =
521521
fprintf oc " flw %a, %a, x31 %s %.18g\n"
522522
freg rd label lbl comment (camlfloat_of_coqfloat32 f)
523523
| Pbtbl(r, tbl) ->
524+
assert (Int64.of_int (List.length tbl) <= 0x8000_0000L);
524525
let lbl = new_label() in
525526
fprintf oc "%s jumptable [ " comment;
526527
List.iter (fun l -> fprintf oc "%a " print_label l) tbl;

‎test‎

‎x86/TargetPrinter.ml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,9 @@ module Target(System: SYSTEM):TARGET =
752752
let (tmp1, tmp2) =
753753
if r = RAX then (RDX, RAX) else (RAX, RDX) in
754754
fprintf oc " leaq %a(%%rip), %a\n" label l ireg tmp1;
755-
fprintf oc " movslq (%a, %a, 4), %a\n" ireg tmp1 ireg r ireg tmp2;
755+
(* Normalize r to 32-bit unsigned *)
756+
fprintf oc " movl %a, %a\n" ireg32 r ireg32 tmp2;
757+
fprintf oc " movslq (%a, %a, 4), %a\n" ireg tmp1 ireg tmp2 ireg tmp2;
756758
fprintf oc " addq %a, %a\n" ireg tmp2 ireg tmp1;
757759
fprintf oc " jmp *%a\n" ireg tmp1
758760
end else begin

0 commit comments

Comments
 (0)