pupa-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Weird behavior of nested functions


From: Jeroen Dekkers
Subject: Re: Weird behavior of nested functions
Date: Mon, 10 Nov 2003 15:42:17 +0100
User-agent: Mutt/1.5.4i

On Mon, Nov 10, 2003 at 10:10:52AM +0100, Yoshinori K. Okuji wrote:
> On Monday 10 November 2003 00:11, Marco Gerards wrote:
> > Is it possible that some object files for the utils and pupa mix up?
> 
> No. The files in utils are compiled without -mrtd or -mregparm, because 
> otherwise they are incompatible against your C library. So it is necessary to 
> compile files in PUPA in per-target basis.
> 
> BTW, are you good at reading assembly code generated by GCC? For this kind of 
> problem, it is inevitable to take a look at what GCC produced. I myself will 
> try your code as soon as possible.

It's a gcc bug triggered by the combination of -mregparm=3 and nested
functions. The problem is that it wants to put the address of test in
%ecx but that register is also used for the third argument with
-mregparm=3. Below is a copy of the assembly code generated by gcc.

Jeroen Dekkers

The wrong code, with -mregparm=3:

        .section        .rodata.str1.1,"aMS",@progbits,1
.LC0:
        .string "Foo: %d\n"
        .text
        .type   do_foo.0, @function
do_foo.0:
.LFB5:
        .loc 1 36 0
        pushl   %ebp
.LCFI0:
        movl    %esp, %ebp
.LCFI1:
        pushl   %eax
        movl    %ecx, -4(%ebp)
        .loc 1 37 0
        pushl   -4(%ecx)
        pushl   $.LC0
.LCFI2:
        call    pupa_printf
        .loc 1 39 0
        leave
        xorl    %eax, %eax
        ret
.LFE5:
        .size   do_foo.0, .-do_foo.0
        .section        .rodata.str1.1
.LC1:
        .string "foo before: %d\n"
.LC2:
        .string "foo after: %d\n"
        .text
        .type   pupa_foo, @function
pupa_foo:
.LFB4:
        .loc 1 31 0
        pushl   %ebp
.LCFI3:
        movl    %esp, %ebp
.LCFI4:
        pushl   %edx
        .loc 1 42 0
.LBB2:
        pushl   $2
        pushl   $.LC1
        .loc 1 41 0
        movl    $2, -4(%ebp)
        .loc 1 42 0
.LCFI5:
        call    pupa_printf
        .loc 1 43 0
        xorl    %ecx, %ecx
        xorl    %edx, %edx
        xorl    %eax, %eax
.LCFI6:
        call    do_foo.0
        .loc 1 44 0
        pushl   -4(%ebp)
        pushl   $.LC2
.LCFI7:
        call    pupa_printf
        .loc 1 47 0
        leave
.LBE2:
        xorl    %eax, %eax
        ret

And the right code, without -mregparm=3:

        .section        .rodata.str1.1,"aMS",@progbits,1
.LC0:
        .string "Foo: %d\n"
        .text
        .type   do_foo.0, @function
do_foo.0:
.LFB5:
        .loc 1 36 0
        pushl   %ebp
.LCFI0:
        movl    %esp, %ebp
.LCFI1:
        pushl   %eax
        movl    %ecx, -4(%ebp)
        .loc 1 37 0
        pushl   -4(%ecx)
        pushl   $.LC0
.LCFI2:
        call    pupa_printf
        .loc 1 39 0
        leave
        xorl    %eax, %eax
        ret     $12
.LFE5:
        .size   do_foo.0, .-do_foo.0
        .section        .rodata.str1.1
.LC1:
        .string "foo before: %d\n"
.LC2:
        .string "foo after: %d\n"
        .text
        .type   pupa_foo, @function
pupa_foo:
.LFB4:
        .loc 1 31 0
        pushl   %ebp
.LCFI3:
        movl    %esp, %ebp
.LCFI4:
        pushl   %edx
        .loc 1 42 0
.LBB2:
        pushl   $2
        pushl   $.LC1
        .loc 1 41 0
        movl    $2, -4(%ebp)
        .loc 1 42 0
.LCFI5:
        call    pupa_printf
        .loc 1 43 0
        pushl   $0
        movl    %ebp, %ecx
        pushl   $0
        pushl   $0
.LCFI6:
        call    do_foo.0
        .loc 1 44 0
        pushl   -4(%ebp)
        pushl   $.LC2
.LCFI7:
        call    pupa_printf
        .loc 1 47 0
        leave
.LBE2:
        xorl    %eax, %eax




reply via email to

[Prev in Thread] Current Thread [Next in Thread]