Hi,

Just noticed an odd behavior of sprintf / snprintf functions, and probably all other functions using va_list() as well. Function parameters are pushed to the stack but never popped back, so the stack gets occupied with junk. I tried to rebuild the libc with -O2, -O1, -O0 but that did not make any change. I am using the msp430f169 and the latest win32 MSPGCC binary build on the website.

Here is the disassembly of a sample program with -O1. After the last call, stack has 6 unwelcome words more.

199  (void)sprintf(str, "str 1 %d 2 %d 3 %d 4 %d", 1, 2, 3, 4);
0x3c7a <main+30>:  push #4  ;#0x0004
- 0x3c7e <main+34>:  push #3  ;#0x0003
- 0x3c82 <main+38>:  push #2  ;subst r3 with As==10
0x3c84 <main+40>:  push #1  ;subst r3 with As==01
- 0x3c86 <main+42>:  push #15428  ;#0x3c44
- 0x3c8a <main+46>:  push r4  ;
- 0x3c8c <main+48>:  call #31994  ;#0x7cfa

Here is the same piece, but with -O0. Note the add #14 at the end.

199  (void)snprintf(str, 30, "str 1 %d 2 %d 3 %d 4 %d", 1, 2, 3, 4);
0x4970 <main+44>:  push #4  ;#0x0004
- 0x4974 <main+48>:  push #3  ;#0x0003
- 0x4978 <main+52>:  push #2  ;subst r3 with As==10
- 0x497a <main+54>:  push #1  ;subst r3 with As==01
- 0x497c <main+56>:  push #18732  ;#0x492c
- 0x4980 <main+60>:  push #30  ;#0x001e
- 0x4984 <main+64>:  push r4  ;
- 0x4986 <main+66>:  call #-26478 ;#0x9892
- 0x498a <main+70>:  add #14, SP ;#0x000e

/Andrei

Reply via email to