When a function or variable has its assembler name given through an __asm__, the __attribute__((__visibility__("default"))) present on the same declaration is ignored. $ gcc -v Using built-in specs. Target: i686-pc-linux-gnu Configured with: /freebsd/gnu/linuxarchive/gcc-4.0.1/configure --prefix=/packages/gnu-inst-gcc/4.0.1 --enable-shared --enable-version-specific-runtime-libs --enable-nls --enable-threads=posix --enable-__cxa_atexit --with-as=/packages/gnu/bin/as --with-ld=/packages/gnu/bin/ld Thread model: posix gcc version 4.0.1 $ cat bug.c extern int hidden_var __asm__("my_hidden_var"); extern __attribute__((__visibility__("default"))) int exported_var __asm__("my_exported_var"); extern int hidden_func (void) __asm__("my_hidden_func"); extern __attribute__((__visibility__("default"))) int exported_func (void) __asm__("my_exported_func"); int my_hidden_var = 0; int my_exported_var = 0; int my_hidden_func (void) { return 0; } int my_exported_func (void) { return 0; } $ gcc -c -fvisibility=hidden bug.c $ readelf --syms bug.o Symbol table '.symtab' contains 11 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00000000 0 FILE LOCAL DEFAULT ABS bug.c 2: 00000000 0 SECTION LOCAL DEFAULT 1 3: 00000000 0 SECTION LOCAL DEFAULT 2 4: 00000000 0 SECTION LOCAL DEFAULT 3 5: 00000000 0 SECTION LOCAL DEFAULT 5 6: 00000000 0 SECTION LOCAL DEFAULT 4 7: 00000000 4 OBJECT GLOBAL HIDDEN 3 my_hidden_var 8: 00000004 4 OBJECT GLOBAL HIDDEN 3 my_exported_var 9: 00000000 10 FUNC GLOBAL HIDDEN 1 my_hidden_func 10: 0000000a 10 FUNC GLOBAL HIDDEN 1 my_exported_func $ gcc -shared -o bug.so bug.o && nm bug.so | grep my_ 00000476 t my_exported_func 000015e4 b my_exported_var 0000046c t my_hidden_func 000015e0 b my_hidden_var As you can see, the symbols my_exported_func, my_exported_var are not exported from bug.so, because their visibility was "HIDDEN" in bug.o. Known workaround: If I write "int exported_var = 0;" instead of "int my_exported_var = 0;", and "int exported_func (void) { return 0; }" instead of ""int my_exported_func (void) { return 0; }", the problem disappears.
-- Summary: visibility attribute does not work for aliased symbols Product: gcc Version: 4.0.1 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: bruno at clisp dot org CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23058