3

I compiled a benchmark using clang 703.0.31. First compiled all sources with -c -flto -O3 -g (and some other flags) into object files, then linked them using same clang (using Apple LLVM 7.3.0, using ld) with -g -flto into an executable. When I am trying to profile the executable I can see function names and disassembler, but there is no correspondence between that and source code. dsymutil on that exe produces this result: warning: (x86_x64) /tmp/lto.o unable to open object file: No such file or directory warning: no debug symbols in executable (-arch x86_64) Any idea what i am missing? (Note: I generally work on Windows, my knowledge of OS X is close to 0)

3 Answers3

0

One of workarounds suggested elsewhere worked for me: I created xcode project and re-compiled the binary. After that debug info was good enough to profile it with Instruments.

-1

You are using -O3 option which explicitly says to compiler that it should optimize the instructions in the best way. So the compiler will rearrange those instructions which may destroy correspondence between source code and executable.

You should use -O0 -g for debugging. See this.

Community
  • 1
  • 1
0x0001
  • 525
  • 4
  • 12
  • @BryanChen: I'm curious as to why...? – l'L'l Jun 09 '16 at 05:33
  • @l'L'l Because you want to know the performance of the shipping product, not the development version. Otherwise you may find out the critical path of the development version get completed optimized out by `-O3`. – Bryan Chen Jun 09 '16 at 07:22
  • That's one way to look at it, however, I think there's more to profiling than just the optimization aspect. It's sometimes helpful to see what code does without optimization since it can provide more debugging data to work with in certain situations. – l'L'l Jun 09 '16 at 09:05
  • Re-arranging instructions is fine, some correspondence between asm and source will still be there. I can't get any: symbols -fullSourcepath doesn't show anything. @l'L'l: As for O0: no, I need to look at O3 optimized code. – Natalia Glagoleva Jun 09 '16 at 15:53
-2

Unlike GCC, clang cannot produce debuginfo while optimizing.

Since you're profiling, disabling optimization would destroy the very information you're trying to collect. So, you have to use another compiler for this task.

I have not used ICC, but from documentation it looks like it can produce debuginfo while optimizing.

o11c
  • 15,265
  • 4
  • 50
  • 75