caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] [RFC] Remaining changes for cross-compilation support in OCaml
Date: Thu, 20 Feb 2014 17:53:35 +0100	[thread overview]
Message-ID: <5306330F.1020401@inria.fr> (raw)
In-Reply-To: <20140218185032.GA20593@notk.org>

Hi Adrien,

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

s/some people/the core OCaml dev team/

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

That could be a nice touch if it's not too much extra work.  The issue
was discussed at the last OCaml dev team meeting that Wojciech
attended, and we agreed that some scenarios were less important than
others, e.g. nobody really needs to compile from a 32-bit host for a
64-bit target.

> ****************************** 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

Perhaps less so now that camlp4 is split off.  The alternative is to
configure for the host, populate boot/ with a ocamlrun and standard
library appropriate for the host, then reconfigure for the target, and
finish the build.

> *** 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 unanimous message from the OCaml dev team is to commit on GNU make
and forget about compatibility with other variants of make.  BSD
people will forgive us, and it looks like the only sane way to merge
the Unix and Windows makefiles and support all the cross-compilation
scenarios.

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

See above: this might not be necessary.

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

Constant propagation and maybe other passes of the compiler also need to
take bitsize into account.

If you're going this way, it's not Int64 the appropriate substitute
for Nativeint: it's Targetint, defined as Int32 or Int64 depending on
target bitsize.  (This can be expressed with first-class modules.)

There might be other ways if we assume bitsize(host) >= bitsize(target).

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

Probably there is no choice.  But it pains me to move link-time errors
to run-time (more exactly, program startup time).  If we program in
OCaml rather than Python, it's also for the early error detection.

- Xavier Leroy

  parent reply	other threads:[~2014-02-20 16:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-18 18:50 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5306330F.1020401@inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).