Hi all,

I have encountered an odd problem with sdasstm8 crashing. I believe I have narrowed it down to a particular set of circumstances, which are:

* Using --debug and --out-fmt-elf options together, and;
* Having a function with __naked attribute that contains inline assembly code.

It seems to hinge on the use of the ELF output option. With everything else being equal, but using --out-fmt-hex, there is no crash. Alternatively, if I instead just comment out the use of the __naked attribute, then ELF compilation succeeds.

I'm assuming it's something to do with the contents of the .asm file that sdas is being asked to assemble, and indeed if I examine the output of both an ELF and Intel Hex output compilation, there are substantial differences between the two - mainly that the former has a massive amount of debug stuff appended, which the latter omits.

Here is a minimal sample program that demonstrates the problem:

unsigned int do_something(unsigned char a, unsigned char b) {
    return a + b;
}

void do_nothing(void) __naked {
    __asm
        nop
        nop
        nop
        ret
    __endasm;
}

void main(void) {
    unsigned int foo;

    foo = do_something(100, 42);
    do_nothing();

    while(1);
}

This is a log of the verbose output from the crashing scenario, when asking SDCC for ELF output:

sdcc.exe -mstm8 --verbose --debug  --out-fmt-elf    -I"C:\Program Files\SDCC\include" -c main.c -o obj\ELF\main.rel sdcc.exe -L"C:\Program Files\SDCC\lib" -o bin\ELF\test.elf -mstm8 --verbose --debug  --out-fmt-elf      obj\ELF\main.rel
sdcc: Calling preprocessor...
sdcc: sdcpp.exe -nostdinc -Wall -std=c11 -I"C:\Program Files\SDCC\include" -obj-ext=.rel -D__SDCC_STACK_AUTO -D__SDCC_CHAR_UNSIGNED -D__SDCC_MODEL_MEDIUM -D__SDCC_INT_LONG_REENT -D__SDCC_FLOAT_REENT -D__SDCC=4_0_0 -D__SDCC_VERSION_MAJOR=4 -D__SDCC_VERSION_MINOR=0 -D__SDCC_VERSION_PATCH=0 -D__SDCC_REVISION=11528 -D__SDCC_stm8 -D__STDC_NO_COMPLEX__=1 -D__STDC_NO_THREADS__=1 -D__STDC_NO_ATOMICS__=1 -D__STDC_NO_VLA__=1 -D__STDC_ISO_10646__=201409L -D__STDC_UTF_16__=1 -D__STDC_UTF_32__=1 -isystem "C:\Program Files\SDCC\bin\..\include\stm8" -isystem "C:\Program Files\SDCC\bin\..\include"  "main.c"
sdcc: Generating code...
sdcc: Calling assembler...
sdcc: sdasstm8.exe -plosgffwy ""obj\ELF\main".asm"

The execution of sdasstm8 crashes (with the usual "sdasstm8.exe has stopped working" message from Windows), so the whole compilation process fails to complete. There are no error messages output by sdas.

This is the output from the non-crash scenario, when asking for Intel Hex output:

sdcc.exe -mstm8 --verbose --debug  --out-fmt-ihx    -I"C:\Program Files\SDCC\include" -c main.c -o obj\IHX\main.rel sdcc.exe -L"C:\Program Files\SDCC\lib" -o bin\IHX\test.hex -mstm8 --verbose --debug  --out-fmt-ihx      obj\IHX\main.rel
sdcc: Calling preprocessor...
sdcc: sdcpp.exe -nostdinc -Wall -std=c11 -I"C:\Program Files\SDCC\include" -obj-ext=.rel -D__SDCC_STACK_AUTO -D__SDCC_CHAR_UNSIGNED -D__SDCC_MODEL_MEDIUM -D__SDCC_INT_LONG_REENT -D__SDCC_FLOAT_REENT -D__SDCC=4_0_0 -D__SDCC_VERSION_MAJOR=4 -D__SDCC_VERSION_MINOR=0 -D__SDCC_VERSION_PATCH=0 -D__SDCC_REVISION=11528 -D__SDCC_stm8 -D__STDC_NO_COMPLEX__=1 -D__STDC_NO_THREADS__=1 -D__STDC_NO_ATOMICS__=1 -D__STDC_NO_VLA__=1 -D__STDC_ISO_10646__=201409L -D__STDC_UTF_16__=1 -D__STDC_UTF_32__=1 -isystem "C:\Program Files\SDCC\bin\..\include\stm8" -isystem "C:\Program Files\SDCC\bin\..\include"  "main.c"
sdcc: Generating code...
sdcc: Calling assembler...
sdcc: sdasstm8.exe -plosgffwy ""obj\IHX\main".asm"
sdcc: Calling linker...
sdcc: sdldstm8.exe -nf ""bin\IHX\test.lk""

I am using SDCC 4.0.0 on Windows 7. If it helps, I can supply a Code::Blocks project that is set up to demonstrate the problem.

Regards,
Basil Hussain


_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to