Giter VIP home page Giter VIP logo

sulongexceptiontest's Introduction

Sulong Exception Test

This repo contains a minimal use-case for a bug in Sulong's C++ exception handling. When we try to catch a std::runtime_error in the C++ code, we get the following abort message printed to stderr.

libc++abi.dylib: Type error in sulong_eh_canCatch(…)
Syscalls (write) not supported on this OS.
Syscalls (write) not supported on this OS.
Syscalls (write) not supported on this OS.
Syscalls (write) not supported on this OS.
Syscalls (write) not supported on this OS.
Syscalls (write) not supported on this OS.
...

The Syscalls (write) portion runs forever (I know the syscalls message is because I'm on macOS. I haven't run it on a linux vm yet.

I tracked this down to the definition of sulong_eh_canCatch

unsigned int sulong_eh_canCatch(_Unwind_Exception *unwindHeader, std::type_info *catchType) {
    __cxa_exception *ex = cxa_exception_from_exception_unwind_exception(unwindHeader);
    void *p = thrown_object_from_cxa_exception(ex);
    __shim_type_info *et = dynamic_cast<__shim_type_info*>(ex->exceptionType); 
    __shim_type_info *ct = dynamic_cast<__shim_type_info*>(catchType);
    if (et == NULL || ct == NULL) { 
        abort_message("Type error in sulong_eh_canCatch(...).\n");
    }
    if (ct->can_catch(et, p)) {
        ex->adjustedPtr = p;
        return 1;
    } else {
        return 0;
    }
}

In the case that the C++ code throws a std::runtime_error, ex->exceptionType is an St13runtime_error and et becomes null. The exception never gets marshalled over into the Java code that I’ve got, so I’m unable to catch the error. I would have expected it to get wrapped in a RuntimeException so that I could handle it.

Building

I've checked in the bitcode file I compiled on macOS. To get a clean build, just run

mvn clean package && java -jar target/sulong-runtime-exception-1.0-SNAPSHOT.jar

sulongexceptiontest's People

Contributors

stabbylambda avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.