Skip to content

Statics don't support alignments larger than the page size #70022

Open
@Amanieu

Description

@Amanieu

Example code:

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

static X: Aligned = Aligned(0);

fn main() {
    let x = Aligned(0);
    println!("{:#x}", &x as *const _ as usize);
    println!("{:#x}", &X as *const _ as usize);
    println!("{:#x}", Box::into_raw(Box::new(Aligned(0))) as usize);
}

Output:

0x7ffec8000000
0x55c9b2596000
0x7f2879f00000

I am not sure about other platforms, but in the case of Linux this happens because the ELF loader in the kernel ignores the p_align field of the ELF program headers and assumes page-alignment instead.

Metadata

Metadata

Assignees

Labels

A-alignArea: alignment control (`repr(align(N))` and so on)A-target-specsArea: Compile-target specificationsC-bugCategory: This is a bug.E-needs-investigationCall for partcipation: This issues needs some investigation to determine current statusI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessO-linuxOperating system: LinuxO-windows-gnuToolchain: GNU, Operating system: WindowsO-windows-msvcToolchain: MSVC, Operating system: WindowsP-highHigh priorityT-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