Menu

#2816 Explicit alignment boundaries shifted while linked

open
nobody
None
STM8
5
2018-09-25
2018-09-24
Henk
No

Explicit alignment boundaries fail due to linker shifting assembled piece of code off the alignment boundary.

Steps to reproduce the issue:

  1. sdasstm8 -los test.asm
  2. sdcc main.c -mstm8 --out-fmt-ihx test.rel -o main.hex

In the test.lst shows the alignment boundaries are taking into account while assembling:

                                      1 .area CODE
      000000                          2 .bndry 4
      000000 9D               [ 1]    3 nop
      000004                          4 .bndry 4
      000004 9D               [ 1]    5 nop

When looking at the .rst file showing the linker results, the alignment boundaries are no longer taking into account:

                                      1 .area CODE
      008026                          2 .bndry 4
      008026 9D               [ 1]    3 nop
      00802A                          4 .bndry 4
      00802A 9D               [ 1]    5 nop

sdcc -v: mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8 3.6.9 #10220 (MINGW32)

2 Attachments

Discussion

  • Henk

    Henk - 2018-09-24

    Since STM8 fetches flash in absolute aligned chunks of 4 bytes, an quickfix would be to allign every .rel on a 4 bytes alignment boundary, so that timing critical code is executed as expected.

     
  • Henk

    Henk - 2018-09-25

    There is a work around for this issue, place explicit 4 byte alignment boundaries to every source file.

    For assembly source files this is quite simple, just adding the 4 byte alignment boundary at end of file:

    .area CODE
    .bndry 4
    

    SDCC only allows inline assembly within function scopes in C source files, therefore the 4 byte alignment boundary must be wrapped in a __naked function:

    static void _4_byte_alignment_boundary(void) __naked
    {
      __asm__ (".bndry 4");
    }
    
     

    Last edit: Henk 2018-09-25

Log in to post a comment.

Auth0 Logo