Skip to content

-prof may fail because of PROFILING macro

Summary

I'm developing a Haskell library with FFI. All are OK except I want to profile with the cabal build --enable-profiling command. Debugging with cabal build --enable-profiling -v3 shows that ghc fails to build c code because of the PROFILING macro.

For my project cabal outputs(if it helps):

/opt/ghc/bin/ghc -c -prof -fPIC -osuf p_o -odir .../build -I... -optcxx-O2 '-optcxx-std=c++17' '-optcxx-march=haswell' -package-db... cpp/lib.cpp
<command-line>: error: expected identifier before numeric constant                                                                                                        
<command-line>: error: expected ‘}’ before numeric constant                                                                                                               
...

Steps to reproduce

Here is a simplified scenario

  1. create a test.c file with content
enum A {
  PROFILING = 0,
};
  1. build with ghc -c test.c, all good

  2. build with ghc -c -prof test.c, failed with

     note: in expansion of macro ‘PROFILING’
        2 |   PROFILING = 0,
          |   ^~~~~~~~~
  |
2 |   PROFILING = 0,
  |   ^
`cc' failed in phase `C Compiler'. (Exit code: 1)

Expected behavior

ghc compiles

Environment

  • GHC version used: Glasgow Haskell Compiler, Version 8.10.7, stage 2 booted by GHC version 8.10.4

Optional:

  • Operating System: ubuntu container(docker) with debian host
  • System Architecture: x86_64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information