Skip to content

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

Open
@retep998

Description

@retep998

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-alignArea: alignment control (`repr(align(N))` and so on)A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.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

    No branches or pull requests

    Issue actions