diff options
| author | bors <bors@rust-lang.org> | 2017-08-04 22:35:22 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-08-04 22:35:22 +0000 |
| commit | 9b6c2382a7f26ea5584c229bec5aab4d0b10c9fd (patch) | |
| tree | 83155d056be4fbc0b31b3e2a84d0f9b366505096 /src/librustc_trans | |
| parent | d692a91fa69a057d82cf6cb71aa3d50260f9de4a (diff) | |
| parent | e412cb30dc1a833e2eb1b3601ed934a89c07fe08 (diff) | |
| download | rust-9b6c2382a7f26ea5584c229bec5aab4d0b10c9fd.tar.gz rust-9b6c2382a7f26ea5584c229bec5aab4d0b10c9fd.zip | |
Auto merge of #43615 - dhduvall:lto-unaligned-read, r=nagisa
Fix some unaligned reads on SPARC in LTO This fixes #43593 by eliminating some undefined behavior.
Diffstat (limited to 'src/librustc_trans')
| -rw-r--r-- | src/librustc_trans/back/lto.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/librustc_trans/back/lto.rs b/src/librustc_trans/back/lto.rs index e160d6b6c6a..3e2d9f5c32e 100644 --- a/src/librustc_trans/back/lto.rs +++ b/src/librustc_trans/back/lto.rs @@ -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 { @@ -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) } |
