http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59693
Bug ID: 59693 Summary: man page says "extern" declarations are unaffected by -fvisibility Product: gcc Version: 4.8.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: jed at 59A2 dot org The gcc man page says the following: extern declarations are not affected by -fvisibility, so a lot of code can be recompiled with -fvisibility=hidden with no modifications. However, this means that calls to "extern" functions with no explicit visibility use the PLT, so it is more effective to use "__attribute ((visibility))" and/or "#pragma GCC visibility" to tell the compiler which "extern" declarations should be treated as hidden. I read this to mean that functions and data declared "extern" will have default visibility when compiled with -fvisibility=hidden, but that is not the case: $ cat externvis.c EXTERN int foo_func(void); EXTERN int foo_data; int foo_func(void) { return 0; } int foo_data; $ gcc -c externvis.c -DEXTERN=extern -fvisibility=hidden && objdump -t externvis.o | grep foo 0000000000000000 g F .text 000000000000000b .hidden foo_func 0000000000000004 O *COM* 0000000000000004 .hidden foo_data $ gcc -c externvis.c -DEXTERN='__attribute((visibility("default")))' -fvisibility=hidden && objdump -t externvis.o | grep foo 0000000000000004 O *COM* 0000000000000004 foo_data 0000000000000000 g F .text 000000000000000b foo_func $ gcc -c externvis.c -DEXTERN=extern && objdump -t externvis.o | grep foo 0000000000000000 g F .text 000000000000000b foo_func 0000000000000004 O *COM* 0000000000000004 foo_data It seems to me that either gcc's behavior should be changed to match the documentation or this paragraph should be removed/modified. Note that clang's behavior matches gcc (not the man page).