Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eagerly run TLS destructors to properly handle stack overflows #109858

Closed
wants to merge 4 commits into from

Conversation

joboet
Copy link
Member

@joboet joboet commented Apr 2, 2023

Fixes #109785 for UNIX systems with native TLS support.

By eagerly running the TLS destructors while the stack overflow handler is still active, stack overflows are now correctly reported. Since the destructors are invoked only after any user code has finished running, there should be no observable differences in behaviour. Also note that TLS destructors still work as expected for threads not created by std.

This also removes the specialized destructor registration implementations on Linux and macOS. Going through a native TLS key probably brings no noticeable performance degradations, and it simplifies the code considerably.

@rustbot
Copy link
Collaborator

rustbot commented Apr 2, 2023

r? @thomcc

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 2, 2023
@rustbot
Copy link
Collaborator

rustbot commented Apr 2, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-log-analyzer

This comment has been minimized.

@joboet
Copy link
Member Author

joboet commented Apr 2, 2023

It seems this doesn't work on Linux (I could only test on macOS). My current guess is that this fails because of some sigaltstack thing...

Resolved it by running the destructors eagerly.

@joboet joboet marked this pull request as draft April 2, 2023 13:27
@thomcc
Copy link
Member

thomcc commented Apr 4, 2023

@rustbot author

@rustbot rustbot 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 Apr 4, 2023
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@joboet joboet changed the title Make stack guard page location available during TLS destruction Eagerly run TLS destructors to properly handle stack overflows Apr 6, 2023
@joboet joboet marked this pull request as ready for review April 6, 2023 12:10
@joboet
Copy link
Member Author

joboet commented Apr 6, 2023

@rustbot ready

@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 Apr 6, 2023
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-14 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
running 16 tests
error: test failed, to rerun pass `--lib`

Caused by:
  process didn't exit successfully: `/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/proc_macro_srv-9ede8e52d0dfb500 -Z unstable-options --format json` (signal: 11, SIGSEGV: invalid memory reference)
.............Build completed unsuccessfully in 0:25:47

@joboet
Copy link
Member Author

joboet commented Apr 6, 2023

@rustbot author

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 6, 2023
@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 6, 2023
@m-ou-se m-ou-se assigned m-ou-se and unassigned thomcc Apr 26, 2023
@workingjubilee workingjubilee linked an issue May 6, 2023 that may be closed by this pull request
@JohnCSimon
Copy link
Member

@joboet

ping from triage - can you post your status on this PR? There hasn't been an update in a few months. Thanks!

FYI: when a PR is ready for review, send a message containing
@rustbot ready to switch to S-waiting-on-review so the PR is in the reviewer's backlog.

@joboet
Copy link
Member Author

joboet commented Jun 21, 2023

I'm still completely lost as to what the issue here might be, but I'll make sure to change the status again once I've found it. Until then I'd like to keep this open if it's alright with you, just so that the tracking issue has an open PR to link to.

@bors
Copy link
Contributor

bors commented Sep 20, 2023

☔ The latest upstream changes (presumably #115753) made this pull request unmergeable. Please resolve the merge conflicts.

@joboet
Copy link
Member Author

joboet commented Oct 18, 2023

I'm marking this as a draft until #116850 is merged, which should simplify the changes here, while preserving the platform-specific parts.

@joboet joboet marked this pull request as draft October 18, 2023 14:33
@Dylan-DPC Dylan-DPC added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 21, 2023
@joboet
Copy link
Member Author

joboet commented Jun 28, 2024

I've found a better way to implement this and will put that up after #126953 is merged.

@joboet joboet closed this Jun 28, 2024
@joboet joboet deleted the tls_stack_overflow branch June 28, 2024 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-blocked Status: Blocked on something else such as an RFC or other implementation work. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
9 participants