Space for large, constant arrays is allocated on the stack #82457
Labels
A-lint
Area: Lints (warnings about flaws in source code) such as unused_mut.
C-bug
Category: This is a bug.
C-optimization
Category: An issue highlighting optimization opportunities or PRs implementing such
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
When a large, constant array like
is accessed directly (rather than through a reference) in a function like this
rustc appears to be allocating enough space to hold the whole array on the stack for each reference. With a large enough array times number of uses, this can cause the stack probe to fail. (I didn't check if the whole array is actually materialized on the stack each time or if only space for it is allocated.)
I expected rustc to not allocate space for the constant array and instead access it directly from the read-only memory segment of the executable.
Instead, when I run the code, I get
Disassembling the binary is sufficient to see the issue.
As you can see, this function is trying to allocate 3120336 bytes on the stack.
A complete example from which the above output was derived is available here. The numbers in the array are meaningless. They came from
/dev/urandom
. The numbers in the match are likewise immaterial.Meta
rustc --version --verbose
:The same occurs with nightly.
RUST_BACKTRACE=1
does not work; however, here's a backtrace fromrust-lldb
.Backtrace
The text was updated successfully, but these errors were encountered: