Things still look good, code executes without surprises. But the generated code size still appears to me huge. My GCC senses are tingling, and telling me there should be somewhere an option to remove unused code.
In GCC the following option is given to the linker to achieve this:
-Wl,--gc-sections
In MplabX I have found it here:
It basically does what it says. If a code is never called, then the linker removes it from final binary image.
Imagine you use a huge math library, which you have as a .c source code. Let's say you only use the log() function, you probably don't want all the other mathematical functions on your flash as dead code.
So let's go on.
I use this linker option, and the code suddenly appears to be not running anymore. After a debugging session I find the culprit.
The only difference at the part, where the mischief happens is this:
So at the end, it looks like the linker has an evil twin, who removed something, the linker wasn't aware of, therefore it calls a reset on it.
After further investigatation, we can see that the call to 0x294 results to a call for an init function.
Thanks a lot linker!
So I tried to do a dirty trick. From the map file I can see, that the _pcb_initFlash function has not been in fact removed.
So I tried to modify the flash while debugging, to exchange the call to 0x00 to a call to _pcb_initFlash. (Believe me I know the quirks of flash writing) So let's see what happens.
What I expected to happen was, that my code now would run correctly. But as you can see, the modification only took action in the GUI. In fact, the Program Memory View in MplabX is not kept in sync with the actual flash content. See my prevoius post: debugging blootloader code
There is only one thing I might add.
No comments:
Post a Comment