Eliminate NESTED_ATTR_FUNC
Hello. NESTED_ATTR_FUNC was introduced 6 years ago to workaround a bug in compiler. Now it creates only problems. In particular if they are used wrong it creates a bug of argument passing. Such bugs are difficult to find because it usually results in strange behaviour and in grub-emu NESTED_FUNC_ATTR is exteneded to an empty string so gdb and valgrind can't detect any error. Should we perhaps remove it coupled with adding a requirement for at least gcc 4.2? Can I run s/NESTED_FUNC_ATTR//g; on entire codebase and remove corresponding entry in configure.ac?
Signature · 4 lines
Regards Vladimir 'phcoder' Serbinenko Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
Quoted 9 lines · Vladimir 'phcoder' Serbinenko
Hello.
NESTED_ATTR_FUNCwas introduced 6 years ago to workaround a bug in compiler. Now it creates only problems. In particular if they are used wrong it creates a bug of argument passing. Such bugs are difficult to find because it usually results in strange behaviour and in grub-emuNESTED_FUNC_ATTRis exteneded to an empty string so gdb and valgrind can't detect any error. Should we perhaps remove it coupled with adding a requirement for at least gcc 4.2? Can I run s/NESTED_FUNC_ATTR//g; on entire codebase and remove corresponding entry in configure.ac?
Hi,
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.
IMO, if we are to tackle the NESTED_FUNC_ATTR issue, we should do it properly by removing nested function, this also has other advantages, like allowing to run tools on systems like OSX that doesn't allow to execute code in stack by default.
Signature · 4 lines
Bean gitgrub home: http://github.com/grub/grub/ my fork page: http://github.com/bean123/grub/
Quoted 14 lines · Bean
Quoted 9 lines · Vladimir 'phcoder' Serbinenko
Hello.
NESTED_ATTR_FUNCwas introduced 6 years ago to workaround a bug in compiler. Now it creates only problems. In particular if they are used wrong it creates a bug of argument passing. Such bugs are difficult to find because it usually results in strange behaviour and in grub-emuNESTED_FUNC_ATTRis exteneded to an empty string so gdb and valgrind can't detect any error. Should we perhaps remove it coupled with adding a requirement for at least gcc 4.2? Can I run s/NESTED_FUNC_ATTR//g; on entire codebase and remove corresponding entry in configure.ac?Hi,
Quoted 8 lines
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.
I have the impression that using stack isn't a good idea for GRUB, due to size and speed improvements, except in cases where we can't avoid it.
If older versions of GCC ignore -mregparm, we need a configure check (I prefer one that checks for the feature itself, but a version check is also acceptable IMHO).
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 23 lines · Bean
Quoted 9 lines · Vladimir 'phcoder' Serbinenko
Hello.
NESTED_ATTR_FUNCwas introduced 6 years ago to workaround a bug in compiler. Now it creates only problems. In particular if they are used wrong it creates a bug of argument passing. Such bugs are difficult to find because it usually results in strange behaviour and in grub-emuNESTED_FUNC_ATTRis exteneded to an empty string so gdb and valgrind can't detect any error. Should we perhaps remove it coupled with adding a requirement for at least gcc 4.2? Can I run s/NESTED_FUNC_ATTR//g; on entire codebase and remove corresponding entry in configure.ac?Hi,
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.
Quoted 4 lines
IMO, if we are to tackle the
NESTED_FUNC_ATTRissue, we should do it properly by removing nested function, this also has other advantages, like allowing to run tools on systems like OSX that doesn't allow to execute code in stack by default.
Hi,
Oh BTW, I just remember a page comparing the benchmark of ubuntu, and find major slowdown in various tests after Ubuntu 7.04. Note that ubuntu 7.04 uses gcc 4.1, while ubuntu 8.04 uses gcc 4.2, could this be caused by the fact that gcc 4.2 starts to ignore some optimization flags ?
http://www.phoronix.com/scan.php?page=article&item=ubuntu_bench_2008&num=1
Signature · 4 lines
Bean gitgrub home: http://github.com/grub/grub/ my fork page: http://github.com/bean123/grub/
Quoted 23 lines · Bean
Quoted 9 lines · Vladimir 'phcoder' Serbinenko
Hello.
NESTED_ATTR_FUNCwas introduced 6 years ago to workaround a bug in compiler. Now it creates only problems. In particular if they are used wrong it creates a bug of argument passing. Such bugs are difficult to find because it usually results in strange behaviour and in grub-emuNESTED_FUNC_ATTRis exteneded to an empty string so gdb and valgrind can't detect any error. Should we perhaps remove it coupled with adding a requirement for at least gcc 4.2? Can I run s/NESTED_FUNC_ATTR//g; on entire codebase and remove corresponding entry in configure.ac?Hi,
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.
Quoted 4 lines
IMO, if we are to tackle the
NESTED_FUNC_ATTRissue, we should do it properly by removing nested function, this also has other advantages, like allowing to run tools on systems like OSX that doesn't allow to execute code in stack by default.
Agree with Bean, it's the last "issue" that made that we can't run tool on OSX directly.
Regards,
Yves Blusseau
From: Yves Blusseau <[email protected]>
Date: Tue, 1 Sep 2009 21:30:01 +0200
Quoted 10 lines · Bean
Quoted 5 lines
IMO, if we are to tackle the
NESTED_FUNC_ATTRissue, we should do it properly by removing nested function, this also has other advantages, like allowing to run tools on systems like OSX that doesn't allow to execute code in stack by default.Agree with Bean, it's the last "issue" that made that we can't run tool on OSX directly.
I agree too, fixing the root issue would be a much better cure for this rather than alienating everyone who happens to be using older tools on their computer.
Quoted 11 lines · David Miller
From: Yves Blusseau <[email protected]>
Date: Tue, 1 Sep 2009 21:30:01 +0200Quoted 8 lines · Bean
Quoted 5 lines
IMO, if we are to tackle the
NESTED_FUNC_ATTRissue, we should do it properly by removing nested function, this also has other advantages, like allowing to run tools on systems like OSX that doesn't allow to execute code in stack by default.
Quoted 7 lines
Quoted 2 lines
Agree with Bean, it's the last "issue" that made that we can't run tool on OSX directly.
I agree too, fixing the root issue would be a much better cure for this rather than alienating everyone who happens to be using older tools on their computer.
I can't agree with designating nested functions as root issue. Imagine tomorrow we discover a bug in "for" loop compiling. This wouldn't be a reason to replace all "for"s with "while"s. The root issue is compiler bug and it should be fixed
The root issue is a compil
Quoted 6 lines
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 4 lines
Regards Vladimir 'phcoder' Serbinenko Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
From: "Vladimir 'phcoder' Serbinenko" <[email protected]>
Date: Thu, 3 Sep 2009 17:08:34 +0200
Quoted 4 lines
I can't agree with designating nested functions as root issue. Imagine tomorrow we discover a bug in "for" loop compiling. This wouldn't be a reason to replace all "for"s with "while"s. The root issue is compiler bug and it should be fixed
I can tell you that in kernel land when we encounter a compiler bug we usually have to simply cope with it somehow, and if that means rearranging some loop to not trigger a bug that is sometimes what it indeed does mean.
Also, a small project using a pretty obscure feature of gcc was in a way asking for trouble :-)
But if you want to decrease your testing base every time we hit some compiler bug you don't particularly like, well I guess that's your perogative then...
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
---------- Forwarded message ----------
From: David Miller <[email protected]>
Date: Sun, Sep 6, 2009 at 12:23 AM
Subject: Re: [RFC] Eliminate NESTED_ATTR_FUNC
To: [email protected]
From: "Vladimir 'phcoder' Serbinenko" <[email protected]>
Date: Sat, 5 Sep 2009 23:04:00 +0200
Quoted 9 lines · David Miller
Quoted 8 lines
From: "Vladimir 'phcoder' Serbinenko" <[email protected]>
Date: Thu, 3 Sep 2009 17:08:34 +0200Quoted 4 lines
I can't agree with designating nested functions as root issue. Imagine tomorrow we discover a bug in "for" loop compiling. This wouldn't be a reason to replace all "for"s with "while"s. The root issue is compiler bug and it should be fixed
Quoted 6 lines
Quoted 4 lines
I can tell you that in kernel land when we encounter a compiler bug we usually have to simply cope with it somehow, and if that means rearranging some loop to not trigger a bug that is sometimes what it indeed does mean.
I would consider this as shooting oneself in a foot - it encourages compilers not to fix bugs.
I would consider it a way to be considerate to one's users.
We do file the bugs, but we recognize that 1) the fix won't propagate for months, if that and 2) requiring a compiler update decreases our testing base which is the most important thing we have.
Do you get that? "The size of your tester base is the most important thing you have."
Quoted 3 lines
What about compiling with -mregparam=1 and displaying a warning if bug is detected? This way users still be yable to use older gcc's just with a cost of some core size
Sure, that might work.
Signature · 4 lines
Regards Vladimir 'phcoder' Serbinenko Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
Quoted 8 lines · Vladimir 'phcoder' Serbinenko
We do file the bugs, but we recognize that 1) the fix won't propagate for months, if that and 2) requiring a compiler update decreases our testing base which is the most important thing we have.
Do you get that? "The size of your tester base is the most important thing you have."
It's one of them. Other things are important, too.
I believe the best response is to aim for balance.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Quoted 8 lines · Bean
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/
Quoted 5 lines
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:
Quoted 7 lines
Compile with:
gcc -m32 -mregparm=3 -Ostest.c./a.out
10 31 -6674368gcc is 4.3.4 from debian.
Here the test on Mac OSX 10.5.7:
* with gcc 4.0.1:
gcc -m32 -fnested-functions test.c : 10 31 31
gcc -m32 -fnested-functions -mregparm=3 -Os test.c : 10 31 -1073744144
* with gcc 4.2.1
gcc-4.2 -m32 -fnested-functions test.c : 10 31 31
gcc-4.2 -m32 -fnested-functions -mregparm=3 -Os test.c : 10 31 -1073744128
Regards,
Yves
Quoted 5 lines
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:
I confirm with gcc-4.4
This is a grave problem then. This check was added by Marco Gerards (maintainer) in 2003. He added a workaround but I don't believe such behaviour to be correct. We're both GNU projects. IMO the correct action would have been to report the bug to gcc-devel and refuse to compile unless bug is fixed. This way users would update to newer gcc patchlevel (e.g. 4.2.(X+1) instead of 4.2.X) instead of compiling with buggy compiler. One GNU project shouldn't have expensive workaround (we had bugs because of NESTED_FUNC_ATTR misuse)
Now we're in feature freeze but I hope in the future we'll be able to change to correct behaviour when freeze is over.
Quoted 44 lines
#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 -Ostest.c./a.out
10 31 -6674368gcc is 4.3.4 from debian.
---
Beangitgrub home: http://github.com/grub/grub/
my fork page: http://github.com/bean123/grub/_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 4 lines
Regards Vladimir 'phcoder' Serbinenko Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 28 lines · Paolo Bonzini
Quoted 28 lines
Quoted 28 lines
#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 -Ostest.c
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
./a.out
10 31 -6674368Ok, this was the only important part of the message to us GCC hackers. :-)
Can you please report a bug in bugzilla, saying which versions work and which fail? Also can you write in the report what was your analysis with respect to regparm?
Done by Robert Millan here: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41246
Quoted 5 lines
Thanks!
Paolo
Signature · 4 lines
Regards Vladimir 'phcoder' Serbinenko Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
Quoted 6 lines · Bean
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:
Thanks Bean. I have opened an entry in GCC bugzilla, and submitted your test program in it:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41246
Hopefully they'll fix it in later versions, and hopefully people will upgrade soon. In the meantime, we're stuck with it.
Signature · 5 lines
Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all."
Am Donnerstag, den 03.09.2009, 17:36 +0200 schrieb Robert Millan:
Quoted 8 lines · Bean
Quoted 6 lines
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:
Quoted 8 lines
Thanks Bean. I have opened an entry in GCC bugzilla, and submitted your test program in it:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41246
Hopefully they'll fix it in later versions, and hopefully people will upgrade soon. In the meantime, we're stuck with it.
Is there any reason why we fallback to regparm 1 and not to regparm 2? According to the output of the testcase in the above bug report 2 seems to work too?
Signature · 2 lines
Felix Zielcke Proud Debian Maintainer
Quoted 14 lines · Felix Zielcke
Am Donnerstag, den 03.09.2009, 17:36 +0200 schrieb Robert Millan:
Quoted 13 lines · Bean
Quoted 6 lines
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:Thanks Bean. I have opened an entry in GCC bugzilla, and submitted your test program in it:
Quoted 8 lines
Quoted 3 lines
Hopefully they'll fix it in later versions, and hopefully people will upgrade soon. In the meantime, we're stuck with it.
Is there any reason why we fallback to regparm 1 and not to regparm 2? According to the output of the testcase in the above bug report 2 seems to work too?
The reason to use regparam(3) is to save space. If you analyse and discover that a gain of regparam(3) as opposed to regparam(2) isn't big we should could change to regparam(2). The only drawback is that all asm helpers with >=3 arguments need an excplicit attribute regparam(3)
Quoted 11 lines
--
Felix Zielcke
Proud Debian Maintainer_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel
Signature · 4 lines
Regards Vladimir 'phcoder' Serbinenko Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
Quoted 14 lines · Felix Zielcke
Am Donnerstag, den 03.09.2009, 17:36 +0200 schrieb Robert Millan:
Quoted 13 lines · Bean
Quoted 6 lines
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:Thanks Bean. I have opened an entry in GCC bugzilla, and submitted your test program in it:
Quoted 7 lines
Quoted 3 lines
Hopefully they'll fix it in later versions, and hopefully people will upgrade soon. In the meantime, we're stuck with it.
Is there any reason why we fallback to regparm 1 and not to regparm 2? According to the output of the testcase in the above bug report 2 seems to work too?
Hi,
If the first parameter is 64-bit, it will use two registers, so the second parameter is %ecx, which conflicts with local environment pointer. To see it in action, change parameter int aa to long long aa in the test program and compile it with -mregparm=2.
Signature · 4 lines
Bean gitgrub home: http://github.com/grub/grub/ my fork page: http://github.com/bean123/grub/