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

GHC ghc-devs at haskell.org
Thu Mar 19 01:30:24 UTC 2015


#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


More information about the ghc-tickets mailing list