[GHC] #15732: getArgsWithResponseFiles does not filter out RTS options

#15732: getArgsWithResponseFiles does not filter out RTS options -------------------------------------+------------------------------------- Reporter: ckoparkar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.8.1 Component: | Version: 8.6.1 libraries/base | Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: Incorrect result Unknown/Multiple | at runtime Test Case: | Blocked By: Blocking: | Related Tickets: #13896 Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- I discovered this while working on a fix for #15072. {{{GHC.ResponseFile.getArgsWithResponseFiles}}} is a recent addition to {{{base-4.12}}}. The idea was to have a function which could read command- line arguments supplied via response files, but otherwise would behave exactly like `System.Environment.getArgs` (see #13896). However, these functions return different results when RTS options are supplied. 1. {{{getArgs}}} does not include RTS options in the list it returns. 2. {{{getArgsWithResponseFiles}}} includes them. It's trivial to reproduce this. Consider these files: {{{ -- Bug1.hs module Main where import System.Environment ( getArgs ) main :: IO () main = do args <- getArgs putStrLn $ "Args: " ++ show args }}} and {{{ -- Bug2.hs module Main where import GHC.ResponseFile ( getArgsWithResponseFiles ) main :: IO () main = do args <- getArgsWithResponseFiles putStrLn $ "ArgsResp: " ++ show args }}} And run them with: {{{#!sh $ ghc-8.6.1 -rtsopts Bug1.hs && ghc-8.6.1 -rtsopts Bug2.hs $ ./Bug1 1 +RTS -H32m -RTS 10 20 Args: ["1","10","20"] -- 'opts_file' contains the same arguments passed to Bug1, and we -- use a '@' to pass it as a response file $ ./Bug2 @opts_file ArgsResp: ["1","+RTS","-H32m","-RTS","10","20"] }}} We should fix {{{getArgsWithResponseFiles}}} to properly handle {{{+RTS ... -RTS}}} and {{{--RTS}}} flags. Currently, {{{getArgs}}} relies on the [http://git.haskell.org/ghc.git/blob/HEAD:/rts/RtsFlags.c#l661 runtime system] for filtering out appropriate things. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15732 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15732: getArgsWithResponseFiles does not filter out RTS options -------------------------------------+------------------------------------- Reporter: ckoparkar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.8.1 Component: libraries/base | Version: 8.6.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #13896 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by ckoparkar: Old description:
I discovered this while working on a fix for #15072.
{{{GHC.ResponseFile.getArgsWithResponseFiles}}} is a recent addition to {{{base-4.12}}}. The idea was to have a function which could read command-line arguments supplied via response files, but otherwise would behave exactly like `System.Environment.getArgs` (see #13896). However, these functions return different results when RTS options are supplied. 1. {{{getArgs}}} does not include RTS options in the list it returns. 2. {{{getArgsWithResponseFiles}}} includes them.
It's trivial to reproduce this. Consider these files:
{{{ -- Bug1.hs module Main where
import System.Environment ( getArgs )
main :: IO () main = do args <- getArgs putStrLn $ "Args: " ++ show args }}}
and
{{{ -- Bug2.hs module Main where
import GHC.ResponseFile ( getArgsWithResponseFiles )
main :: IO () main = do args <- getArgsWithResponseFiles putStrLn $ "ArgsResp: " ++ show args }}}
And run them with:
{{{#!sh $ ghc-8.6.1 -rtsopts Bug1.hs && ghc-8.6.1 -rtsopts Bug2.hs
$ ./Bug1 1 +RTS -H32m -RTS 10 20 Args: ["1","10","20"]
-- 'opts_file' contains the same arguments passed to Bug1, and we -- use a '@' to pass it as a response file
$ ./Bug2 @opts_file ArgsResp: ["1","+RTS","-H32m","-RTS","10","20"] }}}
We should fix {{{getArgsWithResponseFiles}}} to properly handle {{{+RTS ... -RTS}}} and {{{--RTS}}} flags. Currently, {{{getArgs}}} relies on the [http://git.haskell.org/ghc.git/blob/HEAD:/rts/RtsFlags.c#l661 runtime system] for filtering out appropriate things.
New description: I discovered this while working on a fix for #15072. {{{GHC.ResponseFile.getArgsWithResponseFiles}}} is a recent addition to {{{base-4.12}}}. The idea was to have a function which could read command- line arguments supplied via response files, but otherwise would behave exactly like `System.Environment.getArgs` (see #13896). However, these functions return different results when RTS options are supplied. 1. {{{getArgs}}} does not include RTS options in the list it returns. 2. {{{getArgsWithResponseFiles}}} includes them. It's trivial to reproduce this. Consider these files: {{{ -- Bug1.hs module Main where import System.Environment ( getArgs ) main :: IO () main = do args <- getArgs putStrLn $ "Args: " ++ show args }}} and {{{ -- Bug2.hs module Main where import GHC.ResponseFile ( getArgsWithResponseFiles ) main :: IO () main = do args <- getArgsWithResponseFiles putStrLn $ "ArgsResp: " ++ show args }}} And run them with: {{{#!sh $ ghc-8.6.1 -rtsopts Bug1.hs && ghc-8.6.1 -rtsopts Bug2.hs $ ./Bug1 1 +RTS -H32m -RTS 10 20 Args: ["1","10","20"] -- 'opts_file' contains the same arguments passed to Bug1, and we -- use a '@' to pass it as a response file $ ./Bug2 @opts_file ArgsResp: ["1","+RTS","-H32m","-RTS","10","20"] }}} We should fix {{{getArgsWithResponseFiles}}} to properly handle {{{+RTS ... -RTS}}} and {{{--RTS}}} flags. {{{getArgs}}} relies on the [http://git.haskell.org/ghc.git/blob/HEAD:/rts/RtsFlags.c#l661 runtime system] for this. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15732#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15732: getArgsWithResponseFiles does not filter out RTS options -------------------------------------+------------------------------------- Reporter: ckoparkar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.8.1 Component: libraries/base | Version: 8.6.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #13896 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by ckoparkar): There's a bigger problem here wrt setting RTS flags via a file. In the current implementation, {{{getArgsWithResponseFiles}}} is responsible for for reading any command-line arguments passed via a file. It iterates over the list returned by {{{getArgs}}}, and issues {{{readFile}}}'s for appropriate elements (the ones that start with '@'). This means that the RTS never sees any of the flags contained in these files. This is fine for regular command-line arguments -- those which are used by a program, not GHC. But if a file contains any RTS flags ({{{+RTS ... -RTS}}}) they're completely ignored since {{{getArgsWithResponseFiles}}} doesn't know what to do with them. But these flags are indeed special, and we want the RTS to know about them. I can think of two ways to fix this: (1) Properly support response files Like all the other arguments, the RTS would also process response files (read, check errors etc.). It can then do the right thing for the flags contained in these files. We'd also like the main GHC executable to support response files (see #15072). (2) Ignore the {{{+RTS ... -RTS}}} flags contained in a response file Such flags won't have any effect on the RTS. {{{getArgsWithResponseFiles}}} would just filter these out from it's return value. Option (2) is very easy to implement but I don't feel like it's the right thing to do. I can imagine this causing confusion and further problems. On the other hand, (1) is a big change which might affect things included in the Haskell Report. If we decide to go with option (1), I'd be happy to give it a shot. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15732#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15732: getArgsWithResponseFiles does not filter out RTS options -------------------------------------+------------------------------------- Reporter: ckoparkar | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: 8.8.1 Component: libraries/base | Version: 8.6.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: 15072 Related Tickets: #13896 | Differential Rev(s): Phab:D5280 Wiki Page: | -------------------------------------+------------------------------------- Changes (by ckoparkar): * status: new => patch * differential: => Phab:D5280 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15732#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15732: getArgsWithResponseFiles does not filter out RTS options -------------------------------------+------------------------------------- Reporter: ckoparkar | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: 8.10.1 Component: libraries/base | Version: 8.6.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: 15072 Related Tickets: #13896 | Differential Rev(s): Phab:D5280 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * milestone: 8.8.1 => 8.10.1 Comment: This won't be wrapped up for 8.8. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15732#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC