I am using Atmel Studio 7 and in that, optimization level is -O1. Can I check what portion of code is being optimized by the compiler itself? If I am disabling the optimization, my binary file size is of 12KB and on using optimization level -O1, binary file size if 5.5KB.
Can I check what portion of code is being optimized by the compiler itself?
All the code is optimized by the compiler, i.e affected by optimization flags except
It's code that's dragged from libraries (libgcc.a
, libc.a
, libm.a
, lib<device>.a
).
Startup code (crt<device>.o
) which also includes the vector table, or code from other objects that already exist and are not (re-)compiled in the current compilation. The latter can happen with Makefiles when you change flags therein: If the modules do not depend on the Makefile itself, make
will not rebuild them.
Code from assembly modules (*.S
, *.sx
, *.s
) provided preprocessed assembly code does not use conditional assemblation by means of #ifdef __OPTIMIZE__
or similar.
Code in inline assembly, provided the inline asm is not optimized away.
In order to determine whether anything of this is in effect, you can respectively:
Link with -Wl,-Map,file.map
and inspect that map file (a text file). It will list which objects have been dragged from where due to which undefined symbol.
Startup code is linked except you -nostartfiles
. Add -Wl,-v
to the link stage, you'll see crt<device>.o
being linked.
You know your compilation units, assembly modules, don't you?
Add -save-temps
to the compilation. Inline asm will show in the intermediate *.s
file as
/* #APP */
; <line> "<compilation-unit>"
<inline-asm-code>
/* #NOAPP */