5

Do note this is different from Get the compiler options from a compiled executable? which I did go through in detail.

Although -frecord-gcc-switches is great, it only captures the command line arguments.

For example, I am not interested in capturing -O2 which is usually passed in command line. I am more curious about recording all the flags like -fauto-inc-dec which are enabled by -O2.

(In contrast to the link above, do note that I have access to the source, the compiler and the build infrastructure. I just want to capture the flags during compilation. Not picky about any specific gcc version)

R S
  • 162
  • 3
  • 11
  • Used to be -frecord-options-in-elf – Severin Pappadeux May 29 '18 at 14:41
  • Thanks @Severin. '-frecord-options-in-elf` unfortunately doesn't seem to be working (as of gcc v5.2.1). I do see some dev work, but, I'm unable to trace it [link](http://gcc-patches.gcc.gnu.narkive.com/Q5LBr1SX/google-record-compiler-options-to-note-sections) – R S May 30 '18 at 06:31
  • Yeah, I remember some discussion why it should be in/shouldn't be in, at some point it was there and then it wasn't... You have to dig around, I guess – Severin Pappadeux May 30 '18 at 14:11
  • And, frankly, it is only possible/useful to get options from single compilation unit (aka .o file). Noone guarantee files in executable are compiled with the same options, and for all projects I worked on with external libraries, our libraries, system libraries, I'm pretty sure they were all compiled a bit differently - and ABI takes care of the rest – Severin Pappadeux May 30 '18 at 14:15
  • Yep, I'm interested only in flags on a per compilation unit basis (Of course there would be a ton of differences between different CUs, not looking for any global flag !) – R S May 30 '18 at 14:27

1 Answers1

3

You can try -fverbose-asm. That dumps the optimisation options used in a comment at the top of the assembly file.

Kyrill
  • 2,963
  • 1
  • 8
  • 12