Menu

#2360 mcs51 internal memory layout incorrect

closed-fixed
Ben Shi
None
sdld
4
2015-10-30
2015-03-06
No

Linking my application from a number of libraries on a 8051
leads to an incorrect internal memory layout.


Internal RAM layout:
      0 1 2 3 4 5 6 7 8 9 A B C D E F
0x00:|0|0|0|0|0|0|0|0|a|a|b|b|b|b|b|b|
0x10:|b|b|b|b|b|b|b|c|c|c|c|c|c|h|S| |
0x20:|B|B|B|d|d|d|d|d|d|d|d|d|e|e|e|e|
0x30:|e|e|e|e|f|f|f|f|f|f|f|f|g|g|g|g|
0x40:|Q|Q|Q|Q| | | | | | | | | | | | |
0x50:| | | | | | | | | | | | | | | | |
0x60:| | | | | | | | | | | | | | | | |
0x70:| | | | | | | | | | | | | | | | |
0x80:| | | | | | | | | | | | | | | | |
0x90:| | | | | | | | | | | | | | | | |
0xa0:| | | | | | | | | | | | | | | | |
0xb0:| | | | | | | | | | | | | | | | |
0xc0:| | | | | | | | | | | | | | | | |
0xd0:| | | | | | | | | | | | | | | | |
0xe0:| | | | | | | | | | | | | | | | |
0xf0:| | | | | | | | | | | | | | | | |


0-3:Reg Banks, T:Bit regs, a-z:Data, B:Bits, Q:Overlay, 
I:iData, S:Stack,    A:Absolute

ERROR: Couldn't get 64 bytes allocated in internal RAM for area SSEG.
Stack starts at: 0x1e (sp set to 0x1d) with 2 bytes available.

Other memory:
   Name             Start    End      Size     Max     
   ---------------- -------- -------- -------- --------
   PAGED EXT. RAM   0x0001   0x0077     119      256   
   EXTERNAL RAM     0x0078   0x0211     410    32768   
   ROM/EPROM/FLASH  0x0000   0x5dd4   24021    32768

Stack segment is misplaced and too small. Internal memory size is 128 bytes.

SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/pic16/pic14/TININative       /ds400 /hc08/s08/stm8 3.4.0 #8981 (Apr 5 2014) (Linux)

SDCC was called with the parameters below:

sdcc    --verbose --out-fmt-ihx --xram-size 32768 --iram-size 128 \
--stack-size 64 --code-size 32768 --model-medium\
        -L../../EventLogger/bin \
        -L../../Frontplatte/bin \
        -L../../HW-Register/bin \
        -L../../HW-StromquelleMultikanal/bin \
        -L../../HW-UMessMultikanal/bin \
        -L../../Interface-Kanal/bin \
        -L../../Interface-System/bin \
        -L../../MesswertSpeicher/bin \
        -L../../StatusIO/bin \
        -L../../Timer/bin \
        -L../../TracerGUI/bin \
        -L../../TracerLib/bin \
        -L../../USB-Interface/bin \
        eventLogger.lib frontplatte.lib hwRegister.lib \
        stromQuelleMC.lib uMessMultikanal.lib messwertSpeicher.lib \
        kanalInterface.lib systemInterface.lib \
        statusIO.lib timer.lib tracerGUI.lib usbIF.lib \
        tracerMesscontroller.lib Main.rel

Linking the same libraries in other combinations with different Main.rel
leads to working code.


Re-submitted as defect on request of Maarten:

I thunk it might be that the linker first locates the stack (which is specified as only one byte) in the 2 bytes at 0x1E and then finds out it can't place the full 64 bytes there.

Since I can't reclassify this as a bug report, would you please file it again as a bug? And close this one afterwards?

Maarten

Discussion

  • Ben Shi

    Ben Shi - 2015-10-28

    I thought it was not a bug,

    Since your program cost
    register: 8 bytes
    data: 53 bytes
    bit-var: 3 bytes
    overlay: 4 bytes

    total 68 bytes were cost, and you specified iram-size=128 and stack-size=64, that exceeded.

    You may either reduce you data-space cost or specify a smaller stack to fix it.

     
  • Ben Shi

    Ben Shi - 2015-10-28
    • status: open --> closed-rejected
     
  • Maarten Brock

    Maarten Brock - 2015-10-28
    • status: closed-rejected --> open
     
  • Maarten Brock

    Maarten Brock - 2015-10-28

    This is definitely a bug and should not be dismissed.

     
  • Ben Shi

    Ben Shi - 2015-10-28

    Could you please point out where is the issue? I though the author has specified the wrong --xram-size and --stack-size.

     
  • Maarten Brock

    Maarten Brock - 2015-10-28

    Ah, now I understand your reasoning. Since there is only 128 bytes iram, of which 66 were used and 2 were lost as a gap, there is only 60 left for the stack. And that is insufficient for the requested 64. And only then the stack is placed at the worst location 0x1E. You expect it would place it correctly at 0x44 with --stack-size 60. Hmm, this might be true. I haven't checked.

    I (wrongfully?) assumed the linker first picked the first free space and then decided it was insufficient.

    Still, it would be nicer if the linker would fall back to using the largest space available for the stack when the requested size is not available. The error should stay though.

     
  • Ben Shi

    Ben Shi - 2015-10-29
    • assigned_to: Ben Shi
    • Category: MCS51 --> sdld
     
  • Ben Shi

    Ben Shi - 2015-10-29

    I have composed a similiar case attached to reproduce this issue, in which three .c files are compressed inside it.

    Build it by
    sdcc a.c -c
    sdcc b.c -c
    sdcc c.c -c
    sdcc a.rel b.rel c.rel --iram-size 128 --stack-size 40

    Then an error is printed like
    ?ASlink-Error-Could not get 40 consecutive bytes in internal RAM for area SSEG.

    and the content of a.mem is
    Internal RAM layout:
    0 1 2 3 4 5 6 7 8 9 A B C D E F
    0x00:|0|0|0|0|0|0|0|0|a|a|a|a|a|a|a|a|
    0x10:|a|a|a|a|a|a|a|a|a|a|a|a|S| | | |
    0x20:|B|B|B|B|b|b|b|b|b|b|b|b|b|b|b|b|
    0x30:|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|
    0x40:|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|
    0x50:|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|
    0x60:| | | | | | | | | | | | | | | | |
    0x70:| | | | | | | | | | | | | | | | |
    0x80:| | | | | | | | | | | | | | | | |
    0x90:| | | | | | | | | | | | | | | | |
    0xa0:| | | | | | | | | | | | | | | | |
    0xb0:| | | | | | | | | | | | | | | | |
    0xc0:| | | | | | | | | | | | | | | | |
    0xd0:| | | | | | | | | | | | | | | | |
    0xe0:| | | | | | | | | | | | | | | | |
    0xf0:| | | | | | | | | | | | | | | | |
    0-3:Reg Banks, T:Bit regs, a-z:Data, B:Bits, Q:Overlay, I:iData, S:Stack, A:Absolute
    ERROR: Couldn't get 60 bytes allocated in internal RAM for area SSEG.
    Stack starts at: 0x1c (sp set to 0x1b) with 4 bytes available.

    However if I build with
    sdcc a.rel b.rel c.rel --iram-size 128 --stack-size 20

    then the error is eliminated and the a.mem shows
    Internal RAM layout:
    0 1 2 3 4 5 6 7 8 9 A B C D E F
    0x00:|0|0|0|0|0|0|0|0|a|a|a|a|a|a|a|a|
    0x10:|a|a|a|a|a|a|a|a|a|a|a|a| | | | |
    0x20:|B|B|B|B|b|b|b|b|b|b|b|b|b|b|b|b|
    0x30:|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|
    0x40:|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|
    0x50:|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|
    0x60:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
    0x70:|S|S|S|S| | | | | | | | | | | | |
    0x80:| | | | | | | | | | | | | | | | |
    0x90:| | | | | | | | | | | | | | | | |
    0xa0:| | | | | | | | | | | | | | | | |
    0xb0:| | | | | | | | | | | | | | | | |
    0xc0:| | | | | | | | | | | | | | | | |
    0xd0:| | | | | | | | | | | | | | | | |
    0xe0:| | | | | | | | | | | | | | | | |
    0xf0:| | | | | | | | | | | | | | | | |
    0-3:Reg Banks, T:Bit regs, a-z:Data, B:Bits, Q:Overlay, I:iData, S:Stack, A:Absolute
    Stack starts at: 0x60 (sp set to 0x5f) with 32 bytes available.

    My opinion,

    1. Obviously, the ticket creator specified a too large --stack-size in his program
    2. sdld still should try to find the biggest spare space even it is not big enough as requested.
     

    Last edit: Ben Shi 2015-10-29
  • Ben Shi

    Ben Shi - 2015-10-29

    I have checked the source code of sdld, when a too large --stack-size is designated, actually no final results are generated (the .rst and the .ihx), and sdld exit with an error code.

    And the stack information printed in the .mem file is wrong and confusing (the stack locates in a small area of RAM), should the right one be something like "stack can not be allocated due to no enough space".

     

    Last edit: Ben Shi 2015-10-29
  • Maarten Brock

    Maarten Brock - 2015-10-29

    I think the error message is ok. But we should still try to find the biggest spare space.

     
  • Ben Shi

    Ben Shi - 2015-10-30

    Fixed in reversion 9382.

    Now the behavior of sdld

    1. If there was no enough space for the stack, sdld reports errors and terminates with an error code as previous did
    2. sdld will suggest the largest spare space to the developer

    Different results for the above attached test case

    sdcc a.rel b.rel c.rel --iram-size 128 (not specifying the --stack-size)
    Internal RAM layout:
    0 1 2 3 4 5 6 7 8 9 A B C D E F
    0x00:|0|0|0|0|0|0|0|0|a|a|a|a|a|a|a|a|
    0x10:|a|a|a|a|a|a|a|a|a|a|a|a| | | | |
    0x20:|B|B|B|B|b|b|b|b|b|b|b|b|b|b|b|b|
    0x30:|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|
    0x40:|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|
    0x50:|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|
    0x60:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
    0x70:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
    0x80:| | | | | | | | | | | | | | | | |
    0x90:| | | | | | | | | | | | | | | | |
    0xa0:| | | | | | | | | | | | | | | | |
    0xb0:| | | | | | | | | | | | | | | | |
    0xc0:| | | | | | | | | | | | | | | | |
    0xd0:| | | | | | | | | | | | | | | | |
    0xe0:| | | | | | | | | | | | | | | | |
    0xf0:| | | | | | | | | | | | | | | | |
    0-3:Reg Banks, T:Bit regs, a-z:Data, B:Bits, Q:Overlay, I:iData, S:Stack, A:Absolute
    Stack starts at: 0x60 (sp set to 0x5f) with 32 bytes available.
    The largest spare internal RAM space starts from 0x1c with 4 bytes.

    sdcc a.rel b.rel c.rel --iram-size 128 --stack-size 20
    Internal RAM layout:
    0 1 2 3 4 5 6 7 8 9 A B C D E F
    0x00:|0|0|0|0|0|0|0|0|a|a|a|a|a|a|a|a|
    0x10:|a|a|a|a|a|a|a|a|a|a|a|a| | | | |
    0x20:|B|B|B|B|b|b|b|b|b|b|b|b|b|b|b|b|
    0x30:|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|
    0x40:|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|
    0x50:|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|
    0x60:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
    0x70:|S|S|S|S| | | | | | | | | | | | |
    0x80:| | | | | | | | | | | | | | | | |
    0x90:| | | | | | | | | | | | | | | | |
    0xa0:| | | | | | | | | | | | | | | | |
    0xb0:| | | | | | | | | | | | | | | | |
    0xc0:| | | | | | | | | | | | | | | | |
    0xd0:| | | | | | | | | | | | | | | | |
    0xe0:| | | | | | | | | | | | | | | | |
    0xf0:| | | | | | | | | | | | | | | | |
    0-3:Reg Banks, T:Bit regs, a-z:Data, B:Bits, Q:Overlay, I:iData, S:Stack, A:Absolute
    Stack starts at: 0x60 (sp set to 0x5f) with 20 bytes available.
    The largest spare internal RAM space starts from 0x74 with 12 bytes.

    sdcc a.rel b.rel c.rel --iram-size 128 --stack-size 40
    An error is printed on the console first
    ?ASlink-Error-Could not get 40 consecutive bytes in internal RAM for area SSEG.
    and then the a.mem shows
    Internal RAM layout:
    0 1 2 3 4 5 6 7 8 9 A B C D E F
    0x00:|0|0|0|0|0|0|0|0|a|a|a|a|a|a|a|a|
    0x10:|a|a|a|a|a|a|a|a|a|a|a|a| | | | |
    0x20:|B|B|B|B|b|b|b|b|b|b|b|b|b|b|b|b|
    0x30:|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|
    0x40:|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|
    0x50:|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|b|
    0x60:| | | | | | | | | | | | | | | | |
    0x70:| | | | | | | | | | | | | | | | |
    0x80:| | | | | | | | | | | | | | | | |
    0x90:| | | | | | | | | | | | | | | | |
    0xa0:| | | | | | | | | | | | | | | | |
    0xb0:| | | | | | | | | | | | | | | | |
    0xc0:| | | | | | | | | | | | | | | | |
    0xd0:| | | | | | | | | | | | | | | | |
    0xe0:| | | | | | | | | | | | | | | | |
    0xf0:| | | | | | | | | | | | | | | | |
    0-3:Reg Banks, T:Bit regs, a-z:Data, B:Bits, Q:Overlay, I:iData, S:Stack, A:Absolute
    ERROR: Couldn't get 40 bytes allocated in internal RAM for area SSEG.
    No clue at where the stack begins and ends!
    The largest spare internal RAM space starts from 0x60 with 32 bytes.

    sdcc a.rel b.rel c.rel --iram-size 90 (a much smaller ram)
    An error message is printed on the console first
    ?ASlink-Error-Could not get 60 consecutive bytes in internal RAM for area DSEG.
    and then a.mem shows
    Internal RAM layout:
    0 1 2 3 4 5 6 7 8 9 A B C D E F
    0x00:|0|0|0|0|0|0|0|0|a|a|a|a|a|a|a|a|
    0x10:|a|a|a|a|a|a|a|a|a|a|a|a| | | | |
    0x20:|B|B|B|B|S|S|S|S|S|S|S|S|S|S|S|S|
    0x30:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
    0x40:|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|S|
    0x50:|S|S|S|S|S|S|S|S|S|S| | | | | | |
    0x60:| | | | | | | | | | | | | | | | |
    0x70:| | | | | | | | | | | | | | | | |
    0x80:| | | | | | | | | | | | | | | | |
    0x90:| | | | | | | | | | | | | | | | |
    0xa0:| | | | | | | | | | | | | | | | |
    0xb0:| | | | | | | | | | | | | | | | |
    0xc0:| | | | | | | | | | | | | | | | |
    0xd0:| | | | | | | | | | | | | | | | |
    0xe0:| | | | | | | | | | | | | | | | |
    0xf0:| | | | | | | | | | | | | | | | |
    0-3:Reg Banks, T:Bit regs, a-z:Data, B:Bits, Q:Overlay, I:iData, S:Stack, A:Absolute
    ERROR: Couldn't get 60 bytes allocated in internal RAM for area DSEG.
    Stack starts at: 0x24 (sp set to 0x23) with 54 bytes available.
    The largest spare internal RAM space starts from 0x1c with 4 bytes.

     
  • Ben Shi

    Ben Shi - 2015-10-30
    • status: open --> closed-fixed
     

Log in to post a comment.

Auth0 Logo