problems catching std::runtime_error in a .so built with -fPIC

Hasan Mahmood
Wed Apr 22 21:33:00 GMT 2009

I believe both of these are happening:

hmahmood@...> g++ -fPIC -fexceptions -frtti -shared main.cpp -v
Using built-in specs.
Target: i586-suse-linux
Configured with: ../configure --enable-threads=posix --prefix=/usr
--with-local-prefix=/usr/local --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib --libexecdir=/usr/lib
--with-gxx-include-dir=/usr/include/c++/4.2.1 --enable-ssp
--disable-libssp --disable-libgcj --with-slibdir=/lib
--with-system-zlib --enable-shared --enable-_cxa_atexit
--enable-libstdcxx-allocator=new --disable-libstdcxx-pch
--program-suffix=-4.2 --enable-version-specific-runtime-libs --w
ithout-system-libunwind --with-cpu=generic --host=i586-suse-linux
Thread model: posix
gcc version 4.2.1 (SUSE Linux)
 /usr/lib/gcc/i586-suse-linux/4.2.1/cc1plus -quiet -v -D_GNU_SOURCE
main.cpp -quiet -dumpbase main.cpp -mtune=generic -auxbase main
-version -fPIC -fexceptions -frtti -o /tmp/ccBVxqAa.s
#include "..." search starts here:
#include <...> search starts here:
End of search list.
GNU C++ version 4.2.1 (SUSE Linux) (i586-suse-linux)
        compiled by GNU C version 4.2.1 (SUSE Linux).
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129418
Compiler executable checksum: 87d7be6f5d9de7847748ea6085e60774
-V -Qy -o /tmp/ccoQIilQ.o /tmp/ccBVxqAa.s
GNU assembler version 2.17.50 (i586-suse-linux) using BFD version (GNU
Binutils) (SUSE Linux)
 /usr/lib/gcc/i586-suse-linux/4.2.1/collect2 --eh-frame-hdr -m
elf_i386 -shared /usr/lib/gcc/i586-suse-linux/4.2.1/../../../crti.o
-L/usr/lib/gcc/i586-suse-linux/4.2.1/../../.. /tmp/ccoQIilQ.o -lstdc++
-lm -lgcc_s -lc -lgcc_s /usr/lib/gcc/i586-suse-linux/4.2.1/crtendS.o

hmahmood@...> ldd a.out =>  (0xffffe000) => /usr/lib/ (0xb7ef1000) => /lib/ (0xb7ecc000) => /lib/ (0xb7ec0000) => /lib/ (0xb7d8d000)
        /lib/ (0x80000000)

On Wed, Apr 22, 2009 at 4:19 PM, Ian Lance Taylor <> wrote:
> Hasan Mahmood <> writes:
>> I am having a problem trying to catch std::runtime_error (thrown from
>> libstdc++) in a .so I built with -fPIC. If I build without -fPIC, I
>> can catch the exception. Here is the code in the .so:
> What operating system are you using?
> What version of gcc are you using?
> What happens when the program does not work as you expect?
> In general you can only catch an exception thrown by a shared library if
> you are using a shared libgcc or if you are using a linker which
> supports the --eh-frame-hdr option.  So first confirm that one or the
> other is the case.  Use ldd to see whether you are linking against a
> shared libgcc (named libgccc_s).  Use -v when linking to see whether gcc
> pases --eh-frame-hdr to the linker.
> Ian

More information about the Gcc-help mailing list