Skip to content

ICE of SIGILL/STATUS_ILLEGAL_INSTRUCTION when compiling static variables with 2MB alignment targeting Windows #142386

@chris-oo

Description

@chris-oo

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

Activity

added
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
C-bugCategory: This is a bug.
on Jun 11, 2025
added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jun 11, 2025
chris-oo

chris-oo commented on Jun 11, 2025

@chris-oo
Author

Doing some cursory issue searching, I also saw #135752 and #70144, but I'm not sure if those are exactly the same or not.

added
I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
and removed
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jun 12, 2025
Fulgen301

Fulgen301 commented on Jun 12, 2025

@Fulgen301
Contributor

Static variables with alignment of 2MB when building for Windows

...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

chris-oo commented on Jun 12, 2025

@chris-oo
Author

Right, the crash should probably be surfaced as some other kind of error.

nthery

nthery commented on Jun 16, 2025

@nthery

@rustbot claim

nthery

nthery commented on Jun 16, 2025

@nthery

The crash is caused by

  llvm_unreachable("unsupported section alignment");

in getAlignment() called from WinCOFFWriter::defineSection() in src\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:

  1. Change the Rust reference to something along the line of " The alignment value must be a power of two from 1 up to an target-specific value".
    Are there precedents in the reference for target-specific limits?
  2. Add some error checking for Windows targets only. The error checking for repr(align) is implemented in compiler\rustc_attr_parsing\src\attributes\repr.rs.
    Is there infrastructure to perform target-specific error checking?

Thanks in advance

nthery

nthery commented on Jun 16, 2025

@nthery

@rustbot label +O-Windows

Fulgen301

Fulgen301 commented on Jun 16, 2025

@Fulgen301
Contributor

the Windows PE-COFF format supports only up to 8192.
Add some error checking for Windows targets only.

PE is also used for UEFI binaries, so it's probably better to limit it for all PE targets.

workingjubilee

workingjubilee commented on Jun 17, 2025

@workingjubilee
Member

What does MSVC do when given alignas(0x4000) (or other too-high alignments) on a non-static?

beetrees

beetrees commented on Jun 17, 2025

@beetrees
Contributor

"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

workingjubilee commented on Jun 17, 2025

@workingjubilee
Member

Okay, so the choice is effectively between aligning (heh) with GCC or Clang on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.O-windowsOperating system: WindowsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @nthery@chris-oo@Fulgen301@workingjubilee@rustbot

    Issue actions

      ICE of SIGILL/STATUS_ILLEGAL_INSTRUCTION when compiling static variables with 2MB alignment targeting Windows · Issue #142386 · rust-lang/rust