From cc57e84cbd4b76936b1daac52a28d5eccfb3bb2d Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Fri, 23 Aug 2019 09:04:34 -0700 Subject: [PATCH] Fix segfault due to b64 encoding (#919) * Fix segfault due to b64 encoding Prior to this patch, bconst.b64 encoded its instruction with a 32-bit immediate that caused improper decoding of the MOV instruction; instead, use a REX prefix and rely on zero-extension of the immediate. Fixes #911. --- cranelift/codegen/meta/src/isa/x86/encodings.rs | 5 +---- .../filetests/filetests/isa/x86/binary64-run.clif | 10 ++++++++++ cranelift/filetests/filetests/isa/x86/binary64.clif | 7 +++++++ 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 cranelift/filetests/filetests/isa/x86/binary64-run.clif diff --git a/cranelift/codegen/meta/src/isa/x86/encodings.rs b/cranelift/codegen/meta/src/isa/x86/encodings.rs index c5bbfe1a83..a71b2cc68f 100644 --- a/cranelift/codegen/meta/src/isa/x86/encodings.rs +++ b/cranelift/codegen/meta/src/isa/x86/encodings.rs @@ -683,10 +683,7 @@ pub fn define( for &ty in &[B1, B8, B16, B32] { e.enc_both(bconst.bind(ty), rec_pu_id_bool.opcodes(vec![0xb8])); } - e.enc64( - bconst.bind(B64), - rec_pu_id_bool.opcodes(vec![0xb8]).rex().w(), - ); + e.enc64(bconst.bind(B64), rec_pu_id_bool.opcodes(vec![0xb8]).rex()); // Shifts and rotates. // Note that the dynamic shift amount is only masked by 5 or 6 bits; the 8-bit diff --git a/cranelift/filetests/filetests/isa/x86/binary64-run.clif b/cranelift/filetests/filetests/isa/x86/binary64-run.clif new file mode 100644 index 0000000000..b255770c1e --- /dev/null +++ b/cranelift/filetests/filetests/isa/x86/binary64-run.clif @@ -0,0 +1,10 @@ +test run +target x86_64 + +; this verifies that returning b64 immediates does not result in a segmentation fault, see https://github.com/CraneStation/cranelift/issues/911 +function %test_b64() -> b64 { +ebb0: +[-, %r10] v0 = bconst.b64 true + return v0 +} +; run diff --git a/cranelift/filetests/filetests/isa/x86/binary64.clif b/cranelift/filetests/filetests/isa/x86/binary64.clif index a65b3d3d1d..7742a24ee3 100644 --- a/cranelift/filetests/filetests/isa/x86/binary64.clif +++ b/cranelift/filetests/filetests/isa/x86/binary64.clif @@ -1642,3 +1642,10 @@ ebb0: return } + +function %B64() { +ebb0: + [-, %rax] v1 = bconst.b64 true ; bin: 40 b8 00000001 + [-, %r10] v0 = bconst.b64 true ; bin: 41 ba 00000001 + return +}