Bug 21196 - -O2 optimizer bug?
Summary: -O2 optimizer bug?
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.3
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-24 20:02 UTC by Jan-Benedict Glaw
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan-Benedict Glaw 2005-04-24 20:02:05 UTC
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>
Comment 1 Jan-Benedict Glaw 2005-04-24 20:05:02 UTC
Hi!

Here's how I configured it:

/home/jbglaw/vax-linux/scm/build-20050424-193631-i686-linux/src/gcc/configure
--disable-multilib --with-newlib --disable-nls --enable-threads=no
--disable-threads --enable-symvers=gnu --enable-__cxa_atexit --disable-shared
--target=i686-linux
--prefix=/home/jbglaw/vax-linux/scm/build-20050424-193631-i686-linux/install/usr
--enable-languages=c --disable-werror

Thanks,
Jan-Benedict Glaw <jbglaw@lug-owl.de>
Comment 2 Andrew Pinski 2005-04-24 20:30:41 UTC
        pushl   %ebp
        movl    %esp, %ebp
        movl    8(%ebp), %eax
        popl    %ebp
        addl    $_rtext+2146435072, %eax

This is not a bug, see above: you are missing that relocates can happen in more places than where zero 
happens so that is the bug at all.
Comment 3 Andrew Pinski 2005-04-24 20:32:49 UTC
So closing this as invalid.