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 the call to func() was optimised out during the compilation of file-a.c. This happens with -O2, but not when using -fno-unit-at-a-time. First sighted in 4.1.