Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Portability of OCaml bytecode

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 ?

like image 959
Anthony Scemama Avatar asked Jan 07 '23 19:01

Anthony Scemama


1 Answers

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).

like image 111
Basile Starynkevitch Avatar answered Feb 12 '23 16:02

Basile Starynkevitch