Changes between Version 6 and Version 7 of CrossCompilation


Ignore:
Timestamp:
Jul 19, 2010 11:54:29 AM (4 years ago)
Author:
simonmar
Comment:

expand description

Legend:

Unmodified
Added
Removed
Modified
  • CrossCompilation

    v6 v7  
    1111 * Other porting tasks might be easier, given a suitable cross-compilation toolchain. 
    1212 
    13 In general, we have: 
     13By way of example, let's suppose we have an x86/Linux platform and we want to cross-compile to PPC64/OSX.  Then our build is going to look like this: 
    1414 
    15 ||               ||Overall build||Stage 1||Compiler RTS||Stage 2||Code RTS|| 
    16 ||Build platform ||Build        ||Build  ||(Build)     ||Build  ||(Build) || 
    17 ||Host platform  ||Host         ||Build  ||(Build)     ||Host   ||(Host)  || 
    18 ||Target platform||Target       ||Host   ||Host        ||Target ||Target  || 
     15|| '''Compiler'''      || '''Runs on'''    || '''Generates code for''' || 
     16|| Stage 0       || x86/Linux  || x86/Linux          || 
     17|| Stage 1       || x86/Linux  || PPC64/OSX          || 
     18|| Stage 2       || PPC64/OSX  || PPC64/OSX          || 
    1919 
    20 In the special case where we are using cross compilation to bootstrap a new platform, we have Host=Target: 
     20Where stage 0 is the bootstrap compiler (the one you specify using `--with-ghc` when configuring the build), and stages 1 and 2 are the compilers being built. 
    2121 
    22 ||               ||Overall build||Stage 1||RTS    ||Stage 2|| 
    23 ||Build platform ||Build        ||Build  ||(Build)||Build  || 
    24 ||Host platform  ||Target       ||Build  ||(Build)||Target || 
    25 ||Target platform||Target       ||Target ||Target ||Target || 
     22Now some general nomenclature: 
    2623 
    27 In the special case where we are building a cross-compiler running on our current platform, we have Host=Build: 
     24 * '''Build platform''': the platform on which the software is being built 
     25 * '''Host platform''': the platform on which the software will run 
     26 * '''Target platform''': for a compiler, the platform on which the generated code will run 
    2827 
    29 ||               ||Overall build||Stage 1||Compiler RTS||Stage 2||Code RTS|| 
    30 ||Build platform ||Build        ||Build  ||(Build)     ||Build  ||(Build) || 
    31 ||Host platform  ||Build        ||Build  ||(Build)     ||Build  ||(Build) || 
    32 ||Target platform||Target       ||Build  ||Build       ||Target ||Target  || 
     28These correspond to CPP symbols that are defined when compiling both Haskell and C code: 
     29 
     30 * ''xxx''`_BUILD_ARCH`, ''xxx''`_BUILD_OS`: the build platform 
     31 * ''xxx''`_HOST_ARCH`, ''xxx''`_HOST_OS`: the host platform 
     32 * ''xxx''`_TARGET_ARCH`, ''xxx''`_TARGET_OS`: the target platform 
     33 
     34The important thing to realise about the 2-stage bootstrap is that each stage has a different notion of build/host/target: these CPP symbols will map to different things when compiling stage 1 and stage 2.  Furthermore that RTS and libraries also have a notion of build and host (but not target: they don't generate code). 
     35 
     36The overall build has a build/host/target, supplied on the `configure` command line: 
     37 
     38  `$ ./configure --build=`''build''` --host=`''host''` --target=`''target'' 
     39 
     40And here is how we map those platforms onto the platforms used by the different stages, and the RTS and libraries: 
     41 
     42||                      ||'''Overall build''' ||'''Stage 0''' || '''Stage 1''' || '''Stage 2'''   || '''libs-host''' || '''libs-target''' || 
     43||'''Build platform'''  ||''build''       ||''build'' || ''build'' || ''build''   || ''build''   || ''build'' || 
     44||'''Host platform'''   ||''host''        ||''build'' || ''build'' || ''host''    || ''host''    || ''target'' || 
     45||'''Target platform''' ||''target''      ||''build'' || ''host''  || ''target''  || ---       || --- || 
     46 
     47Where '''libs-host''' refers to the libraries and RTS that we are building to link with the stage 2 compiler, and '''libs-target''' refers to the libraries and RTS that will be linked with binaries built by the stage 2 compiler to run on the target platform. 
     48 
     49In the special case where we are using cross compilation to bootstrap a new platform, as in the above example, we have ''host'' == ''target'': 
     50 
     51||               ||'''Overall build'''||'''Stage 1'''||'''Stage 2'''||'''libs-host'''|| 
     52||'''Build platform''' ||''build''   ||''build''  ||''build''  ||''build''  || 
     53||'''Host platform'''  ||''target''  ||''build''  ||''target'' ||''target'' || 
     54||'''Target platform'''||''target''  ||''target'' ||''target'' ||         || 
     55 
     56Note that with ''host'' == ''target'', '''libs-host''' == '''libs-target''', so we only need to build the RTS and libraries once (fortunately, because the GHC build system only supports building them once). 
     57 
     58Suppose we wanted to build a cross-compiler to run on the current platform.  Then we could configure with ''build'' == ''host'', but ''target'' is different: 
     59 
     60||               ||'''Overall build'''||'''Stage 1'''||'''Stage 2'''||'''libs-host'''||'''libs-target''' 
     61||'''Build platform''' ||''build''   ||''build''  ||''build''  ||''build'' ||''build'' || 
     62||'''Host platform'''  ||''build''   ||''build''  ||''build''  ||''build'' ||''target'' || 
     63||'''Target platform'''||''target''  ||''build''  ||''target'' ||          || || 
     64 
     65Note in this configuration that we need both '''libs-host''' and '''libs-target''', so currently the GHC build system does not support building this kind of cross-compiler.  Fortunately, most of the things you would want to do with this kind of cross-compiler are supported by the first kind, the only caveat is that you can't ''install'' a cross-compiler that way. 
    3366 
    3467== Plan ==