Opened 2 years ago

Closed 2 years ago

#13287 closed bug (fixed)

The runtime parses arguments past -- under windows but passes them on as arguments on linux

Reported by: AndreasK Owned by: AndreasK
Priority: high Milestone: 8.2.1
Component: Runtime System Version: 8.0.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Other Test Case: T13287
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D3147
Wiki Page:


Starting a executable like this:

app -- arg1 +RTS -s -RTS arg2

Windows and Linux pass different arguments on to the application:

  • Windows: ["--","arg1","arg2"]
  • Linux: ["--","arg1","+RTS","-s","-RTS","arg2"]

If we want uniform behavior we need to change one of these.

Given the existence of the --RTS flag I'm not sure if the Linux behavior was intended however it matches the behavior you would expect in the *nix world nicely. Therefore changing the behavior on Windows would make more sense.

Change History (9)

comment:1 Changed 2 years ago by AndreasK

Owner: set to AndreasK

comment:2 Changed 2 years ago by AndreasK

There is already a issue for reworking the argument parser: #4243 (Make a proper options parser for the RTS)

Using a unified parser would certainly fix this behavior as well.

There is also interesting behaviour with -rtsopts=none

  • app -- +RTS arg1 get's silently ignored
  • app +RTS arg1 gives a warning (as expected)

comment:3 Changed 2 years ago by rwbarton

Milestone: 8.2.1
Priority: normalhigh

Thank you! I was baffled by this behavior in the context of a stack ticket (on phone, so not going to look for it now). With your hints I now understand more or less what is going on.

The difference between -- and --RTS is that the former is passed on to the program, while the latter is not. It's intentional and documented at least in the code which implements it, and I think in the user's guide also.

Let's just fix this for 8.2 (should be a one line change) and worry about cleaning up the weird command line stuff we do on Windows after that.

comment:4 Changed 2 years ago by AndreasK

The issue was slightly more complicated than expected.

  • The runtime parses arguments correctly and ignores RTS flags past --
  • On linux getArgs fetches the arguments from the runtime and returns these as expected.
  • On Windows getArgs ignores the arguments provided by the RTS and instead uses GetCommandLineW to get the arguments, parsing these and throwing out any RTS flags without parsing them.

The issue is that the code throwing out RTS flags didn't consider the case of -- resulting in the above behavior.

I see two ways to fix this:

  • Update the parsing code in base (easy).
  • Use getCommandLineW and consorts instead of argv in the RTS on Windows. (A more proper fix).

comment:5 Changed 2 years ago by rwbarton

Let's do the first, easy thing for 8.2 (soon). Then the more proper fix as time permits.

comment:6 Changed 2 years ago by AndreasK

Differential Rev(s): Phab:D3147
Test Case: T13287

I implemented the simple fix together with a testcase.

comment:7 Changed 2 years ago by AndreasK

Status: newpatch

comment:8 Changed 2 years ago by Ben Gamari <ben@…>

In 6ca6a36/ghc:

base: Add handling of -- to getArgs for Windows

getArgs didn't match the treatmeant of -- in the RTS leading to
inconsistencies between behavior on Windows and other platforms. See #13287.

Reviewers: austin, hvr, bgamari, erikd, simonmar, rwbarton

Reviewed By: bgamari, rwbarton

Subscribers: rwbarton, thomie

Differential Revision:

comment:9 Changed 2 years ago by bgamari

Resolution: fixed
Status: patchclosed
Note: See TracTickets for help on using tickets.