C program can't catch exception from C++

A

Alfred.Cheong

I am building a NSS module on Solaris 10 64bit (amd64). It is a dynamic
linked library to be invoked by the other programs like the system
command ps.

The dynamic linked library is build on C++. Exception are thrown when
errors are detected. The exceptions actually are handled inside the
dynamic linked library. It is found that the exception can't be caught
when the DLL is invoked by programs like the ps command and lead to
segmentation fault. Yet, the exceptions can be caught when the DLL is
invoked my testing C++ program.

I have try the -fexceptions option in GCC, the problem still exists.

Can anyone give me some suggestions?

Thanks
 
M

Maxim Yegorushkin

The dynamic linked library is build on C++. Exception are thrown when
errors are detected. The exceptions actually are handled inside the
dynamic linked library. It is found that the exception can't be caught
when the DLL is invoked by programs like the ps command and lead to
segmentation fault. Yet, the exceptions can be caught when the DLL is
invoked my testing C++ program.

I have try the -fexceptions option in GCC, the problem still exists.

What makes you think that a C program can catch or propagate C++
exceptions?
 
M

Michiel.Salters

I am building a NSS module on Solaris 10 64bit (amd64). It is a dynamic
linked library to be invoked by the other programs like the system
command ps.

The dynamic linked library is build on C++. Exception are thrown when
errors are detected. The exceptions actually are handled inside the
dynamic linked library. It is found that the exception can't be caught
when the DLL is invoked by programs like the ps command and lead to
segmentation fault. Yet, the exceptions can be caught when the DLL is
invoked my testing C++ program.

The issue is possibly that the C main() doesn't call the C++ library
initializer needed to catch exceptions. Your environment may include
documentation on how to call this initializer. It's not on-topic here.

HTH,
Michiel Salters
 
A

Alfred.Cheong

By using LD_DEBUG, I find that a symbol binds to /usr/amd64/libc.so.1
is stead of /usr/sfw/lib/libgcc_s.so.1

25825: 1: symbol=_Unwind_RaiseException; lookup in
file=/lib/64/libc.so.1 [ ELF ]
25825: 1: binding file=/usr/share/centrifydc/lib/amd64/libstdc++.so.6
(0xfffffd7ffec1c71e:0xdc71e) at plt[502]:full to file=/lib/64/libc.so.1
(0xfffffd7fff1ac4b3:0xcc4b3): symbol `_Unwind_RaiseException'


If use LD_PRELOAD to preload /usr/sfw/lib/libgcc_s.so.1, it works fine.

Can I control the order look up symbols from libraries? I have already
use -R option.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top