Skip to content

Commit a891311

Browse files
committed
Pass profiling flag to ghc when compiling C files.
The main effect of this change is that the PROFILING macro gets defined when compiling C files and profiling is enabled. This is useful for code that inspects closures. Caveat: The change relies on the fact that Cabal does not track dependencies of C files but recompiles them every time. If dependency tracking is added, we'll need different extensions for profiling and non-profiling object files.
1 parent 2912464 commit a891311

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

Distribution/Simple/GHC.hs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ buildLib verbosity pkg_descr lbi lib clbi = do
506506
info verbosity "Building C Sources..."
507507
sequence_ [do let (odir,args) = constructCcCmdLine lbi libBi clbi pref
508508
filename verbosity
509+
(withProfLib lbi)
509510
createDirectoryIfMissingVerbose verbosity True odir
510511
runGhcProg args
511512
ifSharedLib (runGhcProg (args ++ ["-fPIC", "-osuf dyn_o"]))
@@ -631,6 +632,7 @@ buildExe verbosity _pkg_descr lbi
631632
info verbosity "Building C Sources."
632633
sequence_ [do let (odir,args) = constructCcCmdLine lbi exeBi clbi
633634
exeDir filename verbosity
635+
(withProfExe lbi)
634636
createDirectoryIfMissingVerbose verbosity True odir
635637
runGhcProg args
636638
| filename <- cSources exeBi]
@@ -795,8 +797,9 @@ ghcPackageDbOptions dbstack = case dbstack of
795797
ierror = error "internal error: unexpected package db stack"
796798

797799
constructCcCmdLine :: LocalBuildInfo -> BuildInfo -> ComponentLocalBuildInfo
798-
-> FilePath -> FilePath -> Verbosity -> (FilePath,[String])
799-
constructCcCmdLine lbi bi clbi pref filename verbosity
800+
-> FilePath -> FilePath -> Verbosity -> Bool
801+
->(FilePath,[String])
802+
constructCcCmdLine lbi bi clbi pref filename verbosity profiling
800803
= let odir | compilerVersion (compiler lbi) >= Version [6,4,1] [] = pref
801804
| otherwise = pref </> takeDirectory filename
802805
-- ghc 6.4.1 fixed a bug in -odir handling
@@ -805,8 +808,12 @@ constructCcCmdLine lbi bi clbi pref filename verbosity
805808
(odir,
806809
ghcCcOptions lbi bi clbi odir
807810
++ (if verbosity >= deafening then ["-v"] else [])
808-
++ ["-c",filename])
809-
811+
++ ["-c",filename]
812+
-- Note: When building with profiling enabled, we pass the -prof
813+
-- option to ghc here when compiling C code, so that the PROFILING
814+
-- macro gets defined. The macro is used in ghc's Rts.h in the
815+
-- definitions of closure layouts (Closures.h).
816+
++ ["-prof" | profiling])
810817

811818
ghcCcOptions :: LocalBuildInfo -> BuildInfo -> ComponentLocalBuildInfo
812819
-> FilePath -> [String]

0 commit comments

Comments
 (0)