weak-attribute over-optimisation with 4.1

Jan Kiszka jan.kiszka@web.de
Sat May 20 17:48:00 GMT 2006


Hi,

I tracked down some problem with gcc-4.1 (opensuse 10.1, can't say yet
if it's a suse-specific issue). It can be reduced to the following:

file-a.c:
---------
void __attribute__((weak)) func(void)
{
    /* no code */
}

main()
{
    func();
}


file-b.c:
---------
void func(void)
{
    printf("func\n");
}


# gcc -c file-a.c file-b.c -O2
# gcc -o program file-a.o file-b.o

The program will not print "func", because during the compilation of
file-a.c the call to func() was optimised out. This happens with -O2,
but not when using -fno-unit-at-a-time (for kernel hackers: linux 2.6.15
does not suffer while 2.6.16 does, sigh). And I do not see this with a
gcc-4.0.2 (opensuse 10.0).

So, is this a regression? Does it also happen with vanilla 4.1?

Jan


PS: Please CC me on reply.



More information about the Gcc-help mailing list