Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect GCC compile-time flags of a binary

Tags:

c++

c

gcc

Is there a way to find out what gcc flags a particular binary was compiled with?

like image 696
Brian Avatar asked Oct 09 '08 21:10

Brian


3 Answers

A quick look at the GCC documentation doesn't turn anything up.

The Boost guys are some of the smartest C++ developers out there, and they resort to naming conventions because this is generally not possible any other way (the executable could have been created in any number of languages, by any number of compiler versions, after all).


(Added much later): Turns out GCC has this feature in 4.3 if asked for when you compile the code:

A new command-line switch -frecord-gcc-switches ... causes the command line that was used to invoke the compiler to be recorded into the object file that is being created. The exact format of this recording is target and binary file format dependent, but it usually takes the form of a note section containing ASCII text.

like image 57
Max Lybbert Avatar answered Nov 09 '22 07:11

Max Lybbert


Experimental proof:

diciu$ gcc -O2 /tmp/tt.c -o /tmp/a.out.o2
diciu$ gcc -O3 /tmp/tt.c -o /tmp/a.out.o3
diciu$ diff /tmp/a.out.o3 /tmp/a.out.o2 
diciu$

I take that as a no as the binaries are identical.

like image 40
diciu Avatar answered Nov 09 '22 05:11

diciu


I'm the one who asked Brian to post this originally. My question had to do with the samba binary. I found out that you can run smb -b to get information on how it was built.

like image 44
Chris Matta Avatar answered Nov 09 '22 07:11

Chris Matta