grub-devel
[Top][All Lists]
Advanced

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

Re: [RFC] Eliminate NESTED_ATTR_FUNC


From: Bean
Subject: Re: [RFC] Eliminate NESTED_ATTR_FUNC
Date: Wed, 2 Sep 2009 12:20:19 +0800

On Tue, Sep 1, 2009 at 11:43 PM, Bean<address@hidden> 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/




reply via email to

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