Menu

#35 Wrong compilation with -fomit-frame-pointer

open
nobody
None
7
2014-08-24
2001-06-20
No

The following C source is compiled into wrong asm code
with -O2 -fomit-frampointer option.
GNU C version 2.95.3-kgpd 20010315 (release)
(m68k-palmos) compiled by GNU C version 2.95.3 20010315
(release).

#include <PalmOS.h>

char home_pushed;
static int
MySysHandleEvent(EventType *event)
{
int ret;

ret = SysHandleEvent(event);

if (event->eType == keyDownEvent &&
event->data.keyDown.chr == vchrPowerOff) {
} else if (!ret && home_pushed) {
}
return ret;

}

The generated asm code contains wrong stack offset to
argument "event" for the SysHandleEvent() trap as
follows:

.file   "x.c"

gcc2_compiled.:
__gnu_compiled_c:
.text
.even
MySysHandleEvent:
move.l %a2,-(%sp)
move.l 12(%sp),%a2 #<<<WRONG
move.l %a2,-(%sp)
#APP
trap #15; dc.w 0xA0A9
#NO_APP
and.w #0xFF,%d0
addq.l #4,%sp
move.l (%sp)+,%a2
rts
.comm home_pushed,2

The offset 12 should be 8.

Discussion

  • Kouichi kumon

    Kouichi kumon - 2001-06-21

    Logged In: YES
    user_id=249898

    This bug can be reproduced by much simpler case.
    long y;
    static long MySysHandleEvent(long x)
    {
    return x + y;
    }
    With -O -fomit-frame-pointer option,
    it generages wrong offset from stack pointer to argument x;

     
  • Kouichi kumon

    Kouichi kumon - 2001-06-21
    • priority: 5 --> 7
    • summary: Incorect stack offset --> Wrong compilation with -fomit-frame-pointer
     

Log in to post a comment.