Rev. 6445 seems to have introduced a bug which results in the values of --code-size and --xram-size to get ignored during linking. I first observed it with Rev 6454 while trying to build the contiki OS for cc2430. I then reproduced the problem with a very simple example with Revs 6447 and 6454.
We use the following command line to build an image from the attached file.
sdcc --model-large --xram-size 7936 --code-size 0x20000 main.c
Rev: 6438: Things build without errors
Rev: 6447 and 6454: We get the following error
?ASlink-Error-Insufficient EXTERNAL RAM memory.
?ASlink-Error-Insufficient ROM/EPROM/FLASH memory.
The relevant lines of the mem file:
PAGED EXT. RAM 0 0
EXTERNAL RAM 0x0000 0x0001 2 0
ROM/EPROM/FLASH 0x0000 0x007e 127 0
*** ERROR: Insufficient EXTERNAL RAM memory.
*** ERROR: Insufficient ROM/EPROM/FLASH memory.
The exact same behavior is observed if we try to build with these steps:
sdcc --std-c99 --model-large -c main.c
sdcc --model-large --out-fmt-ihx --xram-loc 57344 --xram-size 7936 --code-size 0x20000 -o main.ihx main.rel -llibsdcc.lib
After a bit of searching and it seems that:
- The values are stored correctly in the .lk file.
- code_sav() and xramsav() in lkmain.c set code_size and xram_size to 0 respectively
The problem seems to be initiated by the masking at line 341 of lkeval.c ( term() ).
return((v & s_mask) ? v | ~v_mask : v & v_mask);
Replacing this line with the older return(v); seems to fix this particular issue (although of course it's likely to be breaking lots of other things - I won't pretend to understand what term() does). Out of curiosity, I built a contiki OS image with sdcc Rev 6454 after applying this change and Interestingly, the image seems to be working perfectly.
I'm configuring SDCC with:
./configure --disable-gbz80-port --disable-z80-port --disable-ds390-port --disable-ds400-port --disable-pic14-port --disable-pic16-port --disable-hc08-port --disable-ucsim
This was observed in an Ubuntu 10.10 box with gcc 4.4.5