[GHC] #12674: GHC doesn't handle ./ prefixed paths correctly

#12674: GHC doesn't handle ./ prefixed paths correctly -------------------------------------+------------------------------------- Reporter: dobenour | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: GHC rejects Unknown/Multiple | valid program Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- GHC doesn't correctly handle paths preceded by `./` on the command line, if their first character (after any number of `./`s) is a `-`. For instance, `ghc ./-a.hs` fails, even if `a.hs` exists. Somewhere, `./-a.hs` is being converted to `-a.hs`. I have not been able to figure out where this happens. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12674 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12674: GHC doesn't handle ./ prefixed paths correctly -------------------------------------+------------------------------------- Reporter: dobenour | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by nomeata): You mean “even if `-a.hs` exists”? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12674#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12674: GHC doesn't handle ./ prefixed paths correctly -------------------------------------+------------------------------------- Reporter: dobenour | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Driver | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by dobenour): * component: Compiler => Driver Comment: nomeata: yes, this happens even if `-a.hs` exists. This bug probably is not triggered often because there are few legitimate reasons to have a leading dash in an executable name, but it is still a bug. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12674#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12674: GHC doesn't handle ./ prefixed paths correctly -------------------------------------+------------------------------------- Reporter: dobenour | Owner: RolandSenn Type: bug | Status: new Priority: normal | Milestone: Component: Driver | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RolandSenn): * owner: (none) => RolandSenn Comment: I'll work on this ticket! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12674#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12674: GHC doesn't handle ./ prefixed paths correctly -------------------------------------+------------------------------------- Reporter: dobenour | Owner: RolandSenn Type: bug | Status: new Priority: normal | Milestone: Component: Driver | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RolandSenn): == The Problem I have looked into this and found the following: Assume we use: {{{ ghc ./-Module.hs }}} In the module ''ghc/Main.hs'' we have the following code in the function ''main' '' : {{{ let -- To simplify the handling of filepaths, we normalise all filepaths right -- away - e.g., for win32 platforms, backslashes are converted -- into forward slashes. normal_fileish_paths = map (normalise . unLoc) fileish_args (srcs, objs) = partition_args normal_fileish_paths [] [] <-- --- some lines dropped --- --> ---------------- Final sanity checking ----------- liftIO $ checkOptions postLoadMode dflags6 srcs objs }}} In the ''normalise'' function the FilePath **./-Module.hs** get normalised to **-Module.hs**. Then the ''checkOptions'' function reports an error, because ''-Module.hs'' is not a valid flag and processing stops! I see two possible solutions to fix this: == The hacky solution: We send non-normalised filenames to the ''checkOptions'' function. Then the processing continues. But we get problems, when we send the ''-Module.hs'' file to the preprocessor or the ''-Module.o'' file to the linker. At these locations (and maybe at some more) we have to prepend the ./ to the module name again, but only if it starts with a hyphen. == The radical solution: We extend the function ''library/filepath/System/FilePath/Internal/normalise'' so it works the following way: **./Module.hs** is normalised to **Module.hs** (as it does now) **./-Module.hs** is not normalised and remains **./-Module.hs** (this is new!!) This change in the library is a little bit more dangerous. With both solutions, only users with filenames starting with a hyphen should be affected. Please advice! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12674#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12674: GHC doesn't handle ./ prefixed paths correctly -------------------------------------+------------------------------------- Reporter: dobenour | Owner: RolandSenn Type: bug | Status: new Priority: normal | Milestone: Component: Driver | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Phyx-): You do have a third option, which is to create a wrapper for normalise in ghc and call that. On posix platforms you then have this special case if the part starts with `./-` this is much safer approach than changing filepath. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12674#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12674: GHC doesn't handle ./ prefixed paths correctly -------------------------------------+------------------------------------- Reporter: dobenour | Owner: RolandSenn Type: bug | Status: new Priority: normal | Milestone: Component: Driver | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RolandSenn): @Phyx: Many thanks to your excellent solution. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12674#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12674: GHC doesn't handle ./ prefixed paths correctly -------------------------------------+------------------------------------- Reporter: dobenour | Owner: RolandSenn Type: bug | Status: patch Priority: normal | Milestone: Component: Driver | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: T12674 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab: D5009 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RolandSenn): * testcase: => T12674 * status: new => patch * differential: => Phab: D5009 Comment: Fix in https://phabricator.haskell.org/D5009 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12674#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12674: GHC doesn't handle ./ prefixed paths correctly
-------------------------------------+-------------------------------------
Reporter: dobenour | Owner: RolandSenn
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Driver | Version: 8.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: GHC rejects | Unknown/Multiple
valid program | Test Case: T12674
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab: D5009
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Tamar Christina

#12674: GHC doesn't handle ./ prefixed paths correctly -------------------------------------+------------------------------------- Reporter: dobenour | Owner: RolandSenn Type: bug | Status: patch Priority: normal | Milestone: 8.8.1 Component: Driver | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: T12674 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab: D5009 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RolandSenn): * milestone: => 8.8.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12674#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12674: GHC doesn't handle ./ prefixed paths correctly -------------------------------------+------------------------------------- Reporter: dobenour | Owner: RolandSenn Type: bug | Status: patch Priority: normal | Milestone: 8.8.1 Component: Driver | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: T12674 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5009 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RolandSenn): * differential: Phab: D5009 => Phab:D5009 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12674#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#12674: GHC doesn't handle ./ prefixed paths correctly -------------------------------------+------------------------------------- Reporter: dobenour | Owner: RolandSenn Type: bug | Status: closed Priority: normal | Milestone: 8.8.1 Component: Driver | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: T12674 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5009 Wiki Page: | -------------------------------------+------------------------------------- Changes (by alpmestan): * status: patch => closed * resolution: => fixed Comment: D5009 has been merged, closing. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12674#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC