On Tue, Sep 1, 2009 at 11:43 PM, Bean<bean12...@gmail.com> wrote:
> I make an assembly dump of the code generated by gcc-4.2. Apparently,
> the "FIX" is achieved by ignoring the regparm attribute at all.
> __attribute__ ((__regparm__ (3))) doesn't have any effect any more, it
> always pass the parameters on the stack. This defeats the original
> purpose of -mregparm=3, which passes parameters using register and
> therefore reduce module size. In fact, if we are going to use stack,
> we could just remove -mregparm=3 option, this works for all version of
> gcc.

Hi,

Oh, I was wrong previously, gcc does respect __attribute__
((__regparm__ (3))) flag (I forget to add -Os so it still uses stack
to store value). And the bug is still there ! Try this test program:

#include <stdio.h>

void foo (int a, int b, void (*hook) (int aa, int bb, int cc))
{
  b += a;
  hook (a, b, a + b);
}

void qq (int a)
{
  auto void q1 (int aa, int bb, int cc);
  void q1 (int aa, int bb, int cc)
    {
      printf ("%d %d %d\n", a, aa + bb, cc);
    }

  foo (a, a + 1, q1);
}

int main()
{
  qq (10);
}

Compile with:
gcc -m32 -mregparm=3 -Os test.c

./a.out
10 31 -6674368

gcc is 4.3.4 from debian.
---
Bean

gitgrub home: http://github.com/grub/grub/
my fork page: http://github.com/bean123/grub/


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to