Opened 8 years ago

Closed 8 years ago

Last modified 4 years ago

#5554 closed bug (fixed)

Strange interaction between "-osuf", profiling and TemplateHaskell

Reported by: iustin Owned by:
Priority: normal Milestone: 7.4.1
Component: Template Haskell Version: 7.2.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

I see a strange behaviour of profiling + TemplateHaskell and the -osuf option.

I'm trying to compile (any) TemplateHaskell code with profiling in the following way:

$ ghc --make -O example

[1 of 2] Compiling Th               ( Th.hs, Th.o )
[2 of 2] Compiling Main             ( example.hs, example.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package array-0.3.0.0 ... linking ... done.
Loading package containers-0.3.0.0 ... linking ... done.
Loading package pretty-1.0.1.1 ... linking ... done.
Loading package template-haskell ... linking ... done.
Linking example ...

$ ghc --make -O -prof -auto-all -osuf .prof.o example
[1 of 2] Compiling Th               ( Th.hs, Th.prof.o )
[2 of 2] Compiling Main             ( example.hs, example.prof.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package array-0.3.0.0 ... linking ... done.
Loading package containers-0.3.0.0 ... linking ... done.
Loading package pretty-1.0.1.1 ... linking ... done.
Loading package template-haskell ... linking ... done.
ghc: ./Th.prof.o: unknown symbol `CCCS'

However, if in the second invocation the -osuf .prof.o is changed to -osuf prof_o, then everything works fine:

$ ghc --make -O -prof -auto-all -osuf .prof_o example
[1 of 2] Compiling Th               ( Th.hs, Th.prof_o )
[2 of 2] Compiling Main             ( example.hs, example.prof_o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package array-0.3.0.0 ... linking ... done.
Loading package containers-0.3.0.0 ... linking ... done.
Loading package pretty-1.0.1.1 ... linking ... done.
Loading package template-haskell ... linking ... done.
Linking example ...

Sadly I don't know how to debug this, but it should be reproduceable with any TH code, with all of 6.12, 7.0.3 and 7.2.1.

If the .o suffix is speciall (even in the form of .prof.o), then it would be good to document this; the GHC doc says right now “you can choose any suffix that isn't the normal object suffix here”.

Change History (3)

comment:1 Changed 8 years ago by marlowsd@…

commit c489af738b4a4999ca0000110fe5dcf7944d119f

Author: Simon Marlow <marlowsd@gmail.com>
Date:   Tue Oct 18 13:23:29 2011 +0100

    fix the object suffix when using TH with profiling (#5554)

 compiler/ghci/Linker.lhs |   49 +++++++++++++++++++++++++--------------------
 1 files changed, 27 insertions(+), 22 deletions(-)

comment:2 Changed 8 years ago by simonmar

Milestone: 7.4.1
Resolution: fixed
Status: newclosed

comment:3 Changed 4 years ago by Thomas Miedema <thomasmiedema@…>

In 48db13d/ghc:

Don't drop last char of file if -osuf contains dot

Given:
 * `file = "foo.a.b"`
 * `osuf = ".a.b"`  -- Note the initial dot.
 * `new_osuf = "c"`

Before (bad, the last character of the filename is dropped):
  `dropTail (length osuf + 1) file <.> new_osuf == "fo.c"`
After (good):
  `stripExtension osuf file <.> new_osuf` == "foo.c"

This regression was introduced in commit c489af73 (#5554). That commit
fixed a similar but different bug, and care has been taken to not
reintroduce it (using the the newly introduced
`System.Filepath.stripExtension`).

Given:
 * `file = "foo.a.b"`
 * `osuf = "a.b"`
 * `new_osuf = "c"`

Before c489af73 (bad, the full suffix should get replaced):
  `replaceExtension file new_osuf == "foo.a.c"`
After c489af73 (good):
  `dropTail (length osuf + 1) file <.> new_osuf == "foo.c"`
After this commit (still good):
  `stripExtension osuf file <.> new_osuf == "foo.c"`

Reviewed by: bgamari

Differential Revision: https://phabricator.haskell.org/D1692

GHC Trac Issues: #9760
Note: See TracTickets for help on using tickets.