[GHC] #8206: Add support for Portable Native Client

#8206: Add support for Portable Native Client -------------------------------------------------+------------------------- Reporter: guest | Owner: Alex Type: feature request | Sayers Priority: normal | Status: new Component: Compiler | Milestone: Keywords: NaCl PNaCl Portable Native | Version: Client pexe | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Project (more than a week) | Type of failure: Blocked By: | None/Unknown Related Tickets: | Test Case: | Blocking: -------------------------------------------------+------------------------- == Motivation == [http://www.chromium.org/nativeclient/pnacl/building-and-testing-portable- native-client Portable Native Client] (PNaCl) is a feature in Google Chrome which (roughly) allows it to use LLVM bitcode like browsers use javascript today. The bitcode is downloaded, validated, compiled, and (safely) executed, with access to an API for manipulating the DOM of the page which loaded it. The dream: Haskell executed in the browser at near- native speed. Unfortunately, while GHC has an LLVM backend, the bitcode it generates doesn't satisfy the PNaCl validator. == Portable Native Client == The user visits a page with an <embed> tag pointing to a "pexe" - a PNaCl bitcode file. The bitcode is downloaded and streamed first into a code validator, and then into a compiler. The resulting machine code is then executed as a memory-protected process. The [https://developers.google.com /native-client/pepperc/ Pepper API], a library Google provides, provides access to the browser for things like connecting to websockets, playing audio, and communicating with javascript running on the page. PNaCl is present in Chrome 29 (go to chrome://flags to enable it), and will be enabled for arbitrary sources (the "open web") in Chrome 30. Mozilla have announced that they don't intend to support Native Client. == The Easily-Fixed == The pexe bitcode format is a frozen subset of LLVM bitcode. The PNaCl toolchain provides `pnacl-finalize`, which translates LLVM bitcode into pexe bitcode. PNaCl [http://www.chromium.org/nativeclient/pnacl/bitcode- abi##callingconventions only allows] the standard "ccc" calling convention, whereas GHC likes to use its own "cc 10" calling convention. You can make GHC use ccc by using an unregisterised build, for a slow-down factor of about 2. It seems likely that code-next-to-tables will upset the validator. If so, this can be turned off for a small performance hit. == The Not-So-Easily-Fixed == The validator requires that requests for IO are sent to Pepper. PNaCl also requires that you use newlib instead of glibc. Spawning new processes is forbidden (although creating pthreads is fine). It also seems likely that the validator with take umbrage at calls to `mmap`, which the GHC runtime uses to request memory allocation. It seems, therefore, that significant chunks of the RTS will have to be ported. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8206 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8206: Add support for Portable Native Client -------------------------+------------------------------------------------- Reporter: | Owner: Alex Sayers guest | Status: new Type: | Milestone: feature request | Version: Priority: | Keywords: NaCl PNaCl Portable Native normal | Client pexe Component: | Architecture: Unknown/Multiple Compiler | Difficulty: Project (more than a week) Resolution: | Blocked By: Operating System: | Related Tickets: Unknown/Multiple | Type of failure: | None/Unknown | Test Case: | Blocking: | -------------------------+------------------------------------------------- Changes (by hvr): * cc: hvr (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8206#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8206: Add support for Portable Native Client -------------------------+------------------------------------------------- Reporter: | Owner: Alex Sayers guest | Status: new Type: | Milestone: feature request | Version: Priority: | Keywords: NaCl PNaCl Portable Native normal | Client pexe Component: | Architecture: Unknown/Multiple Compiler | Difficulty: Project (more than a week) Resolution: | Blocked By: Operating System: | Related Tickets: Unknown/Multiple | Type of failure: | None/Unknown | Test Case: | Blocking: | -------------------------+------------------------------------------------- Changes (by yokto): * cc: silvio.frischi@… (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8206#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8206: Add support for Portable Native Client -------------------------+------------------------------------------------- Reporter: | Owner: Alex Sayers guest | Status: new Type: | Milestone: feature request | Version: Priority: | Keywords: NaCl PNaCl Portable Native normal | Client pexe Component: | Architecture: Unknown/Multiple Compiler | Difficulty: Project (more than a week) Resolution: | Blocked By: Operating System: | Related Tickets: Unknown/Multiple | Type of failure: | None/Unknown | Test Case: | Blocking: | -------------------------+------------------------------------------------- Changes (by ydewit): * cc: ydewit@… (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8206#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8206: Add support for Portable Native Client -------------------------------------+------------------------------------- Reporter: guest | Owner: Alex Sayers Type: feature | Status: new request | Milestone: Priority: normal | Version: Component: Compiler | Keywords: NaCl PNaCl Resolution: | Portable Native Client pexe Operating System: | Architecture: Unknown/Multiple Unknown/Multiple | Difficulty: Project (more Type of failure: | than a week) None/Unknown | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by snoyberg): * cc: snoyberg (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8206#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8206: Add support for Portable Native Client -------------------------------------+------------------------------------- Reporter: guest | Owner: Alex Type: feature request | Sayers Priority: normal | Status: new Component: Compiler | Milestone: Resolution: | Version: Operating System: Unknown/Multiple | Keywords: NaCl PNaCl Type of failure: None/Unknown | Portable Native Client pexe Blocked By: | Architecture: Related Tickets: | Unknown/Multiple | Test Case: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by tomberek): * cc: tomberek@… (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8206#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8206: Add support for Portable Native Client -------------------------------------+------------------------------------- Reporter: guest | Owner: Alex Type: feature request | Sayers Priority: normal | Status: new Component: Compiler | Milestone: Resolution: | Version: Operating System: Unknown/Multiple | Keywords: NaCl PNaCl Type of failure: None/Unknown | Portable Native Client pexe Blocked By: | Architecture: Related Tickets: | Unknown/Multiple | Test Case: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by jakzale): * cc: jakzale (added) Comment: I'm working on this issue as a part of GSOC'15. Apart from minor issues with the build system, there are some additional clashes between ghc's dependencies and native client's (nacl) newlib I found so far: - the rts depends on posix signals, which are not supported in nacl newlib (although there seems to be a workaround), - the unix package depends on posix semaphores, which are currently not supported in nacl newlib, - additionally, dlfcn.h (and all functionality regarding dynamic linking) is not available in nacl newlib. Would it be possible to build ghc without the unix package? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8206#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8206: Add support for Portable Native Client -------------------------------------+------------------------------------- Reporter: guest | Owner: Alex Type: feature request | Sayers Priority: normal | Status: new Component: Compiler | Milestone: Resolution: | Version: Operating System: Unknown/Multiple | Keywords: NaCl PNaCl Type of failure: None/Unknown | Portable Native Client pexe Blocked By: | Architecture: Related Tickets: | Unknown/Multiple | Test Case: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by asayers): I just want to make sure you're aware of some recent developments in this area. Until recently there have been two competing solutions to the same problem: nacl and asm.js, developed by Google and Mozilla respectively. Recently a new approach ([https://github.com/WebAssembly/design/blob/master/README.md web assembly]) was [http://brendaneich.com/2015/06/from-asm-js-to-webassembly/ proposed], and it seems to have buy-in from both parties. You should be prepared for the possibility that Google will deprecate nacl in favour of web assembly. There was a [https://github.com/ghcjs/ghcjs/issues/359 suggestion] that the GHCJS project should target web assembly. Luite investigated and had some concerns, but concluded that more research was needed. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8206#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC