Re: huge gcc 4.1.{0,1} __weak problem

Previous thread: Horrendous Audio Stutter - current git by Parag Warudkar on Thursday, May 1, 2008 - 8:14 pm. (49 messages)

Next thread: [PATCH 0/3] ia64: Migrate data off physical pages with correctable errors v2 by Russ Anderson on Thursday, May 1, 2008 - 8:41 pm. (1 message)
To: Andrew Morton <akpm@...>
Cc: Adrian Bunk <bunk@...>, <venkatesh.pallipadi@...>, <davem@...>, <trini@...>, <mingo@...>, <tglx@...>, <hpa@...>, <linux-kernel@...>, <suresh.b.siddha@...>
Date: Thursday, May 1, 2008 - 7:55 pm

Unfortunately Debian Stable (i.e. Etch), which is relatively popular for server
use, is still using 4.1.1 :-( (The current gcc package is gcc-4.1.1-21)

I have not looked to see if Debian Stable's gcc-4.1.1-21 has been patched for
the currently discussed __weak bug.

-- Chris

Chris Knadle
Chris.Knadle@coredump.us
--

To: Chris Knadle <Chris.Knadle@...>
Cc: Andrew Morton <akpm@...>, Adrian Bunk <bunk@...>, <venkatesh.pallipadi@...>, <davem@...>, <trini@...>, <mingo@...>, <tglx@...>, <hpa@...>, <linux-kernel@...>, <suresh.b.siddha@...>, Linus Torvalds <torvalds@...>
Date: Friday, May 2, 2008 - 5:55 am

Hi Chris,

(I fixed the corrupted CC and Reply-to: address from your email.)

I checked and it has been patched in 4.1.1-21. This would make checking for
4.1.1 via __GNUC_PATCHLEVEL__ potentially invalid, as patched distro
compilers may (and in this case do) have this fixed.

--
Cheers,
Alistair.

137/1 Warrender Park Road, Edinburgh, UK.
--

To: Alistair John Strachan <alistair@...>
Cc: Chris Knadle <Chris.Knadle@...>, Andrew Morton <akpm@...>, Adrian Bunk <bunk@...>, <venkatesh.pallipadi@...>, <davem@...>, <trini@...>, <mingo@...>, <tglx@...>, <hpa@...>, <linux-kernel@...>, <suresh.b.siddha@...>, Linus Torvalds <torvalds@...>
Date: Friday, May 2, 2008 - 8:40 am

Not a problem for the Debian Stable Version, as someone already wrote, it
gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

c'ya
sven

--

The Internet treats censorship as a routing problem, and routes around
it. (John Gilmore on http://www.cygnus.com/~gnu/)
--

To: Alistair John Strachan <alistair@...>
Cc: Chris Knadle <Chris.Knadle@...>, Andrew Morton <akpm@...>, Adrian Bunk <bunk@...>, <venkatesh.pallipadi@...>, <davem@...>, <trini@...>, <mingo@...>, <tglx@...>, <hpa@...>, <linux-kernel@...>, <suresh.b.siddha@...>, Linus Torvalds <torvalds@...>
Date: Friday, May 2, 2008 - 6:43 am

Is it possible to cook up a small sample file we could build as part
of the kernel build. If it fails => error out.
If someone comes up with the code I shall try to integrate it
in the build system.

Sam
--

To: Sam Ravnborg <sam@...>
Cc: Chris Knadle <Chris.Knadle@...>, Andrew Morton <akpm@...>, Adrian Bunk <bunk@...>, <venkatesh.pallipadi@...>, <davem@...>, <trini@...>, <mingo@...>, <tglx@...>, <hpa@...>, <linux-kernel@...>, <suresh.b.siddha@...>, Linus Torvalds <torvalds@...>
Date: Friday, May 2, 2008 - 7:48 am

On Friday 02 May 2008 11:43:48 Sam Ravnborg wrote:

The GCC PR has a test case for this regression which might be usable.

http://gcc.gnu.org/viewcvs/branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/...

--
Cheers,
Alistair.

137/1 Warrender Park Road, Edinburgh, UK.
--

To: Alistair John Strachan <alistair@...>
Cc: Chris Knadle <Chris.Knadle@...>, Andrew Morton <akpm@...>, Adrian Bunk <bunk@...>, <venkatesh.pallipadi@...>, <davem@...>, <trini@...>, <mingo@...>, <tglx@...>, <hpa@...>, <linux-kernel@...>, <suresh.b.siddha@...>, Linus Torvalds <torvalds@...>
Date: Friday, May 2, 2008 - 9:57 am

OK, can anyone confirm that this fails to build which a
buggy gcc:

void __attribute__((weak)) func(void)
{
/* no code */
}

int main()
{
func();
return 0;
}

Sam
--

To: Sam Ravnborg <sam@...>
Cc: Alistair John Strachan <alistair@...>, Chris Knadle <Chris.Knadle@...>, Andrew Morton <akpm@...>, Adrian Bunk <bunk@...>, <venkatesh.pallipadi@...>, <davem@...>, <trini@...>, <mingo@...>, <tglx@...>, <hpa@...>, <linux-kernel@...>, <suresh.b.siddha@...>, Linus Torvalds <torvalds@...>
Date: Friday, May 2, 2008 - 10:57 am

I think the problem is that main() would have no call to func(), not
that it wouldn't build.

Does making func noinline fix it? I wonder if we should make __weak
implicitly make the function noinline too.

J
--

To: Sam Ravnborg <sam@...>
Cc: Alistair John Strachan <alistair@...>, Chris Knadle <Chris.Knadle@...>, Andrew Morton <akpm@...>, Adrian Bunk <bunk@...>, <venkatesh.pallipadi@...>, <davem@...>, <trini@...>, <mingo@...>, <tglx@...>, <hpa@...>, <linux-kernel@...>, <suresh.b.siddha@...>, Linus Torvalds <torvalds@...>
Date: Friday, May 2, 2008 - 10:11 am

Of course it doesn't fail to build. With buggy gcc it will be optimized
to
void __attribute__((weak)) func (void)
{
}

int main ()
{
return 0;
}

(similarly how all recent gccs optimize this without the weak attribute)
while non-buggy gcc keeps the func call.
So, you either need to grep the assembly (that's what e.g. the GCC testcase
does), or you can e.g. use a runtime testcase:
extern void abort (void);
void __attribute__((weak)) func (void) { }
int main () { func (); abort (); }
in one compilation unit and
extern void exit (int);
void func (void) { exit (0); }
in another one. I doubt a runtime testcase is acceptable though for the
kernel, as the cross compiler used to build the kernel might not be able to
create userland executables (missing C library, etc.).

Jakub
--

To: Jakub Jelinek <jakub@...>
Cc: Sam Ravnborg <sam@...>, Chris Knadle <Chris.Knadle@...>, Andrew Morton <akpm@...>, Adrian Bunk <bunk@...>, <venkatesh.pallipadi@...>, <davem@...>, <trini@...>, <mingo@...>, <tglx@...>, <hpa@...>, <linux-kernel@...>, <suresh.b.siddha@...>, Linus Torvalds <torvalds@...>, Sven-Haegar Koch <haegar@...>
Date: Friday, May 2, 2008 - 11:26 am

I assume the GCC testsuite has the same generic problem, which is probably why
it uses the -fdump-tree-optimized parameter to gcc. For example:

alistair@just:~$ cat test.c
void __attribute__((weak)) func(void)
{
/* no code */
}

int main()
{
func();
return 0;
}

alistair@just:~$ gcc -O2 -fdump-tree-optimized test.c
alistair@just:~$ rm -f a.out
alistair@just:~$ cat test.c*.optimized | egrep "func \\(\\);"
func ();

Ergo, my compiler isn't buggy. As this doesn't require a runtime test I think
it would be OK for the kernel.

Of course, whether or not it's worth it is now debatable, given the
information Sven-Haegar Koch provided (Debian's GCC version number is
actually 4.1.2).

--
Cheers,
Alistair.

137/1 Warrender Park Road, Edinburgh, UK.
--

To: Chris Knadle <Chris.Knadle@...>
Cc: Andrew Morton <akpm@...>, Adrian Bunk <bunk@...>, <venkatesh.pallipadi@...>, <davem@...>, <trini@...>, <mingo@...>, <tglx@...>, <hpa@...>, <linux-kernel@...>, <suresh.b.siddha@...>
Date: Friday, May 2, 2008 - 5:19 am

Well the package version string is 4.1.1, but the compiler thinks it's
4.1.2, at least on i386, amd64 and ia64:

$ cc -v
gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)

A small test program agrees:

printf("%d\n", __GNUC_PATCHLEVEL__);
$ ./a.out
2

Mike.

--

Previous thread: Horrendous Audio Stutter - current git by Parag Warudkar on Thursday, May 1, 2008 - 8:14 pm. (49 messages)

Next thread: [PATCH 0/3] ia64: Migrate data off physical pages with correctable errors v2 by Russ Anderson on Thursday, May 1, 2008 - 8:41 pm. (1 message)