[GHC] #10171: runghc has problem when the argument list is too big

#10171: runghc has problem when the argument list is too big -------------------------------------+------------------------------------- Reporter: redneb | Owner: Type: bug | Status: new Priority: low | Milestone: Component: Compiler | Version: 7.11 Keywords: | Operating System: POSIX Architecture: | Type of failure: Runtime crash Unknown/Multiple | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- The way `runghc` works is by calling `ghc` with some extra arguments. These extra arguments cause the `argv` passed to `ghc` to be larger than the original one. This can cause the size of `argv` to exceed the maximum allowed. This might seem like a minor issue, but it can confuse several unix tools that rely on exact calculations on the size of `argv`, such as `xargs` or `find` with the `-exec` option. To demonstrate the problem, consider the following the program (call it `print_size.hs`): {{{#!hs import System.Environment import System.Posix main = getArgs >>= mapM_ printSize where printSize file = do st <- getSymbolicLinkStatus file putStrLn $ show (fileSize st) ++ " " ++ file }}} The program interpreters its `argv` as a list of files and prints their sizes. Now suppose that you want to run the program without compiling it (i.e. by interpreting it) on a specific set files, as returned by `find`. For example, consider something like that: {{{ find / -exec runhaskell print_size.hs {} + }}} If you run this, you will get the following error (multiple times): {{{ runghc: /usr/bin/ghc: rawSystem: runInteractiveProcess: exec: resource exhausted (Argument list too long) }}} The problem here is that the `-exec` option of `find`, when used with the `+` switch, works as follows: it starts collecting the list of found files and just before the list exceeds the maximum allowed size for `argv` it runs the specified program on that list (it works this way in order to minimize the number of times the program is ran). Of course this is problematic because `runghc` will then increase the size of `argv` and because of that the call to `ghc` might fail. The same thing happens if you try to run the following as well: {{{ find / -print0 | xargs -0 runhaskell print_size.hs }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10171 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10171: runghc has problem when the argument list is too big -------------------------------------+------------------------------------- Reporter: redneb | Owner: Type: bug | Status: new Priority: low | Milestone: Component: Compiler | Version: 7.11 Resolution: | Keywords: Operating System: POSIX | Architecture: Type of failure: Runtime crash | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by redneb): Currently, when you run `runhaskell script.hs arg1 arg2`, `ghc` is called with the following arguments: {{{ -ignore-dot-ghci -x hs -e ':set prog "script.hs"' -e ':main ["arg1", "arg2"]' }}} Note the the `["arg1", "arg2"]` part is generated by calling `show` on the list of original arguments. This is very inefficient. One solution is to introduce a new flag for `ghc` that would directly interpret the specified file. The new flag must have a short name so that the length of `"ghc"` plus the length of the flag name plus 1 (for the null character) is less than the length of `"runhaskell"`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10171#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10171: runghc has problem when the argument list is too big -------------------------------------+------------------------------------- Reporter: redneb | Owner: Type: bug | Status: new Priority: low | Milestone: Component: Compiler | Version: 7.11 Resolution: | Keywords: Operating System: POSIX | Architecture: Type of failure: Runtime crash | Unknown/Multiple Blocked By: | Test Case: Related Tickets: #7980 | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by rwbarton): * related: => #7980 Comment: Usually there is a limit on the size of an individual argument as well as a (much larger) limit on the total size of all the arguments. So the `':main ["arg1", "arg2"]'` argument can end up exceeding the former limit even when the original command was nowhere near either limit. See #7980. This may be what is going wrong for you too (despite the wording of the error message "Argument ''list'' too long"; note that it is the same in the linked ticket). The way to fix this would be to preserve the original argument list as a suffix of the argument list to ghc, with something like {{{ -ignore-dot-ghci -x hs -e ':set prog "script.hs"' -e ':main' script.hs --with-remaining-arguments arg1 arg2 }}} That still leaves the original issue, though. If `xargs` really leaves ''no'' extra room in the argument list size, I would consider that more than a bit crazy. Recall also that `runhaskell` is a symbolic link to `runghc` and the user could invoke the latter directly, which gives you 4 fewer characters to work with. For that matter, the user could invoke `runghc` through another symlink named `r`, and then you are really stuck! For this reason I think playing games with the lengths of GHC's options is a bit misguided. It may be the simplest solution to both issues to have `runghc` simply invoke the GHC API directly (ideally reusing the code of `ghci`) rather than launching a separate `ghc` process. Now that we have dynamic libraries, the extra binary size is no concern right? :) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10171#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10171: runghc has problem when the argument list is too big -------------------------------------+------------------------------------- Reporter: redneb | Owner: Type: bug | Status: new Priority: low | Milestone: Component: Compiler | Version: 7.11 Resolution: | Keywords: Operating System: POSIX | Architecture: Type of failure: Runtime crash | Unknown/Multiple Blocked By: | Test Case: Related Tickets: #7980 | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by redneb): What about adding a new flag to `ghc`, say `--run`, that would make it work like `runghc`, e.g. {{{ ghc --run script.hs arg1 arg2 }}} and also make `ghc` add the flag automatically to its arguments when invoked as `runghc` so that we could make `runghc` (and `runhaskell` of course) as simple symlink to `ghc`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10171#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC