store target.min_global_align as an Align
This commit is contained in:
@@ -2,7 +2,7 @@ use std::borrow::Cow;
|
||||
use std::collections::BTreeMap;
|
||||
use std::str::FromStr;
|
||||
|
||||
use rustc_abi::ExternAbi;
|
||||
use rustc_abi::{Align, AlignFromBytesError, ExternAbi};
|
||||
use serde_json::Value;
|
||||
|
||||
use super::{Target, TargetKind, TargetOptions, TargetWarnings};
|
||||
@@ -57,6 +57,14 @@ impl Target {
|
||||
base.metadata.std = metadata.remove("std").and_then(|host| host.as_bool());
|
||||
}
|
||||
|
||||
let alignment_error = |field_name: &str, error: AlignFromBytesError| -> String {
|
||||
let msg = match error {
|
||||
AlignFromBytesError::NotPowerOfTwo(_) => "not a power of 2 number of bytes",
|
||||
AlignFromBytesError::TooLarge(_) => "too large",
|
||||
};
|
||||
format!("`{}` bits is not a valid value for {field_name}: {msg}", error.align() * 8)
|
||||
};
|
||||
|
||||
let mut incorrect_type = vec![];
|
||||
|
||||
macro_rules! key {
|
||||
@@ -111,6 +119,15 @@ impl Target {
|
||||
base.$key_name = Some(s.into());
|
||||
}
|
||||
} );
|
||||
($key_name:ident, Option<Align>) => ( {
|
||||
let name = (stringify!($key_name)).replace("_", "-");
|
||||
if let Some(b) = obj.remove(&name).and_then(|b| b.as_u64()) {
|
||||
match Align::from_bits(b) {
|
||||
Ok(align) => base.$key_name = Some(align),
|
||||
Err(e) => return Err(alignment_error(&name, e)),
|
||||
}
|
||||
}
|
||||
} );
|
||||
($key_name:ident, BinaryFormat) => ( {
|
||||
let name = (stringify!($key_name)).replace("_", "-");
|
||||
obj.remove(&name).and_then(|f| f.as_str().and_then(|s| {
|
||||
@@ -617,7 +634,7 @@ impl Target {
|
||||
key!(crt_static_default, bool);
|
||||
key!(crt_static_respected, bool);
|
||||
key!(stack_probes, StackProbeType)?;
|
||||
key!(min_global_align, Option<u64>);
|
||||
key!(min_global_align, Option<Align>);
|
||||
key!(default_codegen_units, Option<u64>);
|
||||
key!(default_codegen_backend, Option<StaticCow<str>>);
|
||||
key!(trap_unreachable, bool);
|
||||
|
||||
@@ -1697,6 +1697,12 @@ impl ToJson for BinaryFormat {
|
||||
}
|
||||
}
|
||||
|
||||
impl ToJson for Align {
|
||||
fn to_json(&self) -> Json {
|
||||
self.bits().to_json()
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! supported_targets {
|
||||
( $(($tuple:literal, $module:ident),)+ ) => {
|
||||
mod targets {
|
||||
@@ -2513,7 +2519,7 @@ pub struct TargetOptions {
|
||||
pub stack_probes: StackProbeType,
|
||||
|
||||
/// The minimum alignment for global symbols.
|
||||
pub min_global_align: Option<u64>,
|
||||
pub min_global_align: Option<Align>,
|
||||
|
||||
/// Default number of codegen units to use in debug mode
|
||||
pub default_codegen_units: Option<u64>,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use rustc_abi::Endian;
|
||||
use rustc_abi::{Align, Endian};
|
||||
|
||||
use crate::spec::{SanitizerSet, StackProbeType, Target, TargetMetadata, base};
|
||||
|
||||
@@ -8,7 +8,7 @@ pub(crate) fn target() -> Target {
|
||||
// z10 is the oldest CPU supported by LLVM
|
||||
base.cpu = "z10".into();
|
||||
base.max_atomic_width = Some(128);
|
||||
base.min_global_align = Some(16);
|
||||
base.min_global_align = Some(Align::from_bits(16).unwrap());
|
||||
base.stack_probes = StackProbeType::Inline;
|
||||
base.supported_sanitizers =
|
||||
SanitizerSet::ADDRESS | SanitizerSet::LEAK | SanitizerSet::MEMORY | SanitizerSet::THREAD;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use rustc_abi::Endian;
|
||||
use rustc_abi::{Align, Endian};
|
||||
|
||||
use crate::spec::{SanitizerSet, StackProbeType, Target, TargetMetadata, base};
|
||||
|
||||
@@ -8,7 +8,7 @@ pub(crate) fn target() -> Target {
|
||||
// z10 is the oldest CPU supported by LLVM
|
||||
base.cpu = "z10".into();
|
||||
base.max_atomic_width = Some(128);
|
||||
base.min_global_align = Some(16);
|
||||
base.min_global_align = Some(Align::from_bits(16).unwrap());
|
||||
base.static_position_independent_executables = true;
|
||||
base.stack_probes = StackProbeType::Inline;
|
||||
base.supported_sanitizers =
|
||||
|
||||
Reference in New Issue
Block a user