-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add diagnostic for stack allocations of 1 GB or more #119798
base: master
Are you sure you want to change the base?
Conversation
r? @wesleywiser (rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
fd9f9a6
to
8ee58b2
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
9fb4f4f
to
91dcd42
Compare
This comment has been minimized.
This comment has been minimized.
I have addressed all the comments, but not sure how to add the stdout file for 32 bit :
|
@rustbot review |
|
This comment has been minimized.
This comment has been minimized.
@iSwapna any updates on this? thanks |
Sorry, I am taking a class @Stanford CS103, taking every bit of my time outside of work. That's towards wanting a good grounding on CS/compilers as well, to do a better job here! There was a CI failure (fluent related) which I have not got an answer on how to address, the Zulip discussion is here: Issue 83060 - Regression with large stack arrays (2-4GB) If I could get an answer on how to address the CI issue, I can take care of this in a couple of weeks (after impending midterm) |
Sure, Thanks for the update. Just wanted to know if you are still working on it and have any updates. You should get a reply on zulip else you can bump it i guess |
will do! Thank you for checking! |
3305a06
to
96c95df
Compare
This comment has been minimized.
This comment has been minimized.
d9232a0
to
72aa684
Compare
72aa684
to
bece062
Compare
Some changes occurred in tests/ui/sanitizer cc @rust-lang/project-exploit-mitigations, @rcvalle |
991265a
to
96da2f1
Compare
This comment has been minimized.
This comment has been minimized.
f9ad136
to
d7480c4
Compare
This comment has been minimized.
This comment has been minimized.
d7480c4
to
fa8402a
Compare
This comment has been minimized.
This comment has been minimized.
use ilog2 Update compiler/rustc_codegen_ssa/messages.ftl Co-authored-by: Michael Goulet <[email protected]> Run test only on 64 bit
265cfea
to
a0338cf
Compare
This comment has been minimized.
This comment has been minimized.
The job Click to see the possible cause of the failure (guessed by this bot)
|
☔ The latest upstream changes (presumably #132581) made this pull request unmergeable. Please resolve the merge conflicts. |
@estebank I will get back to this after exams - late Dec. Do let me know your comments. |
decl.source_info.span, | ||
|lint| { | ||
lint.primary_message(format!( | ||
"allocation of size: {:.2} {} exceeds most system architecture limits", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"allocation of size: {:.2} {} exceeds most system architecture limits", | |
"allocation of {:.2} {} exceeds most system architecture limits", |
/// Formats a number of bytes into a human readable SI-prefixed size. | ||
/// Returns a tuple of `(quantity, units)`. | ||
pub fn human_readable_bytes(bytes: u64) -> (u64, &'static str) { | ||
static UNITS: [&str; 7] = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"]; | ||
let i = ((bytes.checked_ilog2().unwrap_or(0) / 10) as usize).min(UNITS.len() - 1); | ||
(bytes >> (10 * i), UNITS[i]) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could have sworn that we did this already, but alas it is in cargo 😅
/// Large arras may cause stack overflow due to the limited size of the | ||
/// stack on most platforms. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Large arras may cause stack overflow due to the limited size of the | |
/// stack on most platforms. | |
/// Large arrays may cause stack overflow due to the limited size of the | |
/// stack on most platforms. |
We should probably extend this to be more explicit about which platforms this is an issue in (no need to be exhaustive).
/// stack on most platforms. | ||
pub DANGEROUS_STACK_ALLOCATION, | ||
Warn, | ||
"Detects dangerous stack allocations at the limit of most architectures" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Detects dangerous stack allocations at the limit of most architectures" | |
"detects dangerously large stack allocations at the limit of most architectures" |
@@ -29,6 +31,8 @@ use self::debuginfo::{FunctionDebugContext, PerLocalVarDebugInfo}; | |||
use self::operand::{OperandRef, OperandValue}; | |||
use self::place::PlaceRef; | |||
|
|||
const MIN_DANGEROUS_SIZE: u64 = 1024 * 1024 * 1024 * 1; // 1 GB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const MIN_DANGEROUS_SIZE: u64 = 1024 * 1024 * 1024 * 1; // 1 GB | |
const MIN_DANGEROUS_ALLOC_SIZE: u64 = 1024 * 1024 * 1024 * 1; // 1 GB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not to change, but to discuss: would making this lower than 1GB be worth it, so that people that we can guide people that are not hitting the limits, but are on their way to do so get some early warning?
@@ -234,6 +238,21 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( | |||
let layout = start_bx.layout_of(fx.monomorphize(decl.ty)); | |||
assert!(!layout.ty.has_erasable_regions()); | |||
|
|||
if layout.size.bytes() >= MIN_DANGEROUS_SIZE { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if layout.size.bytes() >= MIN_DANGEROUS_SIZE { | |
if layout.size.bytes() >= MIN_DANGEROUS_ALLOC_SIZE { |
#[derive(Diagnostic)] | ||
#[diag(codegen_ssa_dangerous_stack_allocation)] | ||
pub struct DangerousStackAllocation { | ||
#[primary_span] | ||
pub span: Span, | ||
pub output: String, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the ftl
change are no longer used, right?
lint::builtin::DANGEROUS_STACK_ALLOCATION, | ||
CRATE_HIR_ID, | ||
decl.source_info.span, | ||
|lint| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add more context, like in the lint description, about some common platform limits.
/// warning: allocation of size: 1 GiB exceeds most system architecture limits | ||
/// --> $DIR/large-stack-size-issue-83060.rs:7:9 | ||
/// | | ||
/// LL | let mut x: [u8; CAP>>1] = [0; CAP>>1]; | ||
/// | ^^^^^ | ||
/// | | ||
/// = note: `#[warn(dangerous_stack_allocation)]` on by default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will likely fail because of the textual formatting not being correctly left aligned.
/// warning: allocation of size: 1 GiB exceeds most system architecture limits | ||
/// --> $DIR/large-stack-size-issue-83060.rs:7:9 | ||
/// | | ||
/// LL | let mut x: [u8; CAP>>1] = [0; CAP>>1]; | ||
/// | ^^^^^ | ||
/// | | ||
/// = note: `#[warn(dangerous_stack_allocation)]` on by default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// warning: allocation of size: 1 GiB exceeds most system architecture limits | |
/// --> $DIR/large-stack-size-issue-83060.rs:7:9 | |
/// | | |
/// LL | let mut x: [u8; CAP>>1] = [0; CAP>>1]; | |
/// | ^^^^^ | |
/// | | |
/// = note: `#[warn(dangerous_stack_allocation)]` on by default | |
/// warning: allocation of size: 1 GiB exceeds most system architecture limits | |
/// --> $DIR/large-stack-size-issue-83060.rs:7:9 | |
/// | | |
/// LL | let mut x: [u8; CAP>>1] = [0; CAP>>1]; | |
/// | ^^^^^ | |
/// | | |
/// = note: `#[warn(dangerous_stack_allocation)]` on by default |
Add diagnostic for stack allocations of 1 GB or more
Zulip conversation [here](Issue 83060 - Regression with large stack arrays (2-4GB))
Do I generate an ICE or issue a warning?
cc #83060