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

raw pointer produced illegal instruction on X86 and X86-64 but not ARM #19681

Closed
mark3982 opened this issue Dec 10, 2014 · 1 comment
Closed

Comments

@mark3982
Copy link

rustc 0.13.0-dev (dbc379a66 2014-12-03 18:52:48 +0000)
binary: rustc
commit-hash: dbc379a66eae8504b663b0032da518595335d872
commit-date: 2014-12-03 18:52:48 +0000
host: x86_64-unknown-linux-gnu
release: 0.13.0-dev
fn main() {
    unsafe {
        let mem: *mut u8 = 1234 as *mut u8;
        *mem = 6u as u8;
    }
}

The following code will produce correct machine instructions for arm-unknown-linux-gnueabi but produces an illegal instruction on X86 (i686-unknown-linux-gnu) and X86-64.

I can try testing on the very latest development version tomorrow, but I imagine someone will beat me to it as it takes me a long time to build.

@huonw
Copy link
Member

huonw commented Dec 10, 2014

The asm rust/llvm produces (rustc -O --emit=asm) is:

_ZN4main20h7890cd32b0d93ad4eaaE:
    .cfi_startproc
    movb    $6, 1234
    retq

as expected (this is essentially identical to what GCC and Clang produce for the equivalent C program).

The illegal instruction error seems to be related to our current runtime catching/handling the segfault signal, e.g. changing the code to

#[start]
fn main(_: int, _: *const *const u8) -> int {
    unsafe {
        *(1234 as *mut u8) = 6;
    }
    0
}

gives a segfault which is the expected output: writing to some "random" piece of memory is unlikely to work well.

Closing as not-a-bug, feel free to reopen if I've misinterpreted you.

@huonw huonw closed this as completed Dec 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants