Segfault when linking cudart statically and using exceptions


I encounter a segmentation fault when using exceptions and linking against libcudart_static.a. The problem goes away when linking against I’m curious to learn why this happens. Below is a description of my setup.

Source code:

#include <stdexcept>
#include <cuda_runtime.h>

void foo()
    throw std::runtime_error("Foo");

int main()
    int* ptr{};
    auto err = cudaMalloc(&ptr, 128);
    if (cudaSuccess != err)
        return 1;

    try {
    catch (const std::runtime_error&)


#0  linear_search_fdes (ob=0x7fffffffd580, this_fde=0x0, pc=0x403df7 <foo()+65>) at ../../../gcc/libgcc/unwind-dw2-fde.c:969
#1  0x00007ffff7dc0e11 in find_fde_tail (dbase=18446744073709383432, bases=0x7fffffffd7d8, hdr=0x4aa594, pc=4210167) at ../../../gcc/libgcc/unwind-dw2-fde-dip.c:519
#2  _Unwind_Find_FDE (pc=<optimized out>, bases=bases@entry=0x7fffffffd7d8) at ../../../gcc/libgcc/unwind-dw2-fde-dip.c:573
#3  0x00007ffff7dbc4aa in uw_frame_state_for (context=0x7fffffffd730, fs=0x7fffffffd820) at ../../../gcc/libgcc/unwind-dw2.c:1005
#4  0x00007ffff7dbdefd in _Unwind_RaiseException (exc=0xcfc520) at ../../../gcc/libgcc/
#5  0x00007ffff79fdd8a in __cxa_throw ()
   from /path/to/
#6  0x0000000000403df8 in foo() ()
#7  0x0000000000403e44 in main ()

I am running this on the following setup:

  • Ubuntu 20.04.
  • cuda-cudart-11-7_11.7.99-1_amd64.deb.
  • GCC 13.1 built from source.

I am aware that NVCC does not support GCC > 11, but in this case I’m not using NVCC, just plain C++ code and linking external libraries, so I don’t see the reason why it shouldn’t work. We’d prefer to keep linking cudart statically instead of dynamically.

Do you have any feeling for what the problem might be?