Skip to content

Conversation

@nthery
Copy link

@nthery nthery commented Jun 17, 2025

The PE-COFF binary format limits section alignment to 8192 bytes. Emit error when alignment exceeds this limit to avoid crash in llvm.

Closes #142386.

Reference PR:

@rustbot
Copy link
Collaborator

rustbot commented Jun 17, 2025

r? @WaffleLapkin

rustbot has assigned @WaffleLapkin.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 17, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 17, 2025

Some changes occurred in diagnostic error codes

cc @GuillaumeGomez

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@jieyouxu jieyouxu added the A-align Area: alignment control (`repr(align(N))` and so on) label Jun 17, 2025
@workingjubilee
Copy link
Member

It only needs to error if we generate a static based on this.

@folkertdev
Copy link
Contributor

Could you include testing alignment on functions here in this PR (if relevant, but I suspect it is). I think you can just add it to the test files you already modify.

#![feature(fn_align)]

// ...

// and then you can annotate a function with `#[repr(align(N))]`
#[repr(align(16))]
fn foo() {}

@workingjubilee
Copy link
Member

@nthery This simple version that rejects repr(align(0x4000)) will need to be cratered. Nonetheless please finish writing up the PR so we can do so.

@workingjubilee
Copy link
Member

...wait, we can't crater for Windows.

@workingjubilee
Copy link
Member

fbbth.

@bors
Copy link
Collaborator

bors commented Jun 18, 2025

☔ The latest upstream changes (presumably #138165) made this pull request unmergeable. Please resolve the merge conflicts.

@nthery
Copy link
Author

nthery commented Jun 20, 2025

Could you include testing alignment on functions here in this PR (if relevant, but I suspect it is). I think you can just add it to the test files you already modify.

#![feature(fn_align)]

// ...

// and then you can annotate a function with `#[repr(align(N))]`
#[repr(align(16))]
fn foo() {}

It is relevant indeed. I reproduced the original bug with a function alignment exceeding 0x2000 bytes. Thanks for spotting this. I will add some test points.

@rustbot

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 21, 2025
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 21, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-rfcbot rust-rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Nov 5, 2025
@rust-rfcbot
Copy link
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

@rust-rfcbot rust-rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Nov 5, 2025
@nthery
Copy link
Author

nthery commented Nov 9, 2025

I'm working on rebasing the PR. Thanks for all the comments.

@rustbot
Copy link
Collaborator

rustbot commented Nov 9, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer

This comment has been minimized.

The PE-COFF binary format limits section alignment to 8192 bytes.
Emit error when alignment exceeds this limit to avoid crash in llvm.
nthery added a commit to nthery/rust-reference that referenced this pull request Nov 9, 2025
This document the following change to the compiler that enforces the
limit: rust-lang/rust#142638.
@nthery
Copy link
Author

nthery commented Nov 9, 2025

We should document this in the Reference, in:

@nthery, would you perhaps be interested in putting up a PR for that?

Here is the PR: rust-lang/reference#2081.

@traviscross
Copy link
Contributor

Thanks for that.

@rfcbot reviewed

cc @rust-lang/fls

@traviscross traviscross removed I-lang-nominated Nominated for discussion during a lang team meeting. P-lang-drag-2 Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang. labels Nov 12, 2025
@rust-rfcbot rust-rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Nov 15, 2025
@rust-rfcbot
Copy link
Collaborator

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@workingjubilee
Copy link
Member

I suspect we'll get such feedback soon enough, but I also think that the fastest way to find out is the old "throw it over the wall and see who screams" tactic, so!

@bors r+

@bors
Copy link
Collaborator

bors commented Nov 15, 2025

📌 Commit a8fc845 has been approved by workingjubilee

It is now in the queue for this repository.

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Nov 15, 2025
@bors
Copy link
Collaborator

bors commented Nov 15, 2025

⌛ Testing commit a8fc845 with merge dcd6fb3...

bors added a commit that referenced this pull request Nov 15, 2025
error out when `repr(align)` exceeds COFF limit

The PE-COFF binary format limits section alignment to 8192 bytes. Emit error when alignment exceeds this limit to avoid crash in llvm.

Closes #142386.

Reference PR:

- rust-lang/reference#2081
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-msvc-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
---- [ui] tests\ui\structs-enums\align-struct.rs stdout ----

error: test compilation failed although it shouldn't!
status: exit code: 1
command: PATH="C:\a\rust\rust\build\aarch64-pc-windows-msvc\stage2\bin;C:\Program Files (x86)\Windows Kits\10\bin\arm64;C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\arm64;C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\bin\HostARM64\arm64;C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.44.35207\bin\HostARM64\arm64;C:\a\rust\rust\build\aarch64-pc-windows-msvc\bootstrap-tools\aarch64-pc-windows-msvc\release\deps;C:\Program Files\Git\clangarm64\bin;C:\Program Files\Git\usr\bin;C:\Users\runneradmin\bin;C:\a\rust\rust\ninja;C:\a\rust\rust\citools\clang-rust\bin;C:\a\rust\rust\sccache;C:\aliyun-cli;C:\vcpkg;C:\Program Files (x86)\NSIS;C:\Program Files\Mercurial;C:\hostedtoolcache\windows\stack\3.7.1\x64;C:\mingw64\bin;C:\Program Files\dotnet;C:\Program Files\MySQL\MySQL Server 8.0\bin;C:\Program Files (x86)\R\R-4.5.1\bin\x64;C:\SeleniumWebDrivers\GeckoDriver;C:\SeleniumWebDrivers\EdgeDriver;C:\SeleniumWebDrivers\ChromeDriver;C:\Program Files (x86)\sbt\bin;C:\Program Files (x86)\GitHub CLI;C:\Program Files\Git\usr\bin;C:\Program Files (x86)\pipx_bin;C:\npm\prefix;C:\hostedtoolcache\windows\go\1.24.9\arm64\bin;C:\hostedtoolcache\windows\Python\3.12.10\arm64\Scripts;C:\hostedtoolcache\windows\Python\3.12.10\arm64;C:\hostedtoolcache\windows\Ruby\3.4.7\aarch64\bin;C:\Program Files\OpenSSL\bin;C:\tools\kotlinc\bin;C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\21.0.8-9.0\aarch64\bin;C:\Program Files (x86)\ImageMagick-7.1.2-Q16-HDRI;C:\Program Files\Microsoft SDKs\Azure\CLI2\wbin;C:\ProgramData\kind;C:\ProgramData\Chocolatey\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\PowerShell\7;C:\Program Files\Microsoft\Web Platform Installer;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files\Microsoft SQL Server\150\Tools\Binn;C:\Program Files\dotnet;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit;C:\Program Files\Microsoft SQL Server\130\DTS\Binn;C:\Program Files\Microsoft SQL Server\140\DTS\Binn;C:\Program Files\Microsoft SQL Server\150\DTS\Binn;C:\Program Files\Microsoft SQL Server\160\DTS\Binn;C:\Program Files\Microsoft SQL Server\170\DTS\Binn;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\ProgramData\chocolatey\lib\pulumi\tools\Pulumi\bin;C:\Program Files\CMake\bin;C:\Tools\Ninja;C:\ProgramData\chocolatey\lib\maven\apache-maven-3.9.11\bin;C:\Program Files\LLVM\bin;C:\Program Files\nodejs;C:\Program Files\Git\cmd;C:\Program Files\Git\clangarm64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\GitHub CLI;C:\tools\php;C:\Program Files (x86)\sbt\bin;C:\Program Files\Amazon\AWSCLIV2;C:\Program Files\Amazon\SessionManagerPlugin\bin;C:\Program Files\Amazon\AWSSAMCLI\bin;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Users\runneradmin\.dotnet\tools;C:\Users\runneradmin\.cargo\bin;C:\Users\runneradmin\AppData\Local\Microsoft\WindowsApps" "C:\\a\\rust\\rust\\build\\aarch64-pc-windows-msvc\\stage2\\bin\\rustc.exe" "C:\\a\\rust\\rust\\tests\\ui\\structs-enums\\align-struct.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=C:\\Users\\runneradmin\\.cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=C:\\a\\rust\\rust\\vendor" "--sysroot" "C:\\a\\rust\\rust\\build\\aarch64-pc-windows-msvc\\stage2" "--target=aarch64-pc-windows-msvc" "--check-cfg" "cfg(test,FALSE)" "-O" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "-o" "C:\\a\\rust\\rust\\build\\aarch64-pc-windows-msvc\\test\\ui\\structs-enums\\align-struct\\a.exe" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=C:\\a\\rust\\rust\\build\\aarch64-pc-windows-msvc\\native\\rust-test-helpers"
stdout: none
--- stderr -------------------------------
error[E0806]: alignment must not be greater than 8192 bytes for COFF targets
##[error]  --> C:\a\rust\rust\tests\ui\structs-enums\align-struct.rs:67:8
   |
LL | #[repr(align(0x10000))]
   |        ^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0806`.
---

Some tests failed in compiletest suite=ui mode=ui host=aarch64-pc-windows-msvc target=aarch64-pc-windows-msvc
Bootstrap failed while executing `test --stage 2 --skip=compiler --skip=src`
Build completed unsuccessfully in 1:09:00
make: *** [Makefile:112: ci-msvc-py] Error 1
  local time: Sat Nov 15 20:39:53 CUT 2025
  network time: Sat, 15 Nov 2025 20:39:54 GMT
##[error]Process completed with exit code 2.
##[group]Run echo "disk usage:"
echo "disk usage:"

@bors
Copy link
Collaborator

bors commented Nov 15, 2025

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-align Area: alignment control (`repr(align(N))` and so on) A-attributes Area: Attributes (`#[…]`, `#![…]`) disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. S-waiting-on-documentation Status: Waiting on approved PRs to documentation before merging S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-t-lang Status: Awaiting decision from T-lang T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team to-announce Announce this issue on triage meeting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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