Stream: compiler development

Topic: windows setjmp/longjmp bug


view this post on Zulip Folkert de Vries (Jan 07 2024 at 17:29):

turns out setjmp/longjmp is broken on windows. I've added some info to an existing issue https://github.com/llvm/llvm-project/issues/72908#issuecomment-1880119269 but I'd say it's unlikely to be resolved given the amount of activity on that issue ...

@Brendan Hansknecht how are your LLVM skills at this point? could we figure this out ourselves?

view this post on Zulip Folkert de Vries (Jan 07 2024 at 17:30):

and cc @Luke Boswell who helped at least find this bug on our side. but I don't think we can fix it on our side

view this post on Zulip Folkert de Vries (Jan 07 2024 at 17:30):

except by using our own inline assembly of course

view this post on Zulip Brendan Hansknecht (Jan 07 2024 at 17:51):

As much as I work with llvm and mlir, I almost never touch the actual llvm codebase.

view this post on Zulip Richard Feldman (Jan 07 2024 at 17:55):

Folkert de Vries said:

I don't think we can fix it on our side

is it possible we could emit assembly or machine instructions there directly somehow?

view this post on Zulip Folkert de Vries (Jan 07 2024 at 17:56):

yeah we could have zig provide those

view this post on Zulip Folkert de Vries (Jan 07 2024 at 17:56):

we already need a workaround on aarch64 because llvm just does not generate anything for the setjmp/longjmp intrinsics

view this post on Zulip Folkert de Vries (Jan 07 2024 at 17:56):

though that might be fixed now? the issue that ayaz made is still open though

view this post on Zulip Folkert de Vries (Jan 07 2024 at 21:13):

ugh zig inline assembly does not support intel syntax... apparently for good reasons (in 2016) but cmon

view this post on Zulip Richard Feldman (Jan 07 2024 at 21:15):

chatgpt might be able to translate

view this post on Zulip Folkert de Vries (Jan 07 2024 at 21:23):

well yes but my eyes!

view this post on Zulip Folkert de Vries (Jan 07 2024 at 22:05):

@Luke Boswell can you try this one locally when you get a chance https://github.com/roc-lang/roc/pull/6363

view this post on Zulip Luke Boswell (Jan 07 2024 at 22:30):

        FAIL [   0.915s] test_gen::test_gen gen_panic::crash_in_passed_closure

--- STDOUT:              test_gen::test_gen gen_panic::crash_in_passed_closure ---

running 1 test
test gen_panic::crash_in_passed_closure - should panic ... FAILED

failures:

---- gen_panic::crash_in_passed_closure stdout ----
note: panic did not contain expected string
      panic message: `"Unrecognized builtin function: \"windows_longjmp\" - if you're working on the Roc compiler, do you need to rebuild the bitcode? See compiler/builtins/bitcode/README.md"`,
 expected substring: `"User crash with message: \"no new even primes\""`

failures:
    gen_panic::crash_in_passed_closure

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 1328 filtered out; finished in 0.89s


--- STDERR:              test_gen::test_gen gen_panic::crash_in_passed_closure ---
thread 'gen_panic::crash_in_passed_closure' panicked at 'Unrecognized builtin function: "windows_longjmp" - if you're working on the Roc compiler, do you need to rebuild the bitcode? See compiler/builtins/bitcode/README.md', crates\compiler\gen_llvm\src\llvm\bitcode.rs:104:28
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

   Canceling due to test failure
------------
     Summary [   0.918s] 1 test run: 0 passed, 1 failed, 1328 skipped
        FAIL [   0.915s] test_gen::test_gen gen_panic::crash_in_passed_closure

view this post on Zulip Folkert de Vries (Jan 07 2024 at 22:32):

hmm you may need a construction like this

// Zig won't expose the externs (and hence link correctly) unless we force them to be used.
fn __roc_force_setjmp(it: [*c]c_int) callconv(.C) c_int {
    return setjmp(it);
}
fn __roc_force_longjmp(a0: [*c]c_int, a1: c_int) callconv(.C) noreturn {
    longjmp(a0, a1);
}

to force an export?

view this post on Zulip Luke Boswell (Jan 07 2024 at 23:58):

What is the syntax of that global assembly in zig?

 \\.global windows_longjmp;
\\.type windows_longjmp, @function; # <<--- do we need something like this??? I added this and its wrong
\\windows_longjmp:
\\  movq 0x00(%rcx), %rdx
\\  movq 0x08(%rcx), %rbx

Looking at zig docs I wonder if we need to specify the symbol is a function?

view this post on Zulip Luke Boswell (Jan 08 2024 at 01:22):

Fixed :tada:

PS C:\Users\bosyl\Documents\GitHub\ROC> cargo nextest-gen-llvm gen_panic
   Compiling test_gen v0.0.1 (C:\Users\bosyl\Documents\GitHub\ROC\crates\compiler\test_gen)
    Finished test [unoptimized + debuginfo] target(s) in 8.44s
    Starting 4 tests across 1 binary (1325 skipped)
        PASS [   3.105s] test_gen::test_gen gen_panic::crash_in_passed_closure
        PASS [   4.193s] test_gen::test_gen gen_panic::crash_variable
        PASS [   4.380s] test_gen::test_gen gen_panic::crash_literal
        PASS [   4.422s] test_gen::test_gen gen_panic::crash_in_call
------------
     Summary [   4.424s] 4 tests run: 4 passed, 1325 skipped

view this post on Zulip Richard Feldman (Jan 08 2024 at 01:49):

woooooo!!!! :tada: :tada: :tada:


Last updated: Jul 06 2025 at 12:14 UTC