GCC -O2 and __attribute__((weak))
问题 It looks like GCC with -O2 and __attribute__((weak)) produces different results depending on how you reference your weak symbols. Consider this: $ cat weak.c #include <stdio.h> extern const int weaksym1; const int weaksym1 __attribute__(( weak )) = 0; extern const int weaksym2; const int weaksym2 __attribute__(( weak )) = 0; extern int weaksym3; int weaksym3 __attribute__(( weak )) = 0; void testweak(void) { if ( weaksym1 == 0 ) { printf( "0\n" ); } else { printf( "1\n" ); } printf( "%d\n",