Custom ghcPrimIface for cross-compilation?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Custom ghcPrimIface for cross-compilation?

Shao Cheng
Hi all, is it possible for a 64-bit ghc to emit 32-bit code, if I supply a custom ghcPrimIface via Hooks and also modify the platform flags in DynFlags? The module does not import Prelude and has no dependencies other than GHC.Prim.
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Custom ghcPrimIface for cross-compilation?

Moritz Angermann
Hi,

not sure I understand your question. If you build a cross compiler
targetting a 32bit device (say Raspbian/Raspberry Pi) for say x86_64
linux, you end up with a 64bit compiler emitting code for a 32bit
device.

If you question revolves around dynamically changing GHCs target at
runtime.  Essentially turning GHC into a multi-target compiler, we
hope to get there eventually.

Please not that just emitting a single module in 32bit is likely not
going to get you far. You will still need to build the rts and potentially
some additional support libraries to turn that module into something
useful.

Cheers,
 Moritz

> On Mar 16, 2018, at 1:12 PM, Shao Cheng <[hidden email]> wrote:
>
> Hi all, is it possible for a 64-bit ghc to emit 32-bit code, if I supply a custom ghcPrimIface via Hooks and also modify the platform flags in DynFlags? The module does not import Prelude and has no dependencies other than GHC.Prim. _______________________________________________
> ghc-devs mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Custom ghcPrimIface for cross-compilation?

Luite Stegeman
In reply to this post by Shao Cheng
Hi,

Normally when you build a cross compiler, you build the GHC sources configured for the target platform. Your GHC.Prim would already expect 32 bit, so the hook is not needed. However if you want to use the ghc library to build a non-standard cross compiler (GHCJS in my case), it may be useful. I added the `ghcPrimIface` hook for this purpose: GHCJS essentially targets a 32 bit platform, and it's a standalone program that uses the existing (already installed) `ghc` library.

But this is really a stop-gap solution. Besides replacing the GHC.Prim interface, you also need to make sure that the name cache in the GHC session doesn't contain entries referring to the built-in version, and the built-in rewrite rules also need to be avoided. And apparently there are more places: In GHCJS on GHC 8.0 it is possible to get type errors that shouldn't have been there, caused by differences between the original and replaced GHC.Prim module.

For GHC 8.2 I made the decision to abandon the use of the ghcPrimIface hook, instead building GHCJS against a "private" ghc library (under the cabal package name `ghc-api-ghcjs` ). The `ghc-api-ghcjs` library always targets 32 bit. Once we have a better way to dynamically change the target in the `ghc` library, GHCJS can drop the customized library.

Luite

On Fri, Mar 16, 2018 at 6:12 AM Shao Cheng <[hidden email]> wrote:
Hi all, is it possible for a 64-bit ghc to emit 32-bit code, if I supply a custom ghcPrimIface via Hooks and also modify the platform flags in DynFlags? The module does not import Prelude and has no dependencies other than GHC.Prim. _______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs