Menu

#3161 Assembler Segmentation fault on STM8 when using --debug and --out-fmt-elf with static declarations

closed-fixed
None
sdas
5
2021-07-10
2020-12-18
Michael
No

Hey,

void fkt(const char *t) {
    const char *string = t;
}

void main(void) {
    static const char *test = "Hello!\n";
    fkt( test );
    return;
}
sdcc -mstm8 --debug --out-fmt-elf -c test.c

running this code leads to a segmentation fault from the assembler.

Compiling seem to be fine:

sdcc -mstm8 --debug --out-fmt-elf -S test.c

If the string is not declarated as static it seem to be fine, too.
If ether "--debug" or "--out-fmt-elf" is missing in the commandline it seem to be fine, too.

$sdcc -v
SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/gbz80/tlcs90/ez80_z80/z80n/ds390/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15 4.0.7 #11994 (Linux)
published under GNU General Public License (GPL)

Best regards
Michael

Discussion

  • Michael

    Michael - 2020-12-18

    invoking the assembler by "hand" gives additional errors:

    sdcc -mstm8 --debug --out-fmt-elf -S test.c
    sdasstm8 -y -g -l test.asm => test.asm:505: Error: <r> relocation error
    sdasstm8 -y -g -o test.asm => segmentation fault
    sdasstm8 -y -g -s test.asm => test.asm:505: Error: <r> relocation error
    

    line 505 is

    501: Ldebug_CIE0_end:
    502:    .dw 0,12
    503:    .dw 0,(Ldebug_CIE0_start-4)
    504:    .dw 0,0 ;initial loc
    505:    .dw 0,(null)-(null)
    506: 
    507:    .area .debug_frame (NOLOAD)
    508:    .dw 0
    509:    .dw Ldebug_CIE1_end-Ldebug_CIE1_start
    
     

    Last edit: Michael 2020-12-18
  • Michael

    Michael - 2020-12-20

    It seems that the labels for all functions are stored in a global structur "dwCFIRoot" that is read to create the debug entries in the asm file.

    It's values are set in SDCCast.c createFunction() throw the calls of -> eBBlockFromiCode() -> port->assignRegiste() aka "stm8_asignRegister()" -> genSTM8Code() -> debugFile->writeFunction aka "dwWriteFunction()"

    interesting is line 7652 in SDCCast.c in function createFunction here is eBBlockFromiCode are called and after that there is a if(staticAutos) that calls eBBlockFromiCode again and causes the messed up labels when the string is declared as static.

     
  • brad roy

    brad roy - 2021-01-05

    I'm getting the same. SDCC 4.0.7 #11994 (Linux). I've been using global variables as a workaround. Ugly, but, works. (there are a handful of open tickets and discussion on this issue dating back to 3.7.0)

     

    Last edit: brad roy 2021-01-05
  • Erik Petrich

    Erik Petrich - 2021-07-10
    • status: open --> closed-fixed
    • assigned_to: Erik Petrich
     
  • Erik Petrich

    Erik Petrich - 2021-07-10

    Fixed in [r12537]

     

Log in to post a comment.

MongoDB Logo MongoDB