Skip to content

SPARC alignment issue in LTO #43593

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

Closed
dhduvall opened this issue Aug 1, 2017 · 3 comments · Fixed by #43615
Closed

SPARC alignment issue in LTO #43593

dhduvall opened this issue Aug 1, 2017 · 3 comments · Fixed by #43615
Labels
C-bug Category: This is a bug. O-SPARC Target: SPARC processors T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dhduvall
Copy link

dhduvall commented Aug 1, 2017

The function extract_bytecode_format_version() in rustc_trans::back::lto is consistently crashing with a SIGBUS on SPARC when compiling Firefox. I'm seeing pos set to 11, and the code generated for the coercion in the unsafe statement isn't intelligent enough to deal with the lack of alignment.

The reduced testcase is simple:

fn main() {
    let arr: [u8; 8] = [0; 8];
    let byte_data = &arr[1..5];
    let data = unsafe { *(byte_data.as_ptr() as *const u32) };
    u32::from_le(data);
}

I can fix that with a copy_from_slice():

    let mut byte_data: [u8; 4] = [0; 4];
    byte_data.copy_from_slice(&bc[pos..pos + 4]);

but I don't know if there's a more idiomatic way, and I don't know how best to make sure that on architectures that can handle the one-byte alignment, it skips the copy.

I suspect that extract_compressed_bytecode_size_v1() has a similar issue.

@parched
Copy link
Contributor

parched commented Aug 2, 2017

*(byte_data.as_ptr() as *const u32) is undefined behaviour. I think the best fix would just be to << and | the bytes by hand without any unsafe code. Yes, extract_compressed_bytecode_size_v1() also has the same issue.

@ollie27
Copy link
Member

ollie27 commented Aug 2, 2017

Another option would be to replace *(byte_data.as_ptr() as *const u32) with ptr::read_unaligned(byte_data.as_ptr() as *const u32).

dhduvall pushed a commit to dhduvall/rust that referenced this issue Aug 2, 2017
This fixes rust-lang#43593 by eliminating some undefined behavior.
@Mark-Simulacrum Mark-Simulacrum added C-bug Category: This is a bug. O-SPARC Target: SPARC processors T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 3, 2017
bors added a commit that referenced this issue Aug 4, 2017
Fix some unaligned reads on SPARC in LTO

This fixes #43593 by eliminating some undefined behavior.
@infinity0
Copy link
Contributor

infinity0 commented Sep 1, 2017

This also caused test failures on armhf on Ubuntu because they pass -Bsymbolic-functions to ld(1). (Debian does not, and did not see the test failures.) The PR fixes that too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-SPARC Target: SPARC processors T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants