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

Dynamically size sigaltstk in rustc #113528

Conversation

workingjubilee
Copy link
Contributor

@workingjubilee workingjubilee commented Jul 10, 2023

rustc installs a signal stack that assumes that MINSIGSTKSZ is a constant, unchanging value. Newer hardware undermines that assumption greatly, with register files larger than glibc's traditional static MINSIGSTKZ. Properly handle this so that it is correct on all supported Linux versions with all CPUs.

@rustbot
Copy link
Collaborator

rustbot commented Jul 10, 2023

r? @WaffleLapkin

(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. labels Jul 10, 2023
@workingjubilee
Copy link
Contributor Author

This is more-or-less a twin of #113525 but since the code winds up moduled-off from the rest of the world in either case and the two have different contexts, I figured I'd submit it separately.

@workingjubilee workingjubilee force-pushed the use-at-minsigstksz-in-rustc-signal-handler branch from 9577722 to 1e8d24d Compare July 10, 2023 09:32
unsafe {
const ALT_STACK_SIZE: usize = libc::MINSIGSTKSZ + 64 * 1024;
let alt_stack_size: usize = min_sigstack_size() + 64 * 1024;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might seem like 64KiB is greater than the largest number I mentioned, 16KiB.

...but it's up to 16KiB per vector register, and it has way more than one. 🫠

@@ -1469,6 +1470,23 @@ mod signal_handler {
libc::sigaction(libc::SIGSEGV, &sa, std::ptr::null_mut());
}
}

/// Modern kernels on modern hardware can have dynamic signal stack sizes.
#[cfg(any(target_os = "linux", target_os = "android"))]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I have spoken to people who run rustc on Android.

#[cfg(any(target_os = "linux", target_os = "android"))]
fn min_sigstack_size() -> usize {
const AT_MINSIGSTKSZ: core::ffi::c_ulong = 51;
let dynamic_sigstksz = unsafe { libc::getauxval(AT_MINSIGSTKSZ) };
Copy link
Member

Choose a reason for hiding this comment

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

doesn't need to block this PR, but does it make sense to upstream AT_MINSIGSTKSZ to the libc crate so we don't need to hardcode it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean would it be good for rust-lang/libc#3125 to be reviewed and accepted? yes, I think so.

Copy link
Member

@WaffleLapkin WaffleLapkin left a comment

Choose a reason for hiding this comment

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

r=me, preferably with the nit

compiler/rustc_driver_impl/src/lib.rs Outdated Show resolved Hide resolved
@WaffleLapkin WaffleLapkin 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 Jul 10, 2023
rustc installs a signal stack that assumes that
MINSIGSTKSZ is a constant, unchanging value.
Newer hardware undermines that assumption greatly,
with register files larger than MINSIGSTKZ.
Properly handle this so that it is correct on
all supported Linux versions with all CPUs.
@workingjubilee workingjubilee force-pushed the use-at-minsigstksz-in-rustc-signal-handler branch from 1e8d24d to 094cb1a Compare July 10, 2023 19:05
@workingjubilee
Copy link
Contributor Author

@bors r=WaffleLapkin

@bors
Copy link
Contributor

bors commented Jul 10, 2023

📌 Commit 094cb1a has been approved by WaffleLapkin

It is now in the queue for this repository.

@bors bors 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 Jul 10, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 10, 2023
…in-rustc-signal-handler, r=WaffleLapkin

Dynamically size sigaltstk in rustc

rustc installs a signal stack that assumes that MINSIGSTKSZ is a constant, unchanging value. Newer hardware undermines that assumption greatly, with register files larger than glibc's traditional static MINSIGSTKZ. Properly handle this so that it is correct on all supported Linux versions with all CPUs.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 10, 2023
…in-rustc-signal-handler, r=WaffleLapkin

Dynamically size sigaltstk in rustc

rustc installs a signal stack that assumes that MINSIGSTKSZ is a constant, unchanging value. Newer hardware undermines that assumption greatly, with register files larger than glibc's traditional static MINSIGSTKZ. Properly handle this so that it is correct on all supported Linux versions with all CPUs.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 11, 2023
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#113386 (style-guide: Expand example of combinable expressions to include arrays)
 - rust-lang#113523 (Reuse LLVMConstInBoundsGEP2)
 - rust-lang#113528 (Dynamically size sigaltstk in rustc)
 - rust-lang#113543 (Remove `rustc_llvm` from llvm-stamp nags)
 - rust-lang#113548 (Update books)
 - rust-lang#113551 (bootstrap: Don't print "Skipping" twice)
 - rust-lang#113556 (Don't use serde-derive in the rls shim)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit d2a3afe into rust-lang:master Jul 11, 2023
11 checks passed
@rustbot rustbot added this to the 1.73.0 milestone Jul 11, 2023
@workingjubilee workingjubilee deleted the use-at-minsigstksz-in-rustc-signal-handler branch July 31, 2023 17:52
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-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants