rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
94.82k stars 12.22k forks source link

Misaligned pointer error message could be improved. #109997

Open vext01 opened 1 year ago

vext01 commented 1 year ago

Edit(fmease): Add #![feature] to the code example.

When we updated our Rust nightly, and compiled this (elided) code:

#![feature(link_llvm_intrinsics)]

/// The `llvm.embedded.module` symbol in the `.llvmbc` section.
#[repr(C)]
struct EmbeddedModule {
    /// The length of the bitcode.
    len: usize,
    /// The start of the bitcode itself.
    first_byte_of_bitcode: u8,
}

// ykllvm adds the `SHF_ALLOC` flag to the `.llvmbc` section so that the loader puts it into our
// address space at load time.
extern "C" {
    #[link_name = "llvm.embedded.module"]
    static LLVMBC: EmbeddedModule;
}

/// Returns a pointer to (and the size of) the raw LLVM bitcode in the current address space.
pub fn llvmbc_section() -> (*const u8, usize) {
    let bc = unsafe { &LLVMBC };
    (&bc.first_byte_of_bitcode as *const u8, bc.len)
}

'misaligned pointer dereference: address must be a multiple of 0x8 but is 0x200b2d', ykutil/src/obj.rs:154:23

Where line 154 is:

let bc = unsafe { &LLVMBC };

There is no explicit (language-level) pointer deref on that line.

I wonder if the error message needs to be refined?

Thanks

fmease commented 3 months ago

I can't reproduce this. What is the precise compiler invocation?