[GHC] #15262: TH splice containing numeric literal 0 causes heap overflow while cross-compiling

#15262: TH splice containing numeric literal 0 causes heap overflow while cross- compiling -------------------------------------+------------------------------------- Reporter: howtonotwin | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.5 Keywords: | Operating System: MacOS X Architecture: | Type of failure: Compile-time Unknown/Multiple | crash or panic Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Tested off commit `9976bed24dda9449ac2e3e95fb4bf8b379114a28`, running on macOS 10.13.5, trying to compile for iOS. 1. Compile a GHC that cross compiles to `x86_64-apple-ios` (i.e. with `./configure --build=x86_64-apple-darwin --host=x86_64-apple-darwin --target=x86_64-apple-ios; make`). 2. Compile a `ghc-iserv` that can run on the build system (i.e. with `./configure; cd utils/iserv; make`) 3. Try to cross-compile the following file (i.e `x86_64-apple-ios-ghc -fexternal-interpreter -pgmi=path/to/ghc-iserv T.hs`): {{{#!hs {-# LANGUAGE TemplateHaskell #-} module T where $([d| zero = 0 |]) }}} Expected: Compiles fine. Actual: {{{ [1 of 1] Compiling T ( T.hs, T.o ) T.hs:1:1: error: Exception when trying to run compile-time code: heap overflow Code: [d| zero = 0 |] | 1 | {-# LANGUAGE TemplateHaskell #-} | ^ }}} For more fun: * This problem appears to only affect the numeric literal `0`. * `0.0` is not fine. * `1` is fine. * `1 - 1` appears to be a workaround. * `0.1` is fine. * "Burying" the `0` inside another expression is not fine (e.g. `zero = [0]`). * I can even compile most of `singletons`, and it only chokes when the `0` literal first appears (`negate x = 0 - x`). * The `0` has to actually appear in the result. (`$(const [d| |] [d| zero = 0 |])` is fine.) * `0#` is not fine. * This problem only appears when cross-compiling. If I complete the build of the native GHC above and use it instead of the cross-compiler but still use `-fexternal-interpreter`, everything is fine. * Moving the declaration outside of the TH brackets is fine. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15262 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15262: TH splice containing numeric literal 0 causes heap overflow while cross- compiling -------------------------------------+------------------------------------- Reporter: howtonotwin | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.8.1 Component: Compiler | Version: 8.5 Resolution: | Keywords: Operating System: MacOS X | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by howtonotwin): Further testing reveals that the issue is simply that the GHC distribution that created the `ghc-iserv` program used `integer-gmp` but the cross- compiler used `integer-simple`. Configuring the non-cross-compiling GHC to use `integer-simple` too fixes this. It would be nice, however, if the error message were more informative. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15262#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15262: GHC and iserv cannot agree on what an Integer is; insanity ensues -------------------------------------+------------------------------------- Reporter: howtonotwin | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.8.1 Component: Compiler | Version: 8.5 Resolution: | Keywords: Operating System: MacOS X | Architecture: x86_64 Type of failure: Compile-time | (amd64) crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by howtonotwin): * architecture: Unknown/Multiple => x86_64 (amd64) Old description:
Tested off commit `9976bed24dda9449ac2e3e95fb4bf8b379114a28`, running on macOS 10.13.5, trying to compile for iOS.
1. Compile a GHC that cross compiles to `x86_64-apple-ios` (i.e. with `./configure --build=x86_64-apple-darwin --host=x86_64-apple-darwin --target=x86_64-apple-ios; make`). 2. Compile a `ghc-iserv` that can run on the build system (i.e. with `./configure; cd utils/iserv; make`) 3. Try to cross-compile the following file (i.e `x86_64-apple-ios-ghc -fexternal-interpreter -pgmi=path/to/ghc-iserv T.hs`): {{{#!hs {-# LANGUAGE TemplateHaskell #-} module T where $([d| zero = 0 |]) }}}
Expected: Compiles fine.
Actual:
{{{ [1 of 1] Compiling T ( T.hs, T.o )
T.hs:1:1: error: Exception when trying to run compile-time code: heap overflow Code: [d| zero = 0 |] | 1 | {-# LANGUAGE TemplateHaskell #-} | ^ }}}
For more fun:
* This problem appears to only affect the numeric literal `0`. * `0.0` is not fine. * `1` is fine. * `1 - 1` appears to be a workaround. * `0.1` is fine. * "Burying" the `0` inside another expression is not fine (e.g. `zero = [0]`). * I can even compile most of `singletons`, and it only chokes when the `0` literal first appears (`negate x = 0 - x`). * The `0` has to actually appear in the result. (`$(const [d| |] [d| zero = 0 |])` is fine.) * `0#` is not fine. * This problem only appears when cross-compiling. If I complete the build of the native GHC above and use it instead of the cross-compiler but still use `-fexternal-interpreter`, everything is fine. * Moving the declaration outside of the TH brackets is fine.
New description: Tested off `ghc-8.6.1-alpha1`, running on macOS 10.13.5. 1. Compile a GHC that uses `integer-gmp`. 2. Compile a GHC that uses `integer-simple`. 3. Make `Main.hs`: {{{#!hs {-# LANGUAGE TemplateHaskell #-} main = print $([e| 0 |]) }}} 4. Try to compile the file with `integer-gmp` `ghc` and `integer-simple` `ghc-iserv`. * Expected behavior: compiles fine; executable prints `0` * Actual: {{{ [1 of 1] Compiling Main ( Main.hs, Main.o ) Main.hs:2:14: error: • Exception when trying to run compile-time code: ghc: ghc-iserv terminated (-11) Code: [| 0 |] • In the untyped splice: $([| 0 |]) | 2 | main = print $([e| 0 |]) | ^^^^^^^^^^^ }}} 4. Try to compile the file with `integer-simple` `ghc` and `integer-gmp` `ghc-iserv`. * Expected behavior: compiles fine, executable prints `0`. * Actual: {{{ [1 of 1] Compiling Main ( Main.hs, Main.o ) Main.hs:2:14: error: • Exception when trying to run compile-time code: heap overflow Code: [| 0 |] • In the untyped splice: $([| 0 |]) | 2 | main = print $([e| 0 |]) | ^^^^^^^^^^^ }}} For more fun, replace the `0` with a `1`. `gmp` `ghc` + `simple` `iserv` continues to explode. This is better than `simple` `ghc` + `gmp` `iserv`: {{{#!bash $ ./Main 283468057265 $ ./Main 283468057265 $ $simple_ghc -fexternal-interpreter -pgmi=$gmp_iserv Main.hs # again # ... $ ./Main 283468057105 }}} Absolutely delicious. There is a similar situation for fractional literals. It would be nice if there was at least a warning for situations like this. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15262#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15262: GHC and iserv cannot agree on what an Integer is; insanity ensues -------------------------------------+------------------------------------- Reporter: howtonotwin | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.8.1 Component: Compiler | Version: 8.5 Resolution: | Keywords: Operating System: MacOS X | Architecture: x86_64 Type of failure: Compile-time | (amd64) crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by howtonotwin: Old description:
Tested off `ghc-8.6.1-alpha1`, running on macOS 10.13.5.
1. Compile a GHC that uses `integer-gmp`. 2. Compile a GHC that uses `integer-simple`. 3. Make `Main.hs`: {{{#!hs {-# LANGUAGE TemplateHaskell #-} main = print $([e| 0 |]) }}} 4. Try to compile the file with `integer-gmp` `ghc` and `integer-simple` `ghc-iserv`. * Expected behavior: compiles fine; executable prints `0` * Actual: {{{ [1 of 1] Compiling Main ( Main.hs, Main.o )
Main.hs:2:14: error: • Exception when trying to run compile-time code: ghc: ghc-iserv terminated (-11) Code: [| 0 |] • In the untyped splice: $([| 0 |]) | 2 | main = print $([e| 0 |]) | ^^^^^^^^^^^ }}}
4. Try to compile the file with `integer-simple` `ghc` and `integer-gmp` `ghc-iserv`. * Expected behavior: compiles fine, executable prints `0`. * Actual: {{{ [1 of 1] Compiling Main ( Main.hs, Main.o )
Main.hs:2:14: error: • Exception when trying to run compile-time code: heap overflow Code: [| 0 |] • In the untyped splice: $([| 0 |]) | 2 | main = print $([e| 0 |]) | ^^^^^^^^^^^ }}}
For more fun, replace the `0` with a `1`. `gmp` `ghc` + `simple` `iserv` continues to explode. This is better than `simple` `ghc` + `gmp` `iserv`:
{{{#!bash $ ./Main 283468057265 $ ./Main 283468057265 $ $simple_ghc -fexternal-interpreter -pgmi=$gmp_iserv Main.hs # again # ... $ ./Main 283468057105 }}}
Absolutely delicious. There is a similar situation for fractional literals.
It would be nice if there was at least a warning for situations like this.
New description: Tested off `ghc-8.6.1-alpha1`, running on macOS 10.13.5. 1. Compile a GHC that uses `integer-gmp`. 2. Compile a GHC that uses `integer-simple`. 3. Make `Main.hs`: {{{#!hs {-# LANGUAGE TemplateHaskell #-} main = print $([e| 0 |]) }}} 4. Try to compile the file with `integer-gmp` `ghc` and `integer-simple` `ghc-iserv`. * Expected behavior: (compiles fine and executable prints `0`) or (outputs to-the-point error message) * Actual: {{{ [1 of 1] Compiling Main ( Main.hs, Main.o ) Main.hs:2:14: error: • Exception when trying to run compile-time code: ghc: ghc-iserv terminated (-11) Code: [| 0 |] • In the untyped splice: $([| 0 |]) | 2 | main = print $([e| 0 |]) | ^^^^^^^^^^^ }}} 4. Try to compile the file with `integer-simple` `ghc` and `integer-gmp` `ghc-iserv`. * Expected behavior: (compiles fine and executable prints `0`) or (outputs to-the-point error message) * Actual: {{{ [1 of 1] Compiling Main ( Main.hs, Main.o ) Main.hs:2:14: error: • Exception when trying to run compile-time code: heap overflow Code: [| 0 |] • In the untyped splice: $([| 0 |]) | 2 | main = print $([e| 0 |]) | ^^^^^^^^^^^ }}} For more fun, replace the `0` with a `1`. `gmp` `ghc` + `simple` `iserv` continues to explode. This is better than `simple` `ghc` + `gmp` `iserv`: {{{#!bash $ ./Main 283468057265 $ ./Main 283468057265 $ $simple_ghc -fexternal-interpreter -pgmi=$gmp_iserv Main.hs # again # ... $ ./Main 283468057105 }}} Absolutely delicious. There is a similar situation for fractional literals. It would be nice if there was at least a warning for situations like this. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15262#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15262: GHC and iserv cannot agree on what an Integer is; insanity ensues -------------------------------------+------------------------------------- Reporter: howtonotwin | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.8.1 Component: Compiler | Version: 8.5 Resolution: | Keywords: Operating System: MacOS X | Architecture: x86_64 Type of failure: Compile-time | (amd64) crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * priority: normal => high Comment: Hmmm, indeed this looks pretty terrible. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15262#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC