Repository navigation
Open
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.Category: This is a bug.C-external-bugCategory: issue that is caused by bugs in software beyond our controlCategory: issue that is caused by bugs in software beyond our controlE-needs-investigationCall for participation: This issues needs some investigation to determine current statusCall for participation: This issues needs some investigation to determine current statusI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessO-windowsOperating system: WindowsOperating system: WindowsP-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Forked from #70022
Minimal example
#[repr(align(0x10000))]
struct Aligned(u8);
fn main() {
let x = Aligned(0);
println!("{:#x}", &x as *const _ as usize);
}Aligning the stack is done after the stack probe. Because stacks grow downwards and aligning the stack shifts it downwards, it can cause the end of the stack to extend past the guard page and cause invalid access exceptions or worse when those sections of the stack are touched.
Only confirmed that this occurs on (pnkfelix edit: see comment thread, its a more general problem.)pc-windows-msvc
Reacted by Clément Nerma
Reacted by Ralf Jung and Gareth Booth
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.Category: This is a bug.C-external-bugCategory: issue that is caused by bugs in software beyond our controlCategory: issue that is caused by bugs in software beyond our controlE-needs-investigationCall for participation: This issues needs some investigation to determine current statusCall for participation: This issues needs some investigation to determine current statusI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessO-windowsOperating system: WindowsOperating system: WindowsP-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Activity
[-]Alignment greater than page size locals can cause invalid access exceptions.[/-][+]Locals aligned to greater than page size can cause unsound behavior[/+]Amanieu commentedon Mar 19, 2020
This is most likely an LLVM bug.
RalfJung commentedon Apr 22, 2020
Could someone who knows the technical details here report this bug upstream with LLVM?
LeSeulArtichaut commentedon Jun 17, 2020
@rustbot ping llvm
27 remaining items
cuviper commentedon Dec 10, 2022
Updating my earlier godbolt to current nightly (https://rust.godbolt.org/z/hseenMTKP) still shows the same asm, still just as problematic. However, I also rechecked
"probe-stack"="inline-asm"since #102503 turned that on for the upcoming LLVM 16, and it's better, but I found a bug: https://reviews.llvm.org/D139756(NB: inline-asm won't apply for Windows and its
__chkstk.)Hotfix for unexpected crash
cuviper commentedon Mar 5, 2024
I think we can now consider this a Windows-only bug, because the rest are now using
"probe-stack"="inline-asm", except for arches that lack stack probes entirely. It's not really specific to MSVC either, aswindows-gnugenerates the same code calling__chkstk.@rustbot label -O-linux -O-windows-msvc +O-windows
jieyouxu commentedon Nov 22, 2024
Visited during T-compiler P-high review: as far as we can tell this still needs someone to try and investigate/fix from the llvm side. Labeled with
C-external-bugas well.apiraino commentedon Jun 19, 2026
Visited during T-compiler P-high review#t-compiler/meetings > [triage] 2026-06-19 P-high review @ 💬
Looks nothing changed here and the fix is on us rather than LLVM? cc: @rust-lang/wg-llvm
ChrisDenton commentedon Jun 19, 2026
recent godbolt
RalfJung commentedon Jun 19, 2026
This is still an LLVM bug, isn't it? We just gave up on hoping they'll fix it so we plan to reject it on the Rust side?
ChrisDenton commentedon Jun 20, 2026
Yeah. Making it an error unless it is ever fixed in llvm was the plan. Notably both
clangand msvc'sclhave a limit of 8192 alignment for the target (godbolt). In my (brief) testing, 16384 appeared to work in rust though it's possible I'm missing some situation where that would break.Fix interaction between stack alignment and inline-asm stack clash pr…