Skip to content

deduplicate abort implementations #139103

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

joboet
Copy link
Member

@joboet joboet commented Mar 29, 2025

Currently, the code for process aborts is duplicated across panic_abort and std. This PR uses #[rustc_std_internal_symbol] to make the std implementation available to panic_abort via the linker, thereby deduplicating the code.

@rustbot
Copy link
Collaborator

rustbot commented Mar 29, 2025

r? @tgross35

rustbot has assigned @tgross35.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added O-hermit Operating System: Hermit O-SGX Target: SGX O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 29, 2025
@rustbot
Copy link
Collaborator

rustbot commented Mar 29, 2025

These commits modify the library/Cargo.lock file. Unintentional changes to library/Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Mar 29, 2025

The Miri subtree was changed

cc @rust-lang/miri

@rust-log-analyzer

This comment has been minimized.

Comment on lines 333 to 337
/// In Windows 8 and later, this will terminate the process immediately without
/// running any in-process exception handlers. In earlier versions of Windows,
/// this sequence of instructions will be treated as an access violation,
/// terminating the process but without necessarily bypassing all exception
/// handlers.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// In Windows 8 and later, this will terminate the process immediately without
/// running any in-process exception handlers. In earlier versions of Windows,
/// this sequence of instructions will be treated as an access violation,
/// terminating the process but without necessarily bypassing all exception
/// handlers.
/// In Windows 8 and later, this will terminate the process immediately,
/// bypassing all in-process exception handlers. In earlier versions of Windows,
/// this sequence of instructions will be treated as an access violation,
/// terminating the process but without necessarily bypassing all exception
/// handlers.

Let's use the same verb both times, otherwise this is unnecessarily confusing since it uses "without" twice to actually make statements that are opposites of each other.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've rephrased the comment a bit to make it even clearer.

@@ -1,6 +1,6 @@
//@error-in-other-file: the program aborted execution
//@normalize-stderr-test: "\| +\^+" -> "| ^"
//@normalize-stderr-test: "unsafe \{ libc::abort\(\); \}|core::intrinsics::abort\(\);" -> "ABORT();"
//@normalize-stderr-test: "unsafe \{ libc::abort\(\) \}|core::intrinsics::abort\(\)" -> "ABORT()"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
//@normalize-stderr-test: "unsafe \{ libc::abort\(\) \}|core::intrinsics::abort\(\)" -> "ABORT()"
//@normalize-stderr-test: "unsafe \{ libc::abort\(\) \}|crate::intrinsics::abort\(\)" -> "ABORT()"

Copy link
Contributor

Choose a reason for hiding this comment

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

Are either of these needed? Since crate::intrinsics::abort is now normalized in src/tools/miri/tests/ui.rs

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

This will be a nice cleanup. Cc @bjorn3 since this makes some use of internal symbol mangling changes.

Overall looks pretty good to me, @rustbot author for the CI failure

// Note: contrary to the `__rust_abort` in `crate::rt`, this uses `no_mangle`
// because it is actually used from C code. Because symbols annotated with
// #[rustc_std_internal_symbol] get mangled, this will not lead to linker
// conflicts.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could they get different symbol names? Having the same extern signature reused but distinguished by attributes is a bit tricky.

Copy link
Member Author

Choose a reason for hiding this comment

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

__rust_abort is the obvious name for the symbol shared between panic_abort and std, so I'm a bit hesitant about changing that. Changing the SGX symbol seems better, but it's a lot of effort as it requires changing libunwind as well; I don't really think it's worth it.

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 8, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 8, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@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 8, 2025
@bjorn3
Copy link
Member

bjorn3 commented Apr 9, 2025

Makes sense for now. In the future maybe we could make panic_abort and panic_unwind depend on std rather than the other way around. Both of them are only used with std, but currently std has a kind of weak dependency on panic_abort and panic_unwind where both get registered into the crate store (and thus for example participate in the duplicate lang item check), but only one of the two will actually "activated" and end up getting linked in the end. Flipping the dependency around would allow getting rid of this weird dependency state and allow directly using libstd symbols from both crates.

@bors
Copy link
Collaborator

bors commented Apr 13, 2025

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

joboet added 3 commits April 21, 2025 15:10
Currently, the code for process aborts is duplicated across `panic_abort` and `std`. This PR uses `#[rustc_std_internal_symbol]` to make the `std` implementation available to `panic_abort` via the linker, thereby deduplicating the code.
@joboet
Copy link
Member Author

joboet commented Apr 21, 2025

@rustbot ready

I've rebased, blessed the tests and improved the comment.

@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 21, 2025
@bors
Copy link
Collaborator

bors commented Apr 21, 2025

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

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

Just double check whether or not the directive at Ralf's comment is needed or not, but r=me with a rebase.

@@ -1,6 +1,6 @@
//@error-in-other-file: the program aborted execution
//@normalize-stderr-test: "\| +\^+" -> "| ^"
//@normalize-stderr-test: "unsafe \{ libc::abort\(\); \}|core::intrinsics::abort\(\);" -> "ABORT();"
//@normalize-stderr-test: "unsafe \{ libc::abort\(\) \}|core::intrinsics::abort\(\)" -> "ABORT()"
Copy link
Contributor

Choose a reason for hiding this comment

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

Are either of these needed? Since crate::intrinsics::abort is now normalized in src/tools/miri/tests/ui.rs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-hermit Operating System: Hermit O-SGX Target: SGX O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

7 participants