caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] [RFC] Remaining changes for cross-compilation support in OCaml
@ 2014-02-18 18:50 Adrien Nader
  2014-02-19  9:51 ` [Caml-list] [RFC] Remaining changes for cross-compilation support oleg
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Adrien Nader @ 2014-02-18 18:50 UTC (permalink / raw)
  To: caml-list

Hi,

Roughly one year ago, late Wojciech Meyer and I started working on the
integration of a set of patches aimed at enabling the OCaml compiler to
be used for cross-compilation.

Some of the patches so far have caused issues to some people. The goal
of this RFC and email thread is to raise awareness of the upcoming work
and its implications and also to start getting feedback as early as
possible. The patches should be handled through the github interface
which Gabriel Scherer mentionned a few weeks ago.


******************************** Note ********************************
The words "target", "host" and "build" below have the meaning that the
GNU project gives them when it comes to compilation.
When compiling an application or library:
- build: the system the compilation process runs on
- host: the system that will run the binaries that are built
- target: meaningless
When compiling a cross-compiler:
- build: the system the compilation process runs on
- host: the system that will run the binaries that are built (i.e. the
  cross-compiler)
- target: the system for which the cross-compiler builds binaries


*************************** Immediate Goals ***************************
- build "${target}-ocamlc", "${target}-ocamlopt", ..., i.e. a
  cross-compiler for ${target}
- typical cross-compilation of projects is expected to go through
  ocamlfind; in practice, oasis-based projects can be cross-compiled
  with no change


**************************** Further Goals ****************************
- cross-compile the compiler: build a native Windows toolchain on Linux
- canadian cross support: ${build}, ${target}, ${host} are all
  different, i.e. on Linux, build a toolchain that runs on Windows 64b
  but targets Windows 32b or a different architecture/OS like ARM Linux.


*************************** Current status ***************************
- the compiler makes few assumptions about the target; this is very
  good.
- build system is fairly large, has been in flux because of the
  separation of labltk and camlp4, supports both GNU make and BSD's
  makes (i.e. it uses no extension beyong POSIX), some things are split
  between "Makefile" and "Makefile.nt" (and for the ".nt" variant, only
  GNU make is supported and these files do use GNU make extensions).
- most of the patches I ended up with have been upstreamed; a couple
  hairy ones are left and one in particular caused issues when
  bootstrapping.


****************************** Approach ******************************

*** A cross-compiler requires a native toolchain of the same version ***
A working _native_ compiler toolchain of the _exact_ same version as the
cross-toolchain is needed, both when building the cross-toolchain and
when using it; the main reason was camlp4 but I believe it is still a
valid restriction


*** Give up the restriction to POSIX for makefiles ***
Either remove compatibility with BSD makes, or move GNU-make-isms to
"GNUMakefile", BSD-makes-isms to "BSDMakefile" and common data to
"Makefile.common" with the GNU/BSDMakefile files being the
"entrypoints".

The manual page for GNU make states (and mk is similar but with
BSDMakefile iirc):
  "If no -f option is  present, make  will  look for the makefiles
  GNUmakefile, makefile, and Makefile, in that order."

However, separating the code which benefits from the extension requires
that:
- the amount of non-shared code (i.e. the size of GNUmakefile and
  BSDMakefile files) is small and at least the data can be shared; this
  is meant for a few specific functions that are currently shelled-out
  because they are too difficult to write in POSIX make
- most BSDs, if not all, can be supported without workarounds, kludges
  or additional hurdles caused by their fragmentation (for instance,
  OpenBSD's pmake is 10-years late compared to NetBSD's and has
  several bugs that are long solved in NetBSD)


*** Use configure-defined variables instead of "ocaml{c,opt}"... ***
The creation of the cross-compiler will rely on a native toolchain on
${build}. As such, ./configure will locate that toolchain and store its
paths. This forbids any call like "./ocamlopt"; everything must rely on
the paths found by configure.


*** Use Int64.t in the compiler instead of Nativeint ***
Currently, OCaml uses Nativeint to handle all the integers in the code
that is being compiled. The "native" is for ${build}, not for ${target}.

With a 64b host and 32b target, OCaml will output its values over 64
bits in the assembly and ld will then complain and truncate them.

Move to Int64.t instead and delay the conversion to the right bitness
until code emiting. The following types change: Cmm.expression,
Cmm.data_item, Arch.specific_operation, Mach.operation. After that it's
mostly a matter of fixing the type errors (around 50); since I do not
have all the platforms that OCaml supports, I need to devise a way to
compile the files for the other architectures too as a quick test.

(types to change: Cmm.{expression,data_item}, Arch.specific_operation,
Mach.operation)

*** For bytecode, assume C libraries contain the required primitives ***

When doing linking for bytecode with -custom, OCaml will dlopen() the
corresponding library and dlsym() the primitive as an early check for
their availability at runtime.

Quite obviously, this fails for cross-compilation and the only solution
I can think of is to disable the check completely. I have already
written the corresponding patch; it adds 4 trivial lines and changes
one.

*** Devil is in the details ***

While I wish the list above was exhaustive, I know for sure that it
isn't, partly because some of the changes needed are implementation
details more than general approaches. Do not hesitate to ask for
clarification on anything you might wonder.

-- 
Adrien Nader


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2014-02-22 20:24 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-18 18:50 [Caml-list] [RFC] Remaining changes for cross-compilation support in OCaml Adrien Nader
2014-02-19  9:51 ` [Caml-list] [RFC] Remaining changes for cross-compilation support oleg
2014-02-20 11:03 ` [Caml-list] [RFC] Remaining changes for cross-compilation support in OCaml Goswin von Brederlow
2014-02-21  7:19   ` Adrien Nader
2014-02-20 16:53 ` Xavier Leroy
2014-02-21  0:06   ` Anil Madhavapeddy
2014-02-21  7:06     ` Adrien Nader
2014-02-21  1:44   ` Francois Berenger
2014-02-21  7:53   ` Adrien Nader
2014-02-21 11:56     ` Benoît Vaugon
2014-02-21 12:52       ` Mark Shinwell
2014-02-22 14:17         ` Adrien Nader
2014-02-22 14:30       ` Adrien Nader
2014-02-22 15:16         ` Gabriel Kerneis
2014-02-22 20:24           ` Richard W.M. Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).