[chbot] gcc experts: Is there a flag/symbol available to see current optimisations?

Helmut Walle helmut.walle at gmail.com
Sun Jun 28 08:35:32 BST 2020


Assuming you only have the binary executable, the question, while conceptually simple, actually 
is complex in practice. You could disassemble the binary and look for signs of optimisation (or 
the absence of the respective signs) there... but the obvious problem with that is that if you 
"optimise" something with a certain switch, and the input doesn't yield anything in that regard, 
the output will be exactly the same as without that switch... So you would expect to get more 
mileage out of this approach for more complex programs, as the probability of something actually 
being achieved by optimisation is greater than for something that is so quick and simple that 
optimisation doesn't make a difference to the output.

Now this is all very nice in theory, but in practice it would still mean that you would have to 
create the analytics tooling yourself (unless someone has already done it).

All of that being said, the question is not exactly new - see here for some quick discussions of 
some of the relevant points:

https://stackoverflow.com/questions/189350/detect-gcc-compile-time-flags-of-a-binary/340828
https://stackoverflow.com/questions/9307960/find-out-compilation-optimization-flag-from-executable

Why does it even matter?

Kind regards,

Helmut.


On 28/06/2020 18:47, Charles Manning wrote:
> Hi All
> 
> I want to be able to tell in some logs what optimisation level was used to compile some code.
> 
> eg.
>   printf("This code was optimised with %s\n", omptimisation_string());
> 
> And this would print:
> "This code was optimised with -Os\n" or whatever.
> 
> Does anyone know of such a thing in gcc?
> 
> Thanks.
> 
> 
> _______________________________________________
> Chchrobotics mailing list Chchrobotics at lists.ourshack.com
> https://lists.ourshack.com/mailman/listinfo/chchrobotics
> Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> Meetings usually 3rd Monday each month. See http://kiwibots.org for venue, directions and dates.
> When replying, please edit your Subject line to reflect new subjects.
> 



More information about the Chchrobotics mailing list