Rollup merge of #139261 - RalfJung:msvc-align-mitigation, r=oli-obk
mitigate MSVC alignment issue on x86-32 This implements mitigation for https://github.com/rust-lang/rust/issues/112480 by stopping to emit `align` attributes on loads and function arguments when building for a win32 MSVC target. MSVC is known to not properly align `u64` and similar types, and claiming to LLVM that everything is properly aligned increases the chance that this will cause problems. Of course, the misalignment is still a bug, but we can't fix that bug, only MSVC can. Also add an errata note to the platform support page warning users about this known problem. try-job: `i686-msvc*`
This commit is contained in:
@@ -144,6 +144,7 @@ pub struct ArgAttributes {
|
||||
/// (corresponding to LLVM's dereferenceable_or_null attributes, i.e., it is okay for this to be
|
||||
/// set on a null pointer, but all non-null pointers must be dereferenceable).
|
||||
pub pointee_size: Size,
|
||||
/// The minimum alignment of the pointee, if any.
|
||||
pub pointee_align: Option<Align>,
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,9 @@ use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
use std::{fmt, io};
|
||||
|
||||
use rustc_abi::{Endian, ExternAbi, Integer, Size, TargetDataLayout, TargetDataLayoutErrors};
|
||||
use rustc_abi::{
|
||||
Align, Endian, ExternAbi, Integer, Size, TargetDataLayout, TargetDataLayoutErrors,
|
||||
};
|
||||
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
|
||||
use rustc_fs_util::try_canonicalize;
|
||||
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
|
||||
@@ -3599,6 +3601,25 @@ impl Target {
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns whether this target is known to have unreliable alignment:
|
||||
/// native C code for the target fails to align some data to the degree
|
||||
/// required by the C standard. We can't *really* do anything about that
|
||||
/// since unsafe Rust code may assume alignment any time, but we can at least
|
||||
/// inhibit some optimizations, and we suppress the alignment checks that
|
||||
/// would detect this unsoundness.
|
||||
///
|
||||
/// Every target that returns less than `Align::MAX` here is still has a soundness bug.
|
||||
pub fn max_reliable_alignment(&self) -> Align {
|
||||
// FIXME(#112480) MSVC on x86-32 is unsound and fails to properly align many types with
|
||||
// more-than-4-byte-alignment on the stack. This makes alignments larger than 4 generally
|
||||
// unreliable on 32bit Windows.
|
||||
if self.is_like_windows && self.arch == "x86" {
|
||||
Align::from_bytes(4).unwrap()
|
||||
} else {
|
||||
Align::MAX
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Either a target tuple string or a path to a JSON file.
|
||||
|
||||
Reference in New Issue
Block a user