Opened 8 years ago

Closed 8 years ago

#5528 closed bug (fixed)

mkExtraObjToLinkIntoBinary invokes cc differently

Reported by: MtnViewMark Owned by: simonmar
Priority: high Milestone: 7.4.1
Component: Driver Version: 7.0.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC doesn't work at all Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


When GHC is performing a final link of an executable, it invokes mkExtraObjToLinkIntoBinary (in DriverPipeline.hs) to compile a small file that encodes things like the -rtsopts option (among other things). That calls mkExtraCObj in turn (it's the only caller) which uses SysTools.runCc to invoke the host compiler.

However, runCc extracts the executable name and arguments from the command line options from the sPgm_c :: (String, [Option]) field of Settings. However, the -optc option doesn't append its argument to sPgm_c's [Option] list, and so runCc, and hence the compilation in mkExtraCObj doesn't get the benefit of the -optc argument.

Contrast this to the handling of the -pgmP and -optP options, where -optP *does* append onto sPgm_P's [Option] list.

Now, it turns out that the -optc flags are used, but only in the more complex doCpp and runPhase functions (which are the only two other calls to runCc). So either a) -optc should add onto sPgm_c's [Option] list, or b) mkExtraCObj should call one of doCpp or runPhase. In the first case, then handling of the -optc options would need to be removed from doCpp and runPhase (since they would be handled by runCc, getting them via sPgm_c (it already tries to!)). This may not look safe to factor out of doCpp, but inspection will see that it is (the two Bool args are only called True/False, or False/True...)

WHY DOES THIS MATTER? A fine question to ask at this point.... If you are compiling in an environment in which the compiler will need an extra argument (say /usr/include isn't around and you need -I/somewhere-else), then you'd expect to set this -optc -- only it won't get used for that one compile generated at final link (for the rtsopts). This will cause your compile to fail.

Change History (3)

comment:1 Changed 8 years ago by simonmar

Milestone: 7.4.1
Owner: set to simonmar
Priority: normalhigh

comment:2 Changed 8 years ago by marlowsd@…

commit bcab1273dcb58199001e225eca1708e6648a3bb4

Author: Simon Marlow <>
Date:   Mon Oct 10 15:56:50 2011 +0100

    Include -optc options in mkExtraCObj (#5528)

 compiler/main/DriverPipeline.hs |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

comment:3 Changed 8 years ago by simonmar

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