Throwing exceptions causes SIGSEGV on OSX 10.11.4 + clang

Given the following code:

#include <stdexcept>
#include <string>

using namespace std;

class exception_base : public runtime_error {
public:
    exception_base() 
    : runtime_error(string()) { }
};

class my_exception : public exception_base {
public:

};

int main() {
    throw my_exception();
}

This works fine on GNU / Linux and Windows, and works fine on OSX until the last update to version 10.11.4. More precisely, I mean that nothing will catch the exception being called std::terminate.

However, in OSX 10.11.4 using clang (LLVM 7.3.0), the program crashes with a segmentation error. Stack tracing does not help:

Program received signal SIGSEGV, Segmentation fault.
0x0000000100000ad1 in main () at test.cpp:17
17      throw my_exception();
(gdb) bt
#0  0x0000000100000ad1 in main () at test.cpp:17
(gdb)

Not that Walgrind has to say about this:

==6500== Process terminating with default action of signal 11 (SIGSEGV)
==6500==  General Protection Fault
==6500==    at 0x100000AD1: main (test.cpp:17)

I don't think this code is in any way violating the standard. Did I miss something?

Please note that even if I add try-catch around throw, the code still crashes due to SIGSEGV.

+4
source share
1

, , SSE movaps (GP):

a.out`main:
    0x100000ad0 :   pushq  %rbp
    0x100000ad1 :   movq   %rsp, %rbp
    0x100000ad4 :   subq   $0x20, %rsp
    0x100000ad8 :   movl   $0x0, -0x4(%rbp)
    0x100000adf :  movl   $0x10, %eax
    0x100000ae4 :  movl   %eax, %edi
    0x100000ae6 :  callq  0x100000dea               ; symbol stub for: __cxa_allocate_exception
    0x100000aeb :  movq   %rax, %rdi
    0x100000aee :  xorps  %xmm0, %xmm0
->  0x100000af1 :  movaps %xmm0, (%rax)
    0x100000af4 :  movq   %rdi, -0x20(%rbp)
    0x100000af8 :  movq   %rax, %rdi
    0x100000afb :  callq  0x100000b40               ; my_exception::my_exception
...

, my_exception:: my_exception() , movaps , __cxa_allocate_exception (size_t). (0x0000000100103498 ) 16 . movaps , 16- GP.

SSE (-mno-sse). , SSE .

, http://reviews.llvm.org/D18479:

r246985 , , Itanium , _Unwind_Exception , __attribute__((aligned)), 16 . , lib++ abi __attribute__((aligned)) 8- 32- 64- . , SIMD, 16- (, movaps).

ItaniumCXXABI:: getAlignmentOfExnObject 8- .

.. 31 2016 r264998.

https://llvm.org/bugs/show_bug.cgi?id=24604 https://llvm.org/bugs/show_bug.cgi?id=27208 .

UPDATE Xcode 7.3.1 ( ), ; :

a.out`main:
    0x100000ac0 :   pushq  %rbp
    0x100000ac1 :   movq   %rsp, %rbp
    0x100000ac4 :   subq   $0x20, %rsp
    0x100000ac8 :   movl   $0x0, -0x4(%rbp)
    0x100000acf :  movl   $0x10, %eax
    0x100000ad4 :  movl   %eax, %edi
    0x100000ad6 :  callq  0x100000dea               ; symbol stub for: __cxa_allocate_exception
    0x100000adb :  movq   %rax, %rdi
    0x100000ade :  movq   $0x0, 0x8(%rax)
    0x100000ae6 :  movq   $0x0, (%rax)
    0x100000aed :  movq   %rdi, -0x20(%rbp)
    0x100000af1 :  movq   %rax, %rdi
    0x100000af4 :  callq  0x100000b40               ; my_exception::my_exception
...
+1

All Articles