The problem
In a SDCC / STM8 assembly project, I want to replace a recurrent assembly pattern with a macro. However, when I use a specific macro more often than 145 times I get a segmentation fault.
I use two similar macros. Removing one instance of one kind doesn't appear to allow adding more macro instances of the other kind.
SDCC Version
The problem happens in the SDCC Version 3.6.0, and also in the recent development version 3.6.6 #9921. Both show the following sdasstm8 version information:
sdas Assembler V02.00 + NoICE + SDCC mods (STMicroelectronics STM8)
How to reproduce
~/stm8ef-2.2.12$ make BOARD=MAXDEV
mkdir -p out/MAXDEV
sdasstm8 -I. -I./MAXDEV -plosgffw out/MAXDEV/forth.rel forth.asm
sdcc -mstm8 -oout/MAXDEV/MAXDEV.ihx main.c out/MAXDEV/forth.rel
~/stm8ef-2.2.12$ cp forth.segf.asm forth.asm
~/stm8ef-2.2.12$ make BOARD=MAXDEV
mkdir -p out/MAXDEV
sdasstm8 -I. -I./MAXDEV -plosgffw out/MAXDEV/forth.rel forth.asm
make: *** [forth.rel] Segmentation fault (core dumped)
~/stm8ef-2.2.12$ cp forth.ok.asm forth.asm
~/stm8ef-2.2.12$ make BOARD=MAXDEV
mkdir -p out/MAXDEV
sdasstm8 -I. -I./MAXDEV -plosgffw out/MAXDEV/forth.rel forth.asm
sdcc -mstm8 -oout/MAXDEV/MAXDEV.ihx main.c out/MAXDEV/forth.rel
What I can contribute to the solution
Please run "make BOARD=MINDEV" instead of the make target described in the bug report.
gdb shows the following:
asxxsrc/asmcro.c uses
FILE *fpfor representing macro instances. On my machine the number of file handles is limited to 1024 but increasing the limit for open files to 2048 doesn't change anything (ulimit -Snreturns 2048).Edit: according to comments in the listing, macro processing behaves as if there were file handles to include files. It doesn't appear to depend on OS files, though.
Edit: the problem is related to macros containing "," (comma).
Last edit: Thomas 2017-06-18
The problem has nothing to do with how often .macro is used: macro parameters don't hande string values consistently.
Given the following macro:
The second macro call below, with a string containing ",", will lead to a segmentation fault:
However, there is a general problem with string delimeters in macros. The following macro call leads to
Error: <q> missing or improper operators, terminators, or delimitersI guess it's better to close this issue, and open a new one.
Should one of the SDCC/SDAS maintainers read this, here is a band-aid which will make SDAS point the user to the offending line instead of crashing:
Ken Yap found out that using octal escapes instead of "delimiting chars" (e..g ",") doesn't lead to a crash.
See https://github.com/TG9541/stm8ef/issues/259 for more information and the applied workaround.
By the way, the patch above would really help some SDCC users to find macros that won't work because of a bug deep in the macro feature. A crash with "Segmentation fault (core dumped)¨ without any line number information is not nice.
The patch has been applied in [r11332].
FWIW asmlnk.txt also documents that there is another way to escape these besides using octal escapes:
But this escape method doesn't work in the current version AFAICS: https://sourceforge.net/p/sdcc/bugs/3150/