have you ever noticed that when you comment out a piece of code, so it is ignored for variable overlay, that ALL other code that was part of the same overlay now will not overlay? for instance, I had 4-5 functions that used local arrays of chars when I commented one of them out of main so it never executed suddenly instead of only using up space for 1 array I had all the arrays in their own space (more memory than the teeny uP had) when I put the code back in the memory usage actually shrunk
Yes. This is expected behavior. Any code that the compiler (well, linker, actually) cannot identify as being part of a call tree serves as the root of its own call tree. Normally, main() serves as the root of a call tree, along with each interrupt handler. (If you have a preemptive RTOS, each task would be the root of a call tree.) Code that's not called can't be proven to belong to any of those, so there will be a number of other call trees. Each call tree has to have its own region of memory for overlaid variables. Within a call tree, the compiler can reuse memory for different paths down the tree. Between call trees, it's not safe to do so. Starting with 7.50a, there's a "removeunused" option for the linker that will remove unused code from the load entirely. There's more details in the manuals in the sections that talk about the overlay analysis.