tensorush/libzigunwind
1
0
Fork
You've already forked libzigunwind
1

feat: add sjlj exception handling #3

Merged
tensorush merged 1 commit from abm-77/libzigunwind:port-sjlj into main 2025年05月19日 17:33:29 +02:00
Contributor
Copy link

This is a PR to add setjmp/longjmp exception handling to libzigunwind. Fixes #2.

This is a PR to add setjmp/longjmp exception handling to libzigunwind. Fixes #2.
Author
Contributor
Copy link

Hi @tensorush, this is my first long-form Zig contribution, so I am sure there are many mistakes. Happy to work together to get this into a state you envision for the project. I had a couple of questions about the SJLJ port:

  1. How should we be referencing longjmp in unwindPhase2 and unwindPhase2Forced? Currently, I declare it as an external symbol.
  2. How should we handle the __ve__ configuration? Right now, I default to 64-bit pointers for the resumeLocation and resumeParameters, but it seems like we should only do this when __ve__ is defined 32-bit pointers otherwise. Is this something we can get from builtin or the config?
  3. How do you envision we switch between exception handling implementations?
  4. Do you intend to port over the tests defined in the original libunwind, or should we look to create more comprehensive tests?
Hi @tensorush, this is my first long-form Zig contribution, so I am sure there are many mistakes. Happy to work together to get this into a state you envision for the project. I had a couple of questions about the SJLJ port: 1. How should we be referencing `longjmp` in `unwindPhase2` and `unwindPhase2Forced`? Currently, I declare it as an external symbol. 2. How should we handle the `__ve__` configuration? Right now, I default to 64-bit pointers for the `resumeLocation` and `resumeParameters`, but it seems like we should only do this when `__ve__` is defined 32-bit pointers otherwise. Is this something we can get from `builtin` or the config? 3. How do you envision we switch between exception handling implementations? 4. Do you intend to port over the [tests](https://github.com/allyourcodebase/libunwind/tree/main/libunwind/test) defined in the original libunwind, or should we look to create more comprehensive tests?

Hi, thanks for taking this on, here're my thoughts:

  1. Yes, that's fine. That function is implemented in libc, so it will have (or maybe already has) a Zig implementation as part of libzigc.
  2. #if defined(__ve__) translates to Zig as if (builtin.cpu.arch == .ve). So, in that instance it means that on the Ve architecture those fields should be u64, otherwise, they should be u32.
  3. That one's tricky, it mostly depends on the ABI (builtin.abi). As Alex pointed out, it's worth looking at how Clang defines those macros, like __USING_SJLJ_EXCEPTIONS__ or __SEH__. Although, I haven't looked too much into it yet, I doubt it'll be as straightforward to do in Zig, so I think we might have to add another config option to switch on manually, at least for now.
  4. Yep, I intend to incorporate them as test functions at the end of respective implementation files. More tests are definitely welcome.
Hi, thanks for taking this on, here're my thoughts: 1. Yes, that's fine. That function is implemented in `libc`, so it will have (or maybe already has) a Zig implementation as part of `libzigc`. 2. `#if defined(__ve__)` translates to Zig as `if (builtin.cpu.arch == .ve)`. So, in that instance it means that on the Ve architecture those fields should be `u64`, otherwise, they should be `u32`. 3. That one's tricky, it mostly depends on the ABI (`builtin.abi`). [As Alex pointed out](https://github.com/ziglang/zig/issues/23560#issuecomment-2845440625), it's worth looking at how Clang defines those macros, like `__USING_SJLJ_EXCEPTIONS__` or `__SEH__`. Although, I haven't looked too much into it yet, I doubt it'll be as straightforward to do in Zig, so I think we might have to add another config option to switch on manually, at least for now. 4. Yep, I intend to incorporate them as test functions at the end of respective implementation files. More tests are definitely welcome.
Author
Contributor
Copy link
  1. Gotcha, I'll leave as is for now.
  2. Cool, just made that change.
  3. I see. I will add a build option like use_sjlj_exceptions. We can use this to conditionally link libc (unless we need it for anything else) and eventually conditionally enabling SJLJ exception handling when we decide on how we expose the functionality to users.
  4. Great, makes sense.
1. Gotcha, I'll leave as is for now. 2. Cool, just made that change. 3. I see. I will add a build option like `use_sjlj_exceptions`. We can use this to conditionally link libc (unless we need it for anything else) and eventually conditionally enabling SJLJ exception handling when we decide on how we expose the functionality to users. 4. Great, makes sense.
Author
Contributor
Copy link

I think at this point I have faithfully ported over the original C file. I am currently looking to create functional tests for validating the implementation.

I think at this point I have faithfully ported over the original C file. I am currently looking to create functional tests for validating the implementation.

LGTM. Don't forget to change the PR from Draft when you're ready to have it merged.

LGTM. Don't forget to change the PR from Draft when you're ready to have it merged.

I think I'll go ahead and merge it with the rest now. Feel free to contribute more in another PR. Thanks again!

I think I'll go ahead and merge it with the rest now. Feel free to contribute more in another PR. Thanks again!
tensorush changed title from (削除) WIP: feat: add sjlj exception handling (削除ここまで) to feat: add sjlj exception handling 2025年05月19日 17:30:47 +02:00
Author
Contributor
Copy link

Great, no worries. Sorry about the delayed communication!

Great, no worries. Sorry about the delayed communication!
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
tensorush/libzigunwind!3
Reference in a new issue
tensorush/libzigunwind
No description provided.
Delete branch "abm-77/libzigunwind:port-sjlj"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?