Skip to content

SIGSEGV trying to compile code that uses fn pointers #590

@mauricioszabo

Description

@mauricioszabo

jank health check

─ system ───────────────────────────────────────────────────────────────────────────────────────────
─ ✅ operating system: linux
─ ✅ default triple: x86_64-unknown-linux-gnu

─ jank install ─────────────────────────────────────────────────────────────────────────────────────
─ ✅ jank version: jank-0.1-6ebd32966e07133861a5734e892a5cfc02bca024
─ ✅ jank resource dir: ../lib/jank/0.1
─ ✅ jank resolved resource dir: /usr/local/bin/../lib/jank/0.1 (found)
─ ✅ jank user cache dir: /home/mauricio/.cache/jank/x86_64-unknown-linux-gnu-8ef9488056101afe1d0969786e5dc264017e65e64f3b420fe6ba9d169dbf29e9 (found)

─ clang install ────────────────────────────────────────────────────────────────────────────────────
─ ⚠ configured clang path: /home/runner/work/jank/jank/compiler+runtime/build/llvm-install/usr/local/bin/clang++ (not found)
─ ✅ runtime clang path: /usr/local/bin/../lib/jank/0.1/bin/clang++ (found)
─ ⚠ configured clang resource dir: /home/runner/work/jank/jank/compiler+runtime/build/llvm-install/usr/local/lib/clang/22 (not found)
─ ✅ runtime clang resource dir: /usr/local/lib/jank/0.1/lib/clang/22 (found)

─ jank runtime ─────────────────────────────────────────────────────────────────────────────────────
─ ✅ jank runtime initialized
─ ✅ jank pch path: /home/mauricio/.cache/jank/x86_64-unknown-linux-gnu-8ef9488056101afe1d0969786e5dc264017e65e64f3b420fe6ba9d169dbf29e9 (found)
─ ✅ jank can jit compile c++
─ ✅ jank can jit compile llvm ir
─ ✅ jank can aot compile working binaries

Description of the issue with reproduction steps

This is somewhat related to #589 - I found this issue while trying to work-around the case. Basically, this code:

(ns types)

(cpp/raw "
#ifndef DUP_CODE
#define DUP_CODE

typedef uintptr_t VALUE;

#define ANYARGS ...

static void rb_define_method(VALUE (*func)(ANYARGS), int arity) {
}

static VALUE some_code(VALUE self, VALUE a) {
  return a;
}

#define RBIMPL_CAST(expr) (expr)

#define RUBY_METHOD_FUNC(func) RBIMPL_CAST((VALUE (*)(ANYARGS))(func))

static auto some_code_1 = RUBY_METHOD_FUNC(some_code);

#endif
 ")

(defn -main [ & args]
  (cpp/rb_define_method cpp/some_code_1 (cpp/cast cpp/int  0)))

Fails to compile with Jank:

jank --module-path . compile types
fish: Job 1, 'jank --module-path . compile ty…' terminated by signal SIGSEGV (Address boundary error)

The offending code seems to be this some_code_1 - if I try to use it in a callback fn (to avoid making a wrapper) I'll get this error.

Stack trace

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions