Open
Description
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
Area: alignment control (`repr(align(N))` and so on)Area: Compile-target specificationsCategory: This is a bug.Call for partcipation: This issues needs some investigation to determine current statusIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessOperating system: LinuxToolchain: GNU, Operating system: WindowsToolchain: MSVC, Operating system: WindowsHigh priorityRelevant to the compiler team, which will review and decide on the PR/issue.