[GHC] #11470: Support changing cross compiler target at runtime

#11470: Support changing cross compiler target at runtime -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Relevant mailing list thread: https://mail.haskell.org/pipermail/ghc- devs/2016-January/011064.html At the moment, GHC's cross-compiling support requires you to build a cross-compiler for every target platform from scratch. (https://ghc.haskell.org/trac/ghc/wiki/CrossCompilation) There are two reasons for this: 1. GHC uses a configure script to interrogate the GCC toolchain about the vagaries of cross-compilation, some parameters of which get baked into various build system scripts and header files and such. Some of this information wends its way into the final built GHC executable. 2. GHC needs to build the boot libraries, using the stage 1 compiler, targeting the cross compiler. It would be very useful to move this configuration from configure time to run time, so that a user can use GHC as a cross-compiler without having to recompile GHC. That is, we would like to (1) ensure that any information from the configure script can alternately be supplemented at runtime, (2) that users can cross-compile the boot libraries on-demand (since GHC won't ship with the ARM versions of the boot libraries), and (3) rearchitect GHC internally so that it handles knows to keep separate the interface files/package database for various cross compilation targets. Such a change will make cross-compiling more convenient (the iOS cross- compiler currently requires GHC to be built twice, once for ARM and once for the simulator!) and will also pave the way for supporting Template Haskell and compiler plugins in the cross-compiler, since a GHC that knows how to deal with both the target and host platforms can simply ensure that it only loads code built for the host platform (a user can then, if necessary, build code twice, once for the host for Template Haskell, and once for the target). Unclear points of design: * How should GHC get the information about the GCC cross-compiler toolchain (which currently is gotten by `configure`?) Preferably, not by running a `configure` script every time you invoke it. What is this information anyway? * How should GHC rebuild the boot libraries? Maybe `cabal-install` can simply handle this for you. Note: please update the top of this ticket as the design becomes clearer. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11470 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11470: Support changing cross compiler target at runtime -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11378 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by ezyang): * related: => #11378 @@ -45,0 +45,4 @@ + + Related tickets: #11378 (an alternate way to implement this without + implementing multitarget support. If this ticket is solved, that ticket is + moot.) New description: Relevant mailing list thread: https://mail.haskell.org/pipermail/ghc- devs/2016-January/011064.html At the moment, GHC's cross-compiling support requires you to build a cross-compiler for every target platform from scratch. (https://ghc.haskell.org/trac/ghc/wiki/CrossCompilation) There are two reasons for this: 1. GHC uses a configure script to interrogate the GCC toolchain about the vagaries of cross-compilation, some parameters of which get baked into various build system scripts and header files and such. Some of this information wends its way into the final built GHC executable. 2. GHC needs to build the boot libraries, using the stage 1 compiler, targeting the cross compiler. It would be very useful to move this configuration from configure time to run time, so that a user can use GHC as a cross-compiler without having to recompile GHC. That is, we would like to (1) ensure that any information from the configure script can alternately be supplemented at runtime, (2) that users can cross-compile the boot libraries on-demand (since GHC won't ship with the ARM versions of the boot libraries), and (3) rearchitect GHC internally so that it handles knows to keep separate the interface files/package database for various cross compilation targets. Such a change will make cross-compiling more convenient (the iOS cross- compiler currently requires GHC to be built twice, once for ARM and once for the simulator!) and will also pave the way for supporting Template Haskell and compiler plugins in the cross-compiler, since a GHC that knows how to deal with both the target and host platforms can simply ensure that it only loads code built for the host platform (a user can then, if necessary, build code twice, once for the host for Template Haskell, and once for the target). Unclear points of design: * How should GHC get the information about the GCC cross-compiler toolchain (which currently is gotten by `configure`?) Preferably, not by running a `configure` script every time you invoke it. What is this information anyway? * How should GHC rebuild the boot libraries? Maybe `cabal-install` can simply handle this for you. Note: please update the top of this ticket as the design becomes clearer. Related tickets: #11378 (an alternate way to implement this without implementing multitarget support. If this ticket is solved, that ticket is moot.) -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11470#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11470: Support changing cross compiler target at runtime -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11378 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by angerman): See also: - https://ghc.haskell.org/trac/ghc/wiki/Building/CrossCompiling/iOS - https://ghc.haskell.org/trac/ghc/wiki/TemplateHaskell - https://ghc.haskell.org/trac/ghc/wiki/TemplateHaskell/CrossCompilation -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11470#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11470: Support changing cross compiler target at runtime -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11378 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by Ericson2314): * cc: john_ericson@… (removed) * cc: Ericson2314 (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11470#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11470: Support changing cross compiler target at runtime -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11378 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by chak): * cc: chak (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11470#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11470: Support changing cross compiler target at runtime -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11378 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by Iceland_jack): * cc: Iceland_jack (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11470#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11470: Support changing cross compiler target at runtime -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11378 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by rwbarton): * cc: rwbarton (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11470#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11470: Support changing cross compiler target at runtime -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11378 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by luite): I'd be happy to help with this. Fortunately there is not all that much information about the target platform hardcoded in GHC anymore. I think a new cross compilation target could be added by pointing GHC to some target-specific `settings` file. This file should also specify how to run TH and GHCi (for example via the external interpreter for general TH and by loading code from another package DB for host-only TH) We would create an `initialize-target` tool that: * queries the toolchain and generates an appropriate `settings` file * (possibly) builds an initial set of packages for the target, similar to what ships with GHC I think this is still reasonably straightforward, and I think it would be a good first step, and would mainly involve separating part of the build system and making sure that all relevant configuration options can indeed be specified by `settings`. This should allow cross compilers to load native code for plugins (the code generator for the target could even be a plugin). For the next step, my main concern would be how to match up the host and target architecture package databases for things like host-only TH. Say a cross compiler needs to run some host-only TH, which means it probably needs to load some code from a host-arch package DB: * Who is responsible for the code to be there? Will `cabal-install` make sure that a host version of a package is built and registered before a target version? * ABI hashes will likely be different between architectures: do we just require transitive version numbers to be the same? Or should there be a way to link hashes between architectures? (if we match on version numbers, i suspect we may lose things like cabal flag settings) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11470#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11470: Support changing cross compiler target at runtime -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11378 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * cc: bgamari (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11470#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11470: Support changing cross compiler target at runtime -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11378 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by angerman): Just to add a note on LLVM. If we would have an architecture independent IR[1] backend, and would just emit bitcode (which we could do from textual or bitcode IR), we could ask LLVM to produce the relevant executables for the relevant targets. There is however the question about how much architecture dependent information is used up until the Cmm phase from which the LLVM backend takes over and how much architecture dependent information we use in the llvm backend. We'd finally have to see about the mangler as well. If we therefore got a bitcode emitting ghc, we would almost get all llvm backends for free. ---- [1]: As far as I understand, you can have architecture independent IR; which however requires careful instruction selection. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11470#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11470: Support changing cross compiler target at runtime -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11378 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by aosivitz): * cc: aosivitz (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11470#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11470: Support changing cross compiler target at runtime -------------------------------------+------------------------------------- Reporter: ezyang | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11378 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ericson2314): @angerman there's not a different ticket you've been exploring `-target` under is there? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11470#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC