This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: constant calls and optimization


On 17-Jul-99 Martin v. Loewis wrote:
> I can't reproduce this. With egcs-2.91.66 g++ -O2 -S -fno-exceptions
> -fomit-frame-pointer, I get

> for bar. This is surely different code, but it won't go to different
> memory addresses. Where is the problem?

That they do go to different memory addresses?  x86 assembler is not my forte',
so I don't really understand why.  I'm guessing one type of call is a relative
and the other is an absolute.

Stupid test program below:

int my_foo(int i)
{
    return ((int (*)(int))0x12345678)(i);
}
 
int my_bar(int i)
{
    int (* volatile orig)(int) = ((int (*)(int))0x12345678);
    return orig(i);
}
 
int main(int argc, char *argv[])
{
    if (argc > 1)
        my_foo(0);
    else
        my_bar(0);
 
    return 0;
}

Gdb session:
?gcc -O2 -fomit-frame-pointer foo.c
?gdb a.out
GNU gdb 4.17.0.11 with Linux support
[ snip Copyright notice and intro text ]

(gdb) run
Starting program: /home/kilpatds/a.out
 
Program received signal SIGSEGV, Segmentation fault.
0x12345678 in ?? ()
(gdb) run 1
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/kilpatds/a.out 1
 
Program received signal SIGSEGV, Segmentation fault.
0x1a38da21 in ?? ()

The addresses they crash at are different.  Why?

-- 
Doug Kilpatrick
kilpatds@erols.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]