Skip to content

Fix some unaligned reads on SPARC in LTO #43615

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

Merged
merged 1 commit into from
Aug 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/librustc_trans/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use flate2::read::DeflateDecoder;
use std::io::Read;
use std::ffi::CString;
use std::path::Path;
use std::ptr::read_unaligned;

pub fn crate_type_allows_lto(crate_type: config::CrateType) -> bool {
match crate_type {
Expand Down Expand Up @@ -223,13 +224,13 @@ fn is_versioned_bytecode_format(bc: &[u8]) -> bool {
fn extract_bytecode_format_version(bc: &[u8]) -> u32 {
let pos = link::RLIB_BYTECODE_OBJECT_VERSION_OFFSET;
let byte_data = &bc[pos..pos + 4];
let data = unsafe { *(byte_data.as_ptr() as *const u32) };
let data = unsafe { read_unaligned(byte_data.as_ptr() as *const u32) };
u32::from_le(data)
}

fn extract_compressed_bytecode_size_v1(bc: &[u8]) -> u64 {
let pos = link::RLIB_BYTECODE_OBJECT_V1_DATASIZE_OFFSET;
let byte_data = &bc[pos..pos + 8];
let data = unsafe { *(byte_data.as_ptr() as *const u64) };
let data = unsafe { read_unaligned(byte_data.as_ptr() as *const u64) };
u64::from_le(data)
}