This may have the same underlying mechanism as bug
646003, but I will post details just in case.
Running Palm OS Development Suite (PODS) 1.1,
under Windows.
This small program demonstrates the failure. Full
source needed to recompile under PODS is included in
the attached zip file.
void StatusMsg(char *s, Boolean blink)
EXTRA_SECTION_ONE;
//static void stall(UInt32 t) EXTRA_SECTION_ONE;
commented out
static void stall(UInt32 t)
{
UInt32 EndTime;
EndTime = TimGetTicks() + t * SysTicksPerSecond() /
1000; // fail
// EndTime = TimGetTicks() + t * 100 / 1000; // no fail
// EndTime = TimGetTicks() + (t / 10); // no fail
// EndTime = TimGetTicks() + (t >> 3 ); // no fail
while (TimGetTicks() < EndTime);
}
static SndCommandType BeepSound =
{sndCmdFreqDurationAmp, 0, 1047, 50, sndMaxAmp};
Boolean myflag = true;
static void beep()
{
if (myflag)
SndDoCmd(NULL, &BeepSound, false);
else
stall(50);
}
void StatusMsg(char *s, Boolean blink)
{
RectangleType EraseRect = {topLeft: {POS_STATUS,
0}, extent: {160 - POS_STATUS, 11}};
WinEraseRectangle(&EraseRect, 0);
stall(200);
beep();
}
The important module, StatusMsg(), is only about 200
bytes. Printouts of the disassembly appear in
the "Release" directory of the attached zip file.
StatusMsg() is assigned to a named Section, "code1".
It calls stall(), which is allowed to exist in the default
section.
stall() does a 32-bit multiply and divide, and the c
compiler appears to be generating a subroutine call to
do so.
The issue appears when optimization is set to -O3 or
higher, which allows simple functions such as stall() to
be in-lined. When this happens, stall(), or perhaps the
math functions it calls, go on a wild walk in memory. If
any of the complexity is removed from stall() or
StatusMsg(), the problem usually goes away, but
possibly because the wild walk returns to good code by
chance. The calls to the math functions are done in a
different way between the working and failing code, even
though the calls are directly from the StatusMsg()
function in both cases.
If optimization is set to -O2, -O1, or O0, the issue will
go away. A bona-fide function call is done to stall(), and
everything is fine.
To run the demo, start it in the Palm Emulator or
Simulator, and select "Debug" from the menu. That
should initiate the crash.
Thanks in advance for your consideration.
Demo of crash, compile under PODS