I am having trouble with symbol visibility with gfortran on Linux x86_64. It looks like -fvisibility=hidden doesn't work. [ed@alion7 tirem-3.2]$ gfortran -v Using built-in specs. Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=x86_64-redhat-linux Thread model: posix gcc version 4.1.2 20070626 (Red Hat 4.1.2-14) So I copied and translated a gcc.dg/visibility-9.c to Fortran for a small test case. I compiled with gfortran to a shared library (x86_64 ELF Linux etc.). visibility-1.f90 -------------------------------------------------------------------- ! Test that -fvisibility works. ! { dg-do compile } ! { dg-require-visibility "" } ! { dg-options "-fvisibility=hidden" } ! { dg-final { scan-hidden "foo" } } subroutine foo end subroutine -------------------------------------------------------------------- [ed@alion7 ~]$ gfortran -shared -fvisibility=default -fPIC -o visibility-1.so visibility-1.f90 [ed@alion7 ~]$ nm -C -D visibility-1.so w _Jv_RegisterClasses 00000000002007c8 A __bss_start w __cxa_finalize w __gmon_start__ 00000000002007c8 A _edata 00000000002007d8 A _end 0000000000000548 T _fini 00000000000003f0 T _init 00000000000004fc T foo_ The "foo_" at the end is teh bad thing. I haven't checked a gfortran less than 4.1 but g77 as of gcc-3.4 supports visibility. I've checked with an almost release gcc-4.3 and visibility still didn't work. Is anyone else seeing a problem? I'll check PPC MacOS and i32 Cygwin when I get home. Ed Smith-Rowland ------------------------------------------------------- I just verified this on PPC MacOSX: MacOSX:~ ed$ bin-4.3/bin/gfortran -v Using built-in specs. Target: powerpc-apple-darwin7.9.0 Configured with: ../gcc/configure --prefix=/Users/ed/bin-4.3 --enable-languages=c,c++,objc,obj-c++,fortran,treelang Thread model: posix gcc version 4.3.0 20071116 (experimental) (GCC) The results of nm: MacOSX:~ ed$ bin-4.3/bin/gfortran -dynamiclib -fvisibility=default -fPIC -o visibility-1.dylib visibility-1.f90 MacOSX:~ ed$ nm visibility-1.dylib ... visibility-1.dylib(ccsE7pf3.o): 00001db0 T _foo_ ... So foo is visible on PPC MacOSX too.
-fvisibility should be only a C/C++ option as you cannot change the visibility in any other language. Also it is only implemented for C/C++/Objective-C/Objective-C++: [dhcp-10-98-10-23:local/gcc/gcc] apinski% grep default_visibility */*.c cp/decl.c: default_visibility = VISIBILITY_HIDDEN; cp/decl2.c: DECL_VISIBILITY (decl) = default_visibility; [dhcp-10-98-10-23:local/gcc/gcc] apinski% grep default_visibility *.c c-common.c: DECL_VISIBILITY (decl) = default_visibility; c-pragma.c: default_visibility); c-pragma.c: default_visibility = VISIBILITY_DEFAULT; c-pragma.c: default_visibility = VISIBILITY_INTERNAL; c-pragma.c: default_visibility = VISIBILITY_HIDDEN; c-pragma.c: default_visibility = VISIBILITY_PROTECTED; c-pragma.c: default_visibility = VEC_pop (visibility, visstack); opts.c:enum symbol_visibility default_visibility = VISIBILITY_DEFAULT; opts.c: default_visibility = VISIBILITY_DEFAULT; opts.c: default_visibility = VISIBILITY_INTERNAL; opts.c: default_visibility = VISIBILITY_HIDDEN; opts.c: default_visibility = VISIBILITY_PROTECTED;
Dear andrew, You have miss that visibility is supported by intel fortran, and is therefore quite useful for fortran dso. See http://software.intel.com/sites/products/documentation/hpc/compilerpro/en-us/fortran/lin/compiler_f/optaps/common/optaps_cmp_visib.htm BTW could you mark that this bug is blocked by 41209 ? http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41209 Bastien