I have some bootloader code that I decided to try to shrink by eliminating some "dead code". It was effectively "dead" since the associated functions were never called with a parameter value that would cause that code to be executed.
I checked the resulting program memory size and saw there was no reduction in size at all. Apparently, the optimizing compiler was smart enough to realize the functions were never called with parameters set so that code would get executed and did the work I was doing manually. Cool! Maybe.
I was planning on having the application code use some of the bootloader functions via well known addresses and function pointers. But, what if the compiler simplified the function's code based on what was needed for the code it could see at bootloader compilation time, but the application code's use of the code could not permit that optimization?
Is this a real problem? If so, how to handle? Compile the bootloader code without optimization? Make sure I include application code in the compilation that exercises the bootloader functions I want to share? Or, conclude it just isn't worth the hassle to try to share bootloader functions with application code that will be continually changing.