Cross-compilation x64 -> x86 easier under Ubuntu 11.10 with multiarch?

Hi cafe, Ubuntu 11.10 has been released, which includes support for "multiarch" https://wiki.ubuntu.com/MultiarchSpec Am I right that this will facilitate compiling Haskell code into x86 binaries on an x64 machine? -- Eugene Kirpichov Principal Engineer, Mirantis Inc. http://www.mirantis.com/ Editor, http://fprog.ru/

On Thu, Oct 13, 2011 at 11:43 AM, Eugene Kirpichov
Hi cafe,
Ubuntu 11.10 has been released, which includes support for "multiarch" https://wiki.ubuntu.com/MultiarchSpec
Am I right that this will facilitate compiling Haskell code into x86 binaries on an x64 machine?
This would make it easier, but GHC is not a cross-compiling compiler, so you'd still need to install a separate GHC executable for 32-bit compiling. This makes it so that apt can handle installing the 32-bit libraries to link against in a sane way, which I'm sure helps. Antoine

On Thu, Oct 13, 2011 at 12:07 PM, Antoine Latter
On Thu, Oct 13, 2011 at 11:43 AM, Eugene Kirpichov
wrote: Hi cafe,
Ubuntu 11.10 has been released, which includes support for "multiarch" https://wiki.ubuntu.com/MultiarchSpec
Am I right that this will facilitate compiling Haskell code into x86 binaries on an x64 machine?
This would make it easier, but GHC is not a cross-compiling compiler, so you'd still need to install a separate GHC executable for 32-bit compiling.
This makes it so that apt can handle installing the 32-bit libraries to link against in a sane way, which I'm sure helps.
Ah, I was assuming here that multi-arch support only covered libraries, not applications and tools. It looks like some applications will be flagged as multiarch, so maybe you'll be able to install two GHCs side-by-side with apt. Interesting!
Antoine

On Thu, Oct 13, 2011 at 12:15 PM, Antoine Latter
Ah, I was assuming here that multi-arch support only covered libraries, not applications and tools.
Never-mind again! Co-installation of executable packages is listed as an "Unresolved issue". So you'd need to install a separate GHC yourself, and handle paths somehow. Antoine

Hello!
2011/10/13 Antoine Latter
It looks like some applications will be flagged as multiarch, so maybe you'll be able to install two GHCs side-by-side with apt.
I used x64 edition of Ubuntu 11.10 for a while, and was able to run both 64-bit and 32-bit GHCs. Both GHCs were manually set-up (i.e. download; tar xvjf ...; ./configure --prefix=...; make install) All is needed is to install both versions of libgmp by "apt-get install libgmp3-dev lib32gmp-dev" 32-bit version runs ghci fine, but I actually cannot compile stuff with it. Haven't looked deeply into that issue, though. The error is like the following: *** Assembler: /usr/bin/gcc -I.. -c /tmp/ghc6285_0/ghc6285_0.s -o ../Test.o -fno-stack-protector -DDONT_WANT_WIN32_DLL_SUPPORT /tmp/ghc6285_0/ghc6285_0.s: Assembler messages: /tmp/ghc6285_0/ghc6285_0.s:29:0: Error: invalid instruction suffix for `push' Maybe the issue can be resolved by figuring out how to target gcc for 32-bit build.

A quick follow-up
2011/10/13 Michael Lazarev
I used x64 edition of Ubuntu 11.10 for a while, and was able to run both 64-bit and 32-bit GHCs. Both GHCs were manually set-up (i.e. download; tar xvjf ...; ./configure --prefix=...; make install) All is needed is to install both versions of libgmp by "apt-get install libgmp3-dev lib32gmp-dev"
32-bit version runs ghci fine, but I actually cannot compile stuff with it.
It turns out that it is also possible to compile a 32-bit executable by 32-bit ghc under Ubuntu 11.10 x64. First, additional files supporting compilation for different architectures in gcc must be installed by "sudo apt-get install g++multilib". Second, one need to pass additional arguments to ghc: "-opta -m32 -optl -m32". They are, in turn, passed to gcc assembler and linker, respectively, telling them to build for 32-bit architecture. Complete example: ---------------------------------------------------------------------- $ sudo apt-get install lib32gmp-dev g++multilib $ cat ./Test.hs module Main where import Control.Monad getR :: Read r => IO r getR = liftM read getLine main = liftM2 (+) getR getR >>= print $ /home/ml/local/ghc/7.0.4-32/bin/ghc --make ./Test.hs -opta -m32 -optl -m32 Linking Test ... $ file ./Test ./Test: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped ---------------------------------------------------------------------- Hope that helps. It is also interesting to find out how that works with "cabal build" command.

Hi, Am Donnerstag, den 13.10.2011, 22:26 +0400 schrieb Michael Lazarev:
It turns out that it is also possible to compile a 32-bit executable by 32-bit ghc under Ubuntu 11.10 x64. First, additional files supporting compilation for different architectures in gcc must be installed by "sudo apt-get install g++multilib". Second, one need to pass additional arguments to ghc: "-opta -m32 -optl -m32". They are, in turn, passed to gcc assembler and linker, respectively, telling them to build for 32-bit architecture.
Complete example:
----------------------------------------------------------------------
$ sudo apt-get install lib32gmp-dev g++multilib
$ cat ./Test.hs module Main where
import Control.Monad
getR :: Read r => IO r getR = liftM read getLine
main = liftM2 (+) getR getR >>= print
$ /home/ml/local/ghc/7.0.4-32/bin/ghc --make ./Test.hs -opta -m32 -optl -m32 Linking Test ...
$ file ./Test ./Test: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped
----------------------------------------------------------------------
Did you build the boot libraries and possible ghc also with these flags? Greetings, Joachim -- Joachim "nomeata" Breitner mail@joachim-breitner.de | nomeata@debian.org | GPG: 0x4743206C xmpp: nomeata@joachim-breitner.de | http://www.joachim-breitner.de/

2011/10/14 Joachim Breitner
Hi,
Am Donnerstag, den 13.10.2011, 22:26 +0400 schrieb Michael Lazarev:
It turns out that it is also possible to compile a 32-bit executable by 32-bit ghc under Ubuntu 11.10 x64. First, additional files ----------------------------------------------------------------------
Did you build the boot libraries and possible ghc also with these flags?
No, I never built ghc myself. I downloaded binary packages from http://www.haskell.org/ghc/ Also, I didn't try to build any package yet, including boot packages, as I yet have to learn how to make cabal pass -m32 flag to gcc. The most puzzling thing for me now is whether I can use some technique to make cabal pass -m32 flag to gcc for every dependency when building an entire hierarchy of packages, e.g. when cabal-installing yesod.
participants (4)
-
Antoine Latter
-
Eugene Kirpichov
-
Joachim Breitner
-
Michael Lazarev