Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: operand size mismatch for `movzb' for 32+bit compiler #11803

Closed
ejgallego opened this issue Dec 9, 2022 · 2 comments
Closed

Error: operand size mismatch for `movzb' for 32+bit compiler #11803

ejgallego opened this issue Dec 9, 2022 · 2 comments

Comments

@ejgallego
Copy link

ejgallego commented Dec 9, 2022

Dear OCaml devs,

when compiling coq-serapi in 32bit OCaml we are seeing this:

$ dune build -p coq-serapi
File "serlib/.serlib.objs/native/_unknown_", line 1, characters 0-0:
(cd _build/default && /home/egallego/.opam/jscoq+32bit/bin/ocamlopt.opt -w -40 -rectypes -g -ppx '.ppx/341932708445810a638020e478ebc4f1/ppx.exe --as-ppx --cookie '\''library-name="serlib"'\''' -I serlib/.serlib.objs/byte -I serlib/.serlib.objs/native -I /home/egallego/.opam/jscoq+32bit/lib/base -I /home/egallego/.opam/jscoq+32bit/lib/base/base_internalhash_types -I /home/egallego/.opam/jscoq+32bit/lib/base/caml -I /home/egallego/.opam/jscoq+32bit/lib/base/shadow_stdlib -I /home/egallego/.opam/jscoq+32bit/lib/findlib -I /home/egallego/.opam/jscoq+32bit/lib/ocaml/threads -I /home/egallego/.opam/jscoq+32bit/lib/parsexp -I /home/egallego/.opam/jscoq+32bit/lib/ppx_compare/runtime-lib -I /home/egallego/.opam/jscoq+32bit/lib/ppx_deriving/runtime -I /home/egallego/.opam/jscoq+32bit/lib/ppx_deriving_yojson/runtime -I /home/egallego/.opam/jscoq+32bit/lib/ppx_hash/runtime-lib -I /home/egallego/.opam/jscoq+32bit/lib/ppx_sexp_conv/runtime-lib -I /home/egallego/.opam/jscoq+32bit/lib/result -I /home/egallego/.opam/jscoq+32bit/lib/seq -I /home/egallego/.opam/jscoq+32bit/lib/sexplib -I /home/egallego/.opam/jscoq+32bit/lib/sexplib0 -I /home/egallego/.opam/jscoq+32bit/lib/yojson -I /home/egallego/.opam/jscoq+32bit/lib/zarith -I /home/egallego/external/coq-master/_build/install/default/lib/coq-core/boot -I /home/egallego/external/coq-master/_build/install/default/lib/coq-core/clib -I /home/egallego/external/coq-master/_build/install/default/lib/coq-core/config -I /home/egallego/external/coq-master/_build/install/default/lib/coq-core/coqworkmgrapi -I /home/egallego/external/coq-master/_build/install/default/lib/coq-core/engine -I /home/egallego/external/coq-master/_build/install/default/lib/coq-core/gramlib -I /home/egallego/external/coq-master/_build/install/default/lib/coq-core/interp -I /home/egallego/external/coq-master/_build/install/default/lib/coq-core/kernel -I /home/egallego/external/coq-master/_build/install/default/lib/coq-core/lib -I /home/egallego/external/coq-master/_build/install/default/lib/coq-core/library -I /home/egallego/external/coq-master/_build/install/default/lib/coq-core/parsing -I /home/egallego/external/coq-master/_build/install/default/lib/coq-core/pretyping -I /home/egallego/external/coq-master/_build/install/default/lib/coq-core/printing -I /home/egallego/external/coq-master/_build/install/default/lib/coq-core/proofs -I /home/egallego/external/coq-master/_build/install/default/lib/coq-core/stm -I /home/egallego/external/coq-master/_build/install/default/lib/coq-core/sysinit -I /home/egallego/external/coq-master/_build/install/default/lib/coq-core/tactics -I /home/egallego/external/coq-master/_build/install/default/lib/coq-core/vernac -I /home/egallego/external/coq-master/_build/install/default/lib/coq-core/vm -intf-suffix .ml -no-alias-deps -open Serlib -o serlib/.serlib.objs/native/serlib__Ser_glob_term.cmx -c -impl serlib/ser_glob_term.ml)
/tmp/build_15c8bd_dune/camlasmcddc6e.s: Assembler messages:
/tmp/build_15c8bd_dune/camlasmcddc6e.s:10336: Error: operand size mismatch for `movzb'
File "serlib/ser_glob_term.ml", line 1:
Error: Assembler error, input left in file /tmp/build_15c8bd_dune/camlasmcddc6e.s

this was first detected by opam CI system. To reproduce try to build coq-serapi as above. Note that a dune build with the dev profile doesn't trigger this error. I can reproduce in 4.12 and 4.14

cc #10626 cc @kit-ty-kate

@gasche
Copy link
Member

gasche commented Dec 9, 2022

cc @lthls : you did wonders on #10626, maybe this one will be cake for you?

@lthls
Copy link
Contributor

lthls commented Dec 11, 2022

It looks like a mistake in the compilation of integer comparison instructions, specifically the ones not used as tests (for example, Int.compare x y is compiled as (x > y) - (x < y)).
These comparisons are compiled to:

      I.cmp (arg i 1) (arg i 0);
      I.set (cond cmp) al;
      I.movzx al (res i 0)

The last move is illegal when the result is allocated on the stack. In theory the bug also occurs on amd64, but I suspect that due to the larger number of available registers we would need even more complex (or bigger) code to trigger the issue (I tried a bit to trigger this case but didn't get anywhere; I suspect the superpressure heuristics are preemptively spilling enough registers that the allocator never needs to allocate on the stack afterwards).
One possible fix would be to use a different move instruction when the result is on the stack, another would be to restrict the allowed locations for comparisons in {amd64,i386}/reload.ml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants