I had a recent problem where a thrown C++ exception was not caught and instead leads to program termination.
My current MWE is:
#include <stdexcept>
#include <cupti.h>
void foo(){
CUpti_SubscriberHandle subscriber;
cuptiSubscribe(&subscriber, (CUpti_CallbackFunc) 0, 0);
}
int main(){
try{
throw std::runtime_error("Hello");
}catch(...){
}
}
Compiling with g++ testRaise.cpp /sw/installed/CUDAcore/11.1.1/extras/CUPTI/lib64/libcupti_static.a -ldl -lpthread -lrt
and running leads to terminate called after throwing an instance of 'std::runtime_error'
which I can't explain.
What I found so far ("works"="exception is caught"):
- Using the default linker works, using the gold linker does not
- Using the shared libcupti works, that static does not (even though it is not called!)
nm libcupti_static.a
doesn't show anything unusual, i.e. especially no libstdc++ symbols- Tried GCC 10.2 and a few other random system compilers, all break when using gold linker
- Debugging shows nothing unusual as far as I can tell but it ends up at https://github.com/gcc-mirror/gcc/blob/releases/gcc-10.2.0/libstdc++-v3/libsupc++/eh_throw.cc#L95 which hints at an unwind error
- For the broken code I see that during unwinding this part is reached, which is not for the working version: https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/libgcc/unwind-dw2-fde-dip.c#L438
As CUPTI is proprietary I don't know how that was build, but I fail to see how linking a static library can break the C++ exception handling/unwinding mechanism
Does anyone know, what could cause this, how it can be checked/verified and avoided?