[Bug c/21196] New: -O2 optimizer bug?

jbglaw at lug-owl dot de gcc-bugzilla@gcc.gnu.org
Sun Apr 24 20:02:00 GMT 2005


Hi!

While working on a vax-linux cross-compiler, I noticed that my vax-linux kernel
won't boot. I tracked this down to a function that re-calculates addresses (VM
addresses to physical addresses for things that run before VM is switched on).
I've then ran the C file through the preprocessor and put it through my host
compiler (gcc-3.3.x on PeeCee). Same result even there.

Testcase:

void *
s0vmaddr_to_load_addr(void *vaddr)
{
        extern char _rtext;
        return (char *)vaddr - (0x80000000) - 0x00100000 + (unsigned int) &_rtext;
}

jbglaw@d2:~/vax-linux/kernel-2.5$ gcc -c testcase.c
jbglaw@d2:~/vax-linux/kernel-2.5$ objdump -d testcase.o

testcase.o:     file format elf32-i386

Disassembly of section .text:

00000000 <s0vmaddr_to_load_addr>:
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   b8 00 00 00 00          mov    $0x0,%eax
   8:   05 00 00 f0 7f          add    $0x7ff00000,%eax
   d:   03 45 08                add    0x8(%ebp),%eax
  10:   5d                      pop    %ebp
  11:   c3                      ret    

As you see, four bytes were reserved to be put in by the linker. However, it
seems this is missing in case of a -O2 build:

jbglaw@d2:~/vax-linux/kernel-2.5$ gcc -c -O2 testcase.c
jbglaw@d2:~/vax-linux/kernel-2.5$ objdump -d testcase.o

testcase.o:     file format elf32-i386

Disassembly of section .text:

00000000 <s0vmaddr_to_load_addr>:
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   8b 45 08                mov    0x8(%ebp),%eax
   6:   5d                      pop    %ebp
   7:   05 00 00 f0 7f          add    $0x7ff00000,%eax
   c:   c3                      ret    

...or am I wrong here?

Thanks!
Jan-Benedict Glaw <jbglaw@lug-owl.de>

-- 
           Summary: -O2 optimizer bug?
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jbglaw at lug-owl dot de
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21196



More information about the Gcc-bugs mailing list