mirage / ocaml-solo5

Freestanding OCaml runtime
Other
101 stars 30 forks source link

Floating point issue #110

Closed palainp closed 2 years ago

palainp commented 2 years ago

I'm not really sure if this issue is related to ocaml-freestanding or solo5 or xen or qubes, sorry for the disturbance if I misplaced the issue here. Actually, I have #MF (floating point exception) error from solo5 with this unikernel (compiled with mirage 4.0~beta3):

$ cat unikernel.ml 
open Lwt.Infix

module Hello (Time : Mirage_time.S) = struct
  let start _time =
    Logs.info (fun f -> f "total runtime 1 %.6f s" 0.5);
    Logs.info (fun f -> f "total runtime 2 %.6f s" 1.0);
    Logs.info (fun f -> f "total runtime 3 %.6f s" 0.75);
    Logs.info (fun f -> f "total runtime 4 %.6e s" 0.5);
    Logs.info (fun f -> f "total runtime 5 %.6e s" 0.25);
    Logs.info (fun f -> f "total runtime 6 %.6e s" 0.875);
    Logs.info (fun f -> f "total runtime 7 %.6e s" 0.6);
    Logs.info (fun f -> f "total runtime 8 %.6e s" 0.4);
    Time.sleep_ns (Duration.of_sec 1) >>= fun () ->
    Lwt.return_unit
end
$ cat config.ml 
open Mirage

let main =
  foreign
    "Unikernel.Hello" (time @->job)

let () =
  register "hello" [main $ default_time]

It works well with the x*1/2^y prints but fails on the first 0.6 print. The faulting address is on a fldz instruction ("add 0 to the FPU stack") which is due to something around the compilation of https://github.com/mirage/ocaml-freestanding/blob/7e85ff780deba6f526ff53445b5a0bd4ac6fd86e/nolibc/vfprintf.c#L236 I was not able to recompile ocaml-freestanding with -msoft-float. If needed the kernel can be found there : https://we.tl/t-DEeIN7TW80 (md5sum: 982d75122f9346b0101510c4a5644252) One strange thing is that it works fine with Xen 4.8 (Qubes 4.0.4) but not with Xen 4.14 (Qubes 4.1), I'm not sure if something is broken between these two versions.

palainp commented 2 years ago

In addition, compilation and execution with spt work as expected.

dinosaure commented 2 years ago

Hope that it will be fixed with #111 but I will let this issue open to let you to recheck with the next release of ocaml-freestanding if it's work or not.

palainp commented 2 years ago

I can confirm that it works fine with qubes-mirage-firewall now (which was the starting point for that issue).