Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statics aligned to greater than a page cause linker error #70144

Open
retep998 opened this issue Mar 19, 2020 · 1 comment
Open

Statics aligned to greater than a page cause linker error #70144

retep998 opened this issue Mar 19, 2020 · 1 comment
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. O-windows-msvc Toolchain: MSVC, Operating system: Windows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@retep998
Copy link
Member

retep998 commented Mar 19, 2020

On Windows link.exe requires that the alignment of any section is less than or equal to the /ALIGN value. Statics with an alignment of 8192 or greater cause the section to have an alignment of 8192 (but not greater, see #70022), but link.exe has a default /ALIGN of 4096 causing fatal error LNK1164: section 0x6 alignment (8192) greater than /ALIGN value. Specifying -Clink-arg="/ALIGN:8192" causes the error to go away.

Minimal example

#[repr(align(0x100000))]
struct Aligned(u8);

static X: Aligned = Aligned(0);

fn main() {
    println!("{:#x}", &X as *const _ as usize);
}
@retep998 retep998 added O-windows-msvc Toolchain: MSVC, Operating system: Windows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 19, 2020
@jonas-schievink jonas-schievink added A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. labels Mar 19, 2020
ijackson added a commit to ijackson/rust that referenced this issue Jul 21, 2021
@ChrisDenton
Copy link
Member

I no longer get a linker error. Instead rustc outright crashes with STATUS_ILLEGAL_INSTRUCTION. I don't think this is an improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. O-windows-msvc Toolchain: MSVC, Operating system: Windows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants