Skip to content

Support/jitlink coff seh llvm 22#3

Open
ikappaki wants to merge 15 commits into
jank-lang:jank-snapshot/llvm22from
ikappaki:support/jitlink-coff-seh-llvm-22
Open

Support/jitlink coff seh llvm 22#3
ikappaki wants to merge 15 commits into
jank-lang:jank-snapshot/llvm22from
ikappaki:support/jitlink-coff-seh-llvm-22

Conversation

@ikappaki

Copy link
Copy Markdown

Backport of the LLVM SEH support changes from lhames#5 to the Jank LLVM 22 branch.

Original description follows.


This PR promotes the WindowsEasyEHPlugin to a library level plugin and fixes the prerequisite JITLink COFF bugs needed to make C++ exceptions work end to end through LLJIT on msys2/mingw.

The fixes were developed iteratively using jank as the test driver. Each iteration: run jank's test suite, hit a crash or link error, write a minimal lit test that reproduces the failure, diagnose the root cause, implement the fix, confirm the lit test passes, then move on to the next failure.

Tests were written with AI assistance and verified with the fail before/pass after principle. Mentioning for transparency, they could benefit from an expert eye. Feedback welcome. I leave it to you whether you'd like to keep them.

The implementation code includes comments at the API level and inside functions where the reasoning isn't obvious from the code alone.

Changes:

  1. Enable JITLink for COFF x86_64 (2019be527937) - Previously LLJIT explicitly excluded COFF (UseJITLink = !TT.isOSBinFormatCOFF()), falling back to RTDyld. Test: coff-imagebase-resolution.ll (basic JITLink linking).

  2. Resolve __ImageBase before ADDR32NB lowering (8fcef754b66c) - __ImageBase was left at address 0, so .pdata/.xdata image-relative offsets were computed as absolute addresses overflowing 32 bits and crashing the unwinder. Test: coff-imagebase-resolution.ll.

  3. Add GOT/PLT stubs for external calls (5bb976340d29) - External DLL calls use 32bit PC relative branches that can't reach targets beyond 2GB. Without stubs, calls to DLL functions (e.g. puts) crash with out of range relocations. Test: coff-plt-stubs.ll.

  4. Add ADDR32NB stubs for image relative external references (f9f8a22050de) - .xdata references the personality function via a 32bit image relative offset, but externals in DLLs are too far away. An executable stub near JIT'd code bridges the gap. Test: coff-addr32nb-stubs.ll.

  5. Fix COMDAT section-definition symbol registration (59c2bca9d561) - The first symbol in a COMDAT pair wasn't registered in the graph symbol table, so .pdata relocations referencing it by index failed with "Could not find symbol at given index." Test: coff-comdat-relocation.ll.

  6. Set OverrideObjectFlags for JITLink on COFF (f226c46abf37) - COFF has no hidden visibility, all externals become Exported. Without the override, hidden visibility IR symbols (e.g. __lljit_run_atexits) trigger a "Resolving symbol with incorrect flags" assertion. Test: trivial-return-zero.ll (existing test now passes).

  7. Add SEHFrameRegistrationPlugin (8327fd89a8a3) — Promotes WindowsEasyEHPlugin into a library level plugin, wired into setUpGenericLLVMIRPlatform so all LLJIT users get SEH registration automatically. Test: coff-seh-registration.ll.

  8. Add filtered DLLImportDefinitionGenerator (905aef3d2517) - Only forwards __imp_ prefixed symbols. Without the filter, the generator intercepts personality function lookups and creates conflicting null stubs, crashing the unwinder. Test: coff-dllimport-filter.ll.

  9. Extend SEHFrameKeepAlivePass for COMDAT .pdata$* (4198c1650b54) - The pass only matched the exact name .pdata, so COMDAT sections like .pdata$comdat_fn were dead-stripped and their unwind info lost. Test: coff-comdat-pdata-keepalive.ll.

  10. Remove dead findDefinedSymbolByName from GetImageBaseSymbol (1b574b035c62) - __ImageBase is always external or absolute, never defined. The scan over all defined symbols was unnecessary dead code. Test: coff-imagebase-lookup-perf.ll.

  11. Add end-to-end integration tests (13c2f438225e) - C++ throw/catch through multiple JIT'd frames (with and without frame pointers), exercising the full SEH pipeline. Tests: throw-catch-mingw-seh.ll, throw-catch-mingw-seh-no-fp.ll.

Happy to answer any follow up questions regarding any of the fixes.

Thanks

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ ikappaki
❌ lhames
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants