Skip to content

Handle multiple action records in EH personality function - #160923

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
nbdd0121:eh_personality
Aug 31, 2026
Merged

Handle multiple action records in EH personality function#160923
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
nbdd0121:eh_personality

Conversation

@nbdd0121

Copy link
Copy Markdown
Member

LSDA encodes actions are a linked list, we currently only decode the first one. Action records are used for catching specific exception types and for exception specifications, and none of these are present in Rust. However we can still have of multiple of them being present due to LLVM inlining. When this happens, "Catch" is the correct action to execute.

We haven't had issues with this because LLVM orders cleanup record last; however GCC doesn't use the same order, so we do need to explicitly handle this case to support both LLVM and GCC codegen.

See https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Possible.20bug.20in.20unwind.20function.20in.20std/with/615883393

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 11, 2026
@rust-log-analyzer

This comment has been minimized.

@antoyo

antoyo commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Thanks for fixing this!

I did the test on my side and it seems to work.
Before this PR, I would get this with cg_gcc:

fatal runtime error: failed to initiate panic, error 5, aborting

and with this PR, I get the correct behavior in my reproducer.

@rust-log-analyzer

This comment has been minimized.

@nbdd0121

Copy link
Copy Markdown
Member Author

r? bjorn3

perhaps?

@nbdd0121
nbdd0121 marked this pull request as ready for review August 11, 2026 19:11
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 11, 2026
// Note that even for the case of "cleanup" + "filter", decoding them as "catch" is
// fine: "filter" behaves identically to "catch" except for forced unwind; in case of
// forced unwind, hitting a "cleanup" landing pad is UB as it indicates that we're
// unwinding past a non-POF Rust frame.

@bjorn3 bjorn3 Aug 27, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there are two cleanup actions for whatever reason? Should this explicitly check that at least one action is a filter or catch if there are multiple ones and abort otherwise?

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'll be a compiler bug? I don't think we should defend against something that won't happen at a cost of code size.

Also, nothing will be catastrophically wrong even if we catch a cleanup frame, we will just be skipping phase 1 of unwind and perform phase 2 unwind for further stack frames, similar to forced unwind.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't the unwinder misbehave if you _Unwind_Resume out of a frame that you said is a catch?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might unwind more frames, but nothing will be terribly wrong. Anyhow, neither GCC nor LLVM will emit duplicate action record entry, so I don't think this is worth handling.

@bjorn3 bjorn3 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 27, 2026
Comment thread tests/ui/panics/lsda-multiple-action.rs Outdated
@bjorn3

bjorn3 commented Aug 30, 2026

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-bors Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

📌 Commit bf56fa4 has been approved by bjorn3

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 30, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 30, 2026
Handle multiple action records in EH personality function

LSDA encodes actions are a linked list, we currently only decode the first one. Action records are used for catching specific exception types and for exception specifications, and none of these are present in Rust. However we can still have of multiple of them being present due to LLVM inlining. When this happens, "Catch" is the correct action to execute.

We haven't had issues with this because LLVM orders cleanup record last; however GCC doesn't use the same order, so we do need to explicitly handle this case to support both LLVM and GCC codegen.

See https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Possible.20bug.20in.20unwind.20function.20in.20std/with/615883393
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 30, 2026
Handle multiple action records in EH personality function

LSDA encodes actions are a linked list, we currently only decode the first one. Action records are used for catching specific exception types and for exception specifications, and none of these are present in Rust. However we can still have of multiple of them being present due to LLVM inlining. When this happens, "Catch" is the correct action to execute.

We haven't had issues with this because LLVM orders cleanup record last; however GCC doesn't use the same order, so we do need to explicitly handle this case to support both LLVM and GCC codegen.

See https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Possible.20bug.20in.20unwind.20function.20in.20std/with/615883393
rust-bors Bot pushed a commit that referenced this pull request Aug 30, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - #137720 (support `#[target_feature(enable = ...)]` on `#[naked]` functions)
 - #160923 (Handle multiple action records in EH personality function)
 - #161788 (Check to ensure we're running against the correct LLVM version)
 - #161644 (bootstrap: Flatten and rename `compute_src_directory_via_git`)
 - #161702 (Use `drop_guard` in some places in {core,alloc,std})
 - #161931 (Revert "Add rustc_test_entrypoint_marker")
 - #162015 (touch up "get attribute" docs.)
 - #162019 (remove a couple of redundant clones, thanks clippy)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 30, 2026
Handle multiple action records in EH personality function

LSDA encodes actions are a linked list, we currently only decode the first one. Action records are used for catching specific exception types and for exception specifications, and none of these are present in Rust. However we can still have of multiple of them being present due to LLVM inlining. When this happens, "Catch" is the correct action to execute.

We haven't had issues with this because LLVM orders cleanup record last; however GCC doesn't use the same order, so we do need to explicitly handle this case to support both LLVM and GCC codegen.

See https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Possible.20bug.20in.20unwind.20function.20in.20std/with/615883393
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 30, 2026
Handle multiple action records in EH personality function

LSDA encodes actions are a linked list, we currently only decode the first one. Action records are used for catching specific exception types and for exception specifications, and none of these are present in Rust. However we can still have of multiple of them being present due to LLVM inlining. When this happens, "Catch" is the correct action to execute.

We haven't had issues with this because LLVM orders cleanup record last; however GCC doesn't use the same order, so we do need to explicitly handle this case to support both LLVM and GCC codegen.

See https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Possible.20bug.20in.20unwind.20function.20in.20std/with/615883393
rust-bors Bot pushed a commit that referenced this pull request Aug 30, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - #160923 (Handle multiple action records in EH personality function)
 - #161788 (Check to ensure we're running against the correct LLVM version)
 - #158303 (Always escape grapheme extenders in `str::escape_debug`)
 - #161644 (bootstrap: Flatten and rename `compute_src_directory_via_git`)
 - #161702 (Use `drop_guard` in some places in {core,alloc,std})
 - #161713 (Add config for gram editor to .gitignore)
 - #161792 (Fix and improve diagnostics for lint `rust_2021_prefixes_incompatible_syntax`)
 - #161931 (Revert "Add rustc_test_entrypoint_marker")
 - #162015 (touch up "get attribute" docs.)
 - #162019 (remove a couple of redundant clones, thanks clippy)
 - #162023 (Remove redundant braces from `NonZero` doctests)
rust-bors Bot pushed a commit that referenced this pull request Aug 30, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - #160923 (Handle multiple action records in EH personality function)
 - #161788 (Check to ensure we're running against the correct LLVM version)
 - #158303 (Always escape grapheme extenders in `str::escape_debug`)
 - #161644 (bootstrap: Flatten and rename `compute_src_directory_via_git`)
 - #161702 (Use `drop_guard` in some places in {core,alloc,std})
 - #161713 (Add config for gram editor to .gitignore)
 - #161792 (Fix and improve diagnostics for lint `rust_2021_prefixes_incompatible_syntax`)
 - #161931 (Revert "Add rustc_test_entrypoint_marker")
 - #162015 (touch up "get attribute" docs.)
 - #162019 (remove a couple of redundant clones, thanks clippy)
 - #162023 (Remove redundant braces from `NonZero` doctests)
@rust-bors
rust-bors Bot merged commit e750bc2 into rust-lang:main Aug 31, 2026
13 checks passed
rust-bors Bot pushed a commit that referenced this pull request Aug 31, 2026
Rollup merge of #160923 - nbdd0121:eh_personality, r=bjorn3

Handle multiple action records in EH personality function

LSDA encodes actions are a linked list, we currently only decode the first one. Action records are used for catching specific exception types and for exception specifications, and none of these are present in Rust. However we can still have of multiple of them being present due to LLVM inlining. When this happens, "Catch" is the correct action to execute.

We haven't had issues with this because LLVM orders cleanup record last; however GCC doesn't use the same order, so we do need to explicitly handle this case to support both LLVM and GCC codegen.

See https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/Possible.20bug.20in.20unwind.20function.20in.20std/with/615883393
@rustbot rustbot added this to the 1.100.0 milestone Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants