C++ exceptions with pragma GCC visibility(hidden)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm using some thirdparty code that (greatly simplified) looks like the following:
-bash-3.00$ cat ExceptionTest.cpp
#pragma GCC visibility push(hidden)
void foo() {
throw 1;
}


That sample can't be linked into a shared library:
-bash-3.00$ c++ -o ExceptionTest.o -c -fPIC ExceptionTest.cpp
-bash-3.00$ c++ -shared -o libexceptiontest.so ExceptionTest.o
/usr/bin/ld: ExceptionTest.o(.text+0x2f): unresolvable relocation against symbol `typeinfo for int@@CXXABI_1.3'
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status


Removing the pragma solves the problem, as does changing the visibility of the throw:
#pragma GCC visibility push(default)
throw 1;
#pragma GCC visibility pop


I'd expect the throw to work regardless of the visibility of the containing function, although that's clearly not the case. Is that a bad assumption? If so, why? My C++ is pretty rusty so I'm not too clear on what's going on. My best guess: GCC creates a typeinfo with hidden visibility for the exception type. That typeinfo is the same as the default typeinfo for int (int@@CXXABI_1.3) (where is that defined? libstdc++?). The linker sees the typeinfo is hidden in ExceptionTest.o and overrides the default visibility ("default") for that typeinfo. Is this correct? <http://www.nedprod.com/programs/gccvisibility.html> discusses something very similar, although it indicates runtime rather than linker errors.

Is this a GCC problem? Bug 20297 <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20297> sounds similar; is "throw" a built-in function? Bug 19664 <http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19664>, on the other hand, suggests a problem in libstdc++.


I'm using Fedora Core 3, which contains the visibility patch backported from GCC 4.0:
-bash-3.00$ uname -a
Linux xxx.pepper.com 2.6.10-1.770_FC3smp #1 SMP Thu Feb 24 14:20:06 EST 2005 i686 i686 i386 GNU/Linux


-bash-3.00$ gcc -v
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux
Thread model: posix
gcc version 3.4.3 20050227 (Red Hat 3.4.3-22.fc3)
gcc version 3.4.3 20050227 (Red Hat 3.4.3-22.fc3)


-bash-3.00$ ld -v
GNU ld version 2.15.92.0.2 20040927


Any insight would be greatly appreciated.

Thanks,
Steve


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux