Open
Description
Static variables with alignment of 2MB when building for Windows crash with either SIGILL on Linux cross-comiling or STATUS_ILLEGAL_INSTRUCTION on Windows.
See https://godbolt.org/z/rvfM8M455.
Code
#[repr(C, align(0x200000))]
struct Foo(u8);
static FOO: Foo = Foo(0);
fn main() {}
Meta
rustc --version --verbose
:
1.87
nightly
Error output
error: rustc interrupted by SIGILL, printing backtrace
Backtrace
error: rustc interrupted by SIGILL, printing backtrace
/opt/compiler-explorer/rust-1.87.0/lib/librustc_driver-9c23edfdcf82221e.so(+0x39177df)[0x7959893177df]
/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x795985642520]
/opt/compiler-explorer/rust-1.87.0/lib/libLLVM.so.20.1-rust-1.87.0-stable(_ZN4llvm13WinCOFFWriter13defineSectionERKNS_11MCAssemblerERKNS_13MCSectionCOFFE+0x51c)[0x795981bb616c]
/opt/compiler-explorer/rust-1.87.0/lib/libLLVM.so.20.1-rust-1.87.0-stable(_ZN4llvm13WinCOFFWriter24executePostLayoutBindingERNS_11MCAssemblerE+0xfd)[0x795981bb821d]
/opt/compiler-explorer/rust-1.87.0/lib/libLLVM.so.20.1-rust-1.87.0-stable(_ZN4llvm19WinCOFFObjectWriter24executePostLayoutBindingERNS_11MCAssemblerE+0x13)[0x795981bb9613]
/opt/compiler-explorer/rust-1.87.0/lib/libLLVM.so.20.1-rust-1.87.0-stable(_ZN4llvm11MCAssembler6layoutEv+0x1606)[0x795984144d06]
/opt/compiler-explorer/rust-1.87.0/lib/libLLVM.so.20.1-rust-1.87.0-stable(_ZN4llvm16MCObjectStreamer10finishImplEv+0x63)[0x7959841435e3]
/opt/compiler-explorer/rust-1.87.0/lib/libLLVM.so.20.1-rust-1.87.0-stable(_ZN4llvm10AsmPrinter14doFinalizationERNS_6ModuleE+0x35e)[0x7959839ebe5e]
/opt/compiler-explorer/rust-1.87.0/lib/libLLVM.so.20.1-rust-1.87.0-stable(_ZN4llvm13FPPassManager14doFinalizationERNS_6ModuleE+0x2a)[0x79598382a0ea]
/opt/compiler-explorer/rust-1.87.0/lib/libLLVM.so.20.1-rust-1.87.0-stable(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x3ff)[0x795983e4a553]
/opt/compiler-explorer/rust-1.87.0/lib/librustc_driver-9c23edfdcf82221e.so(+0x5f719c2)[0x79598b9719c2]
/opt/compiler-explorer/rust-1.87.0/lib/librustc_driver-9c23edfdcf82221e.so(+0x5f71521)[0x79598b971521]
/opt/compiler-explorer/rust-1.87.0/lib/librustc_driver-9c23edfdcf82221e.so(+0x5f6eb5b)[0x79598b96eb5b]
/opt/compiler-explorer/rust-1.87.0/lib/librustc_driver-9c23edfdcf82221e.so(+0x5f6e834)[0x79598b96e834]
/opt/compiler-explorer/rust-1.87.0/lib/librustc_driver-9c23edfdcf82221e.so(_RINvNtNtCseJswNlh1fGO_3std3sys9backtrace28___rust_begin_short_backtraceNCINvXs0_Csj8izNYKuql0_18rustc_codegen_llvmNtB1g_18LlvmCodegenBackendNtNtNtCs2ZezlIswSFH_17rustc_codegen_ssa6traits7backend19ExtraBackendMethods18spawn_named_threadNCINvNtNtB2k_4back5write10spawn_workB1O_E0uE0uEB1g_+0x251)[0x79598b96cf91]
/opt/compiler-explorer/rust-1.87.0/lib/librustc_driver-9c23edfdcf82221e.so(+0x5f6685c)[0x79598b96685c]
/opt/compiler-explorer/rust-1.87.0/lib/librustc_driver-9c23edfdcf82221e.so(+0x5f66bf7)[0x79598b966bf7]
/lib/x86_64-linux-gnu/libc.so.6(+0x94ac3)[0x795985694ac3]
/lib/x86_64-linux-gnu/libc.so.6(+0x126850)[0x795985726850]
note: we would appreciate a report at https://github.com/rust-lang/rust
Program terminated with signal: SIGILL
Execution build compiler returned: 132
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Category: This is a bug.Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.Operating system: WindowsRelevant to the compiler team, which will review and decide on the PR/issue.
Activity
chris-oo commentedon Jun 11, 2025
Doing some cursory issue searching, I also saw #135752 and #70144, but I'm not sure if those are exactly the same or not.
Fulgen301 commentedon Jun 12, 2025
...are not supported. Both clang and MSVC reject it, and the maximum accepted value is documented to be 8192.
It shouldn't crash, but it shouldn't work either.
chris-oo commentedon Jun 12, 2025
Right, the crash should probably be surfaced as some other kind of error.
nthery commentedon Jun 16, 2025
@rustbot claim
nthery commentedon Jun 16, 2025
The crash is caused by
in
getAlignment()
called fromWinCOFFWriter::defineSection()
insrc\llvm-project\llvm\lib\MC\WinCOFFObjectWriter.cpp
.The Rust reference allows alignment up to 2^29 but, as explained in a previous comment, the Windows PE-COFF format supports only up to 8192.
So it seems to me that we should:
Are there precedents in the reference for target-specific limits?
repr(align)
is implemented incompiler\rustc_attr_parsing\src\attributes\repr.rs
.Is there infrastructure to perform target-specific error checking?
Thanks in advance
nthery commentedon Jun 16, 2025
@rustbot label +O-Windows
Fulgen301 commentedon Jun 16, 2025
PE is also used for UEFI binaries, so it's probably better to limit it for all PE targets.
repr(align)
exceeds COFF limit #142638workingjubilee commentedon Jun 17, 2025
What does MSVC do when given
alignas(0x4000)
(or other too-high alignments) on a non-static?beetrees commentedon Jun 17, 2025
"error C2345: align(16384): illegal alignment value" (compiler explorer, error code docs). Clang also gives a similar error; GCC only errors when the struct is used as the type of a static.
workingjubilee commentedon Jun 17, 2025
Okay, so the choice is effectively between aligning (heh) with GCC or Clang on this.