Here I have an executable without knowing its build environment using gcc / g ++. Is there a way to find out the optimization flag used at compile time (e.g. O0, O2, ...)?
All facilities are appreciated, whether analyzing a binary or some debugging test through gdb (if we assume that the -g flag is available at compile time).
If you're lucky, the command line is present in the executable itself, depending on the operating system used and the file format. If it is an Elf file, try dumping the contents using objdumpfrom GNU binutils
objdump
, , O0 (objdump -d), .
, x86 (, backtrace). , , , , - :
... main: ... push% rbp ... mov% rsp,% rbp
"" . ( , ) .
.
... , .
You probably don't want to do this.
Think about it ... do you want to use code that changes the behavior depending on the optimization parameters used to compile it?
If not, why do you want to write it?