[llvm-bugs] [Bug 34424] New: Throwing C++ exception after getting address of JITted function causes segfault.

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Sep 2 01:13:35 PDT 2017


            Bug ID: 34424
           Summary: Throwing C++ exception after getting address of JITted
                    function causes segfault.
           Product: new-bugs
           Version: 4.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: samuelmarinelli at gmail.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 19078
  --> https://bugs.llvm.org/attachment.cgi?id=19078&action=edit
Source file reproducing the bug.

I have a simple JIT implementation that JITs a function, gets its address,
calls it, and removes it from the JIT.  After doing this, I find that any throw
of a C++ exception, caught or uncaught, causes a segfault.

The attached source file is a minimal example.  In fact calling the JITted
function is unnecessary to produce the error; all that's necessary is to get
its address by calling llvm::JITSymbol::getAddress on the symbol produced by

Removing the call to getAddress in line 88 produces a non-segfaulting
executable, as does removing the call to
IRCompileLayer<ObjectLinkingLayer<>>::removeModuleSet in line 90.

I compile the code using the following command.

    g++ -g main.cc `llvm-config --cxxflags --ldflags --system-libs --libs \
    core mcjit native` -O0 -o example -std=c++17 -Wall -Wextra            \
    -Wno-unused-function -Wno-unused-value -Wno-unused-parameter -Werror

I'm using LLVM 4.0.1 and GCC 7.1.1 on Arch Linux.  I explicitly turned on
exception handling in LLVM during the build using -DLLVM_ENABLE_EH=ON, thinking
that the default --fno-exceptions flag passed to the compiler might to blame,
but no such luck.

Here's the backtrace from GDB.

Program received signal SIGSEGV, Segmentation fault.
classify_object_over_fdes (ob=0x101437c00,
this_fde=this_fde at entry=0x7fe5b0413000) at
641     /build/gcc/src/gcc/libgcc/unwind-dw2-fde.c: No such file or directory.
(gdb) bt
#0  classify_object_over_fdes (ob=0x101437c00,
this_fde=this_fde at entry=0x7fe5b0413000) at
#1  0x00007fe5aeeab7d8 in init_object (ob=0x101437c00) at
#2  search_object (ob=ob at entry=0x101437c00, pc=pc at entry=0x7fe5aeeaa17d
<_Unwind_RaiseException+61>) at /build/gcc/src/gcc/libgcc/unwind-dw2-fde.c:989
#3  0x00007fe5aeeac666 in _Unwind_Find_registered_FDE (bases=0x7fffffffddc8,
pc=0x7fe5aeeaa17d <_Unwind_RaiseException+61>)
    at /build/gcc/src/gcc/libgcc/unwind-dw2-fde.c:1066
#4  _Unwind_Find_FDE (pc=0x7fe5aeeaa17d <_Unwind_RaiseException+61>,
bases=bases at entry=0x7fffffffddc8) at
#5  0x00007fe5aeea8a73 in uw_frame_state_for
(context=context at entry=0x7fffffffdd20, fs=fs at entry=0x7fffffffdb70) at
#6  0x00007fe5aeea9ce0 in uw_init_context_1
(context=context at entry=0x7fffffffdd20,
outer_cfa=outer_cfa at entry=0x7fffffffe0d0, outer_ra=
    0x7fe5af452ec6 <__cxxabiv1::__cxa_throw(void*, std::type_info*, void
(*)(void*))+54>) at /build/gcc/src/gcc/libgcc/unwind-dw2.c:1578
#7  0x00007fe5aeeaa17e in _Unwind_RaiseException (exc=exc at entry=0x101426b10) at
#8  0x00007fe5af452ec6 in __cxxabiv1::__cxa_throw (obj=<optimized out>,
tinfo=0x7fe5af73ea90 <typeinfo for std::runtime_error>, 
    dest=0x7fe5af468500 <std::runtime_error::~runtime_error()>) at
#9  0x000000010012fa5e in main () at main.cc:94

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170902/555997cf/attachment.html>

More information about the llvm-bugs mailing list