From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id EC4EA7FC6B for ; Thu, 8 Oct 2015 11:53:13 +0200 (CEST) IronPort-PHdr: 9a23:EVPKSBw3H6QiBZvXCy+O+j09IxM/srCxBDY+r6Qd0eIQIJqq85mqBkHD//Il1AaPBtWHra0ZwLOH+4nbGkU+or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6anHS+4HYoFwnlMkItf6KuStKU0Jn8jrH60qaQSjsLrQL1Wal1IhSyoFeZnegtqqwmFJwMzADUqGBDYeVcyDAgD1uSmxHh+pX4p8Y7oGx48sgs/M9YUKj8Y79wDfkBVGxnYCgJ45jQqRTNRA3HxnYYVmgMlxNOBUCR9w33UJ73mjf6u7B40TKGMNftC7w5D2eM9aBuHTnpgyADPiVx12PahsU4pqtB6Ean4Rt9zsjeaZu9O/93f6ebdtQfEzkSFv1NXjBMV9vvJ7AECPAMaKMB99Hw Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=n.oje.bar@gmail.com; spf=Pass smtp.mailfrom=n.oje.bar@gmail.com; spf=None smtp.helo=postmaster@mail-wi0-f170.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of n.oje.bar@gmail.com) identity=pra; client-ip=209.85.212.170; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="n.oje.bar@gmail.com"; x-sender="n.oje.bar@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of n.oje.bar@gmail.com designates 209.85.212.170 as permitted sender) identity=mailfrom; client-ip=209.85.212.170; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="n.oje.bar@gmail.com"; x-sender="n.oje.bar@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wi0-f170.google.com) identity=helo; client-ip=209.85.212.170; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="n.oje.bar@gmail.com"; x-sender="postmaster@mail-wi0-f170.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0B8AwDHPBZWlKrUVdFEGhaDMDVuBrE4jBaBWiGCcoIKfwKBPQc5EwEBAQEBAQEBEAEBAQEHCwsJHzCCH4IIAQEDARIRHQEbHQEDAQsGBQs3AgIiAREBBQEcBhMih3YBAwoIDTufcIExPjGLSYFsgnmJUQoZJw1WhE8BAQEBAQUBAQEBAQEWAQUOhmaDd4EGhQkEB4JpgUUFlgiFGId/gVdIg3GOKoNPgiMSI4EXERIBgh8kDRYHgVY8MwGHawEBAQ X-IPAS-Result: A0B8AwDHPBZWlKrUVdFEGhaDMDVuBrE4jBaBWiGCcoIKfwKBPQc5EwEBAQEBAQEBEAEBAQEHCwsJHzCCH4IIAQEDARIRHQEbHQEDAQsGBQs3AgIiAREBBQEcBhMih3YBAwoIDTufcIExPjGLSYFsgnmJUQoZJw1WhE8BAQEBAQUBAQEBAQEWAQUOhmaDd4EGhQkEB4JpgUUFlgiFGId/gVdIg3GOKoNPgiMSI4EXERIBgh8kDRYHgVY8MwGHawEBAQ X-IronPort-AV: E=Sophos;i="5.17,654,1437429600"; d="scan'208";a="181722373" Received: from mail-wi0-f170.google.com ([209.85.212.170]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 08 Oct 2015 11:52:58 +0200 Received: by wiclk2 with SMTP id lk2so17230141wic.1 for ; Thu, 08 Oct 2015 02:52:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=rKiEt3RXlMXya4hxZXAAdmKJJkYzsblltbzDI10zCwo=; b=w6XrZnW6dw/gZ+kyyeMeayVRo99X4vz3Z+EavLzHf702EzI20getYnmSdmJzxrUCAz 6weVc85Cdc5mL385maGiA2BBkRIowORxIlrY8uOGFky8OpqHwq7CkP1p2Rk+ccZbNajj /y+XxPOIJUjHKUnMucg99yt+TSYj4KPyg6cVbf+lAcNx5uRZah23PQc2iRmKn+D5z6iH c3KquZC6w/eaGa70sMuJudrJ6SkRwhUL0fScbrjpSvj4S5VZABEI140zqwe94MVSQ1vn y4ao13WCRc2JYuN/E4+WSQFEkZYN9/GbkmPXoUloZHbQ7Nnwnzom865kSPr+eVYOa+S9 YJZg== MIME-Version: 1.0 X-Received: by 10.180.103.167 with SMTP id fx7mr2696351wib.89.1444297978335; Thu, 08 Oct 2015 02:52:58 -0700 (PDT) Received: by 10.194.42.1 with HTTP; Thu, 8 Oct 2015 02:52:58 -0700 (PDT) In-Reply-To: References: Date: Thu, 8 Oct 2015 11:52:58 +0200 Message-ID: From: Nicolas Ojeda Bar To: Stefan Hellermann Cc: caml-list@inria.fr Content-Type: multipart/alternative; boundary=f46d04428674f2db89052194d38e Subject: Re: [Caml-list] Broken 32 bit cross-compiler on 64bit host --f46d04428674f2db89052194d38e Content-Type: text/plain; charset=UTF-8 Dear Stefan, I believe it is currently impossible to build a working cross-compiler between different word sizes, as the compiler does not differentiate between the host and the target's native integers. Best wishes, Nicolas On Thu, Oct 8, 2015 at 11:43 AM, Stefan Hellermann wrote: > Hello, > > currently I'm trying to add OCaml to the openwrt router distribution [1] > [2]. This would mean you could run your favorite OCaml applications on your > router. I would like to run unison [3] on my router. > > So I first build native OCaml 4.02.3 on my x86_64 linux host, and then > build a OCaml cross-compiler for the 32 bit target, e.g. > mips-openwrt-linux. Building OCaml went fine after adding a small patch to > manually set Endianness and Bitness in configure script, please have a look > at attached patch. > > host OCaml configure line: > ./configure -prefix somepath -no-pthread -no-debugger -no-ocamldoc > -no-graph -no-cfi > cross OCaml configure line: > ./configure -prefix someotherpath -target-bindir /usr/bin -host > x86_64-unknown-linux-gnu -target mips-openwrt-linux-musl -cc > "mips-openwrt-linux-musl-gcc some target cflags" -as > "mips-openwrt-linux-musl-as some target as flags" -no-pthread > -no-shared-libs -no-debugger -no-ocamldoc -no-graph -no-cfi -big-endian > > > Now the bug: When running OCaml applicantions (build with -custom), they > crash on startup on the target: > > Fatal error: exception Failure("input_value: integer too large") > > > This is similar to OCaml Bug #5977 [4] > > There is a workaround: > Build the host OCaml as 32 bit OCaml, then build the cross compiler with > this 32 bit host OCaml. The resulting binaries work on the target. > This is what I did for openwrt [2], but it fails on 64 bit hosts where no > 32 bit development tools are installed. It only catches the case when > building on x86_64 hosts, it will break when building on say powerpc64 or > 64 bit arm. It's also problematic for openwrt, as only the cross compiler > but not the host tools are recompiled if the target arch changes, e.g. from > 64 bit arm to 32 bit mips. > > Now my questions: > - Is building a 32 bit cross compiler on a 64 bit host supposed to work? > - Is my patch to configure ok, or is there a better way to configure the > cross-compiler? > - Should I run some test suite on the target and post the results? > > [WARNING] Something went wrong while checking native division and modulus > please report it at http://http://caml.inria.fr/mantis/ > Do I have to care? > I tried defining and undefining NONSTANDARD_DIV_MOD in m.h. without any > visible difference. Running the test-prog divmod.c on a few targets always > returns 0. > > [1] https://openwrt.org/ > [2] https://patchwork.ozlabs.org/patch/518982/ > [3] https://www.cis.upenn.edu/~bcpierce/unison/ > [4] http://caml.inria.fr/mantis/view.php?id=5977 > > > --f46d04428674f2db89052194d38e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Dear Stefan,

I believe it is curren= tly impossible to build a working cross-compiler between different word siz= es, as the compiler does not differentiate between the host and the target&= #39;s native integers.

Best wishes,
Nico= las


On Thu, Oct 8, 2015 at 11:43 AM, Stefan Hellermann <ste= fan@the2masters.de> wrote:
=
Hello,
currently I'm trying to add OCaml to the openwrt router dis= tribution [1] [2]. This would mean you could run your favorite OCaml applic= ations on your router. I would like to run unison [3] on my router.

=
So I first build native OCaml 4.02.3 on my x86_64 linux host, and the= n build a OCaml cross-compiler for the 32 bit target, e.g. mips-openwrt-lin= ux. Building OCaml went fine after adding a small patch to manually set End= ianness and Bitness in configure script, please have a look at attached pat= ch.

host OCaml configure line:
./configure = -prefix somepath -no-pthread -no-debugger -no-ocamldoc -no-graph -no-cfi
cross OCaml configure line:
./configure -prefix s= omeotherpath -target-bindir /usr/bin -host x86_64-unknown-linux-gnu -target= mips-openwrt-linux-musl -cc "mips-openwrt-linux-musl-gcc some target = cflags" -as "mips-openwrt-linux-musl-as some target as flags"= ; -no-pthread -no-shared-libs -no-debugger -no-ocamldoc -no-graph -no-cfi -= big-endian


Now the bug: When running OCaml appl= icantions (build with -custom), they crash on startup on the target:
Fatal error: exception Failure("input_value: integer too large")=


This is similar to OCaml Bug #5977 [4]

There= is a workaround:
Build the host OCaml as 32 bit OCaml, then build= the cross compiler with this 32 bit host OCaml. The resulting binaries wor= k on the target.
This is what I did for openwrt [2], but it fails on 64 = bit hosts where no 32 bit development tools are installed. It only catches = the case when building on x86_64 hosts, it will break when building on say = powerpc64 or 64 bit arm. It's also problematic for openwrt, as only the= cross compiler but not the host tools are recompiled if the target arch ch= anges, e.g. from 64 bit arm to 32 bit mips.

Now my questions:<= br>- Is building a 32 bit cross compiler on a 64 bit host supposed to work?=
- Is my patch to configure ok, or is there a better way to config= ure the cross-compiler?
- Should I run some test suite on the= target and post the results?

[WARNING] Someth= ing went wrong while checking native division and modulus please report it = at http://http:/= /caml.inria.fr/mantis/
Do I have to care?
I tried defining = and undefining NONSTANDARD_DIV_MOD in m.h. without any visible difference. = Running the test-prog divmod.c on a few targets always returns 0.

[1= ] https://openwrt.org/
[2]
https://patchwork.ozlabs.org/patch/518982/
[3] https://www.ci= s.upenn.edu/~bcpierce/unison/
[4] http://caml.inria.fr/mantis/view= .php?id=3D5977



--f46d04428674f2db89052194d38e--