My application has most of its code in ROM. However, the functionality can be extended with code in RAM. The RAM can be switched between CODE and XDATA. For extensions, the RAM is switched into XDATA memory, the code is loaded into RAM and then switched back to CODE memory. The code extensions are in separate directories/files. I compile the ROM as well as the extension code and link them together like this:
BL51 {all object files} TO {target} \ CODE(0 - 0x5FFF, ?PR?*?EXTENSIONS(0x8000)) \ XDATA(0 - 0x0EFF, ?XD?*?EXTENSIONS(0x0F00)) \ RAMSIZE(256) NOOVERLAY
As you can see I have dedicated areas for the ROM code and the extension code (as well as XDATA). From the resulting hex-file I extract the code for the RAM area.
This works fine so far. However, sometimes I get a bunch of linker errors ERROR 107 (ADDRESS SPACE OVERFLOW), although I didn't change anything in the ROM part of the code. And I'm not out of space. Somehow this depends on the number of local variables and initializations I do in the extension functions; yet I couldn't figure out the root cause.
1. Can somebody explain what exactly is going on there? 2. Is there a more elegant way to approach the linking of the extension code?
However, sometimes I get a bunch of linker errors ERROR 107 (ADDRESS SPACE OVERFLOW), although I didn't change anything in the ROM part of the code.
What makes you think that the RAM part of the code can't overflow on its own --- or cause the ROM parts to overflow, for that matter?
And I'm not out of space.
And you know that how?
Somehow this depends on the number of local variables and initializations I do in the extension functions; yet I couldn't figure out the root cause.
The number of initialized variables most likely is the root cause. The initializers have to be kept somewhere, and there's a good chance they'll end up in the ROM part.
The MAP file was telling me ... :)
As it turned out, I had two issues:
1. As you pointed out, the constant segment was not moved to the extension area. Adding it to the CODE statement removed that part. Similar for non-function-specific xdata.
CODE(0 - 0x5FFF, ?PR?*?EXTENSIONS(0x8000), ?CO?EXTENSIONS) \ XDATA(0 - 0x0EFF, ?XD?*?EXTENSIONS(0x0F00), ?XD?EXTENSIONS)
(Unfortunately, if you change the code and you have no initializers, the linker will issue an error about an unfound segment.)
2. I extracted only one function. But the optimizer foud some common code and placed it outside the function. I only transferred the code inside the function. This didn't cause linker problems, but the program was crashing.
Thanks for the hint!