Portability of OCaml bytecode
Asked Answered
D

1

5

I compile an OCaml program in bytecode on an x86 machine, and transfer the bytecode to a ppc64 machine. Assuming that the ppc64 machine has ocamlrun (compiled for ppc64), will I be able to execute my program on the ppc64 architecture ? Is it that simple ?

In other terms, is the bytecode resistant to endianness ?

If not, then what is the purpose of the bytecode ?

Dependence answered 15/1, 2016 at 15:5 Comment(0)
E
9

I assume you don't need any external function; otherwise of course you need the binary code providing them.

Yes, the bytecode is resistant to endianness (and to word size), for systems supported by Ocaml.

(however, your bytecode may depend upon the particular version of ocamlrun interpreter and the Pervasives module used by your program; hence, a bytecode for Ocaml 4.01 might not run in Ocaml 4.02 runtime or vice versa; YMMV)

In particular when you build Ocaml from its source code, it is compiling itself with a distributed version (in boot/ subdirectory ...) of ocamlc - which is a bytecode file.

And Ocaml folks badly need that portability, since most of the Ocaml compiler is written in Ocaml itself and is bootstrapped.

See also J.Pitrat's blog on meta-bugs, curse of the bootstrap which indirectly explains why updating that boot/ocamlc file has to be done rarely and carefully by Ocaml team. Within the Ocaml code, make bootstrap has to be done occasionally and very carefully (at least to commit a newer version of boot/ocamlc bytecode file).

Emblements answered 15/1, 2016 at 15:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.