Auto merge of #113966 - lu-zero:relocation-model-in-cfg, r=bjorn3
Add the relocation_model to the cfg This way is possible to write inline assembly code aware of it.
This commit is contained in:
commit
82c5732b9a
@ -352,6 +352,8 @@ declare_features! (
|
|||||||
(active, c_variadic, "1.34.0", Some(44930), None),
|
(active, c_variadic, "1.34.0", Some(44930), None),
|
||||||
/// Allows the use of `#[cfg(overflow_checks)` to check if integer overflow behaviour.
|
/// Allows the use of `#[cfg(overflow_checks)` to check if integer overflow behaviour.
|
||||||
(active, cfg_overflow_checks, "1.71.0", Some(111466), None),
|
(active, cfg_overflow_checks, "1.71.0", Some(111466), None),
|
||||||
|
/// Provides the relocation model information as cfg entry
|
||||||
|
(active, cfg_relocation_model, "CURRENT_RUSTC_VERSION", Some(114929), None),
|
||||||
/// Allows the use of `#[cfg(sanitize = "option")]`; set when -Zsanitizer is used.
|
/// Allows the use of `#[cfg(sanitize = "option")]`; set when -Zsanitizer is used.
|
||||||
(active, cfg_sanitize, "1.41.0", Some(39699), None),
|
(active, cfg_sanitize, "1.41.0", Some(39699), None),
|
||||||
/// Allows `cfg(target_abi = "...")`.
|
/// Allows `cfg(target_abi = "...")`.
|
||||||
|
@ -35,6 +35,7 @@ const GATED_CFGS: &[GatedCfg] = &[
|
|||||||
(sym::target_has_atomic_load_store, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
|
(sym::target_has_atomic_load_store, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
|
||||||
(sym::sanitize, sym::cfg_sanitize, cfg_fn!(cfg_sanitize)),
|
(sym::sanitize, sym::cfg_sanitize, cfg_fn!(cfg_sanitize)),
|
||||||
(sym::version, sym::cfg_version, cfg_fn!(cfg_version)),
|
(sym::version, sym::cfg_version, cfg_fn!(cfg_version)),
|
||||||
|
(sym::relocation_model, sym::cfg_relocation_model, cfg_fn!(cfg_relocation_model)),
|
||||||
];
|
];
|
||||||
|
|
||||||
/// Find a gated cfg determined by the `pred`icate which is given the cfg's name.
|
/// Find a gated cfg determined by the `pred`icate which is given the cfg's name.
|
||||||
|
@ -12,7 +12,7 @@ use crate::{EarlyErrorHandler, Session};
|
|||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||||
use rustc_data_structures::stable_hasher::{StableOrd, ToStableHashKey};
|
use rustc_data_structures::stable_hasher::{StableOrd, ToStableHashKey};
|
||||||
use rustc_target::abi::Align;
|
use rustc_target::abi::Align;
|
||||||
use rustc_target::spec::{PanicStrategy, SanitizerSet, SplitDebuginfo};
|
use rustc_target::spec::{PanicStrategy, RelocModel, SanitizerSet, SplitDebuginfo};
|
||||||
use rustc_target::spec::{Target, TargetTriple, TargetWarnings, TARGETS};
|
use rustc_target::spec::{Target, TargetTriple, TargetWarnings, TARGETS};
|
||||||
|
|
||||||
use crate::parse::{CrateCheckConfig, CrateConfig};
|
use crate::parse::{CrateCheckConfig, CrateConfig};
|
||||||
@ -1193,6 +1193,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
|
|||||||
let os = &sess.target.os;
|
let os = &sess.target.os;
|
||||||
let env = &sess.target.env;
|
let env = &sess.target.env;
|
||||||
let abi = &sess.target.abi;
|
let abi = &sess.target.abi;
|
||||||
|
let relocation_model = sess.target.relocation_model.desc_symbol();
|
||||||
let vendor = &sess.target.vendor;
|
let vendor = &sess.target.vendor;
|
||||||
let min_atomic_width = sess.target.min_atomic_width();
|
let min_atomic_width = sess.target.min_atomic_width();
|
||||||
let max_atomic_width = sess.target.max_atomic_width();
|
let max_atomic_width = sess.target.max_atomic_width();
|
||||||
@ -1218,6 +1219,9 @@ fn default_configuration(sess: &Session) -> CrateConfig {
|
|||||||
ret.insert((sym::target_pointer_width, Some(Symbol::intern(&wordsz))));
|
ret.insert((sym::target_pointer_width, Some(Symbol::intern(&wordsz))));
|
||||||
ret.insert((sym::target_env, Some(Symbol::intern(env))));
|
ret.insert((sym::target_env, Some(Symbol::intern(env))));
|
||||||
ret.insert((sym::target_abi, Some(Symbol::intern(abi))));
|
ret.insert((sym::target_abi, Some(Symbol::intern(abi))));
|
||||||
|
if sess.is_nightly_build() {
|
||||||
|
ret.insert((sym::relocation_model, Some(relocation_model)));
|
||||||
|
}
|
||||||
ret.insert((sym::target_vendor, Some(Symbol::intern(vendor))));
|
ret.insert((sym::target_vendor, Some(Symbol::intern(vendor))));
|
||||||
if sess.target.has_thread_local {
|
if sess.target.has_thread_local {
|
||||||
ret.insert((sym::target_thread_local, None));
|
ret.insert((sym::target_thread_local, None));
|
||||||
@ -1415,6 +1419,8 @@ impl CrateCheckConfig {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|sanitizer| Symbol::intern(sanitizer.as_str().unwrap()));
|
.map(|sanitizer| Symbol::intern(sanitizer.as_str().unwrap()));
|
||||||
|
|
||||||
|
let relocation_model_values = RelocModel::all();
|
||||||
|
|
||||||
// Unknown possible values:
|
// Unknown possible values:
|
||||||
// - `feature`
|
// - `feature`
|
||||||
// - `target_feature`
|
// - `target_feature`
|
||||||
@ -1453,6 +1459,10 @@ impl CrateCheckConfig {
|
|||||||
.entry(sym::target_has_atomic_equal_alignment)
|
.entry(sym::target_has_atomic_equal_alignment)
|
||||||
.or_insert_with(no_values)
|
.or_insert_with(no_values)
|
||||||
.extend(atomic_values);
|
.extend(atomic_values);
|
||||||
|
self.expecteds
|
||||||
|
.entry(sym::relocation_model)
|
||||||
|
.or_insert_with(empty_values)
|
||||||
|
.extend(relocation_model_values);
|
||||||
|
|
||||||
// Target specific values
|
// Target specific values
|
||||||
{
|
{
|
||||||
|
@ -468,6 +468,7 @@ symbols! {
|
|||||||
cfg_hide,
|
cfg_hide,
|
||||||
cfg_overflow_checks,
|
cfg_overflow_checks,
|
||||||
cfg_panic,
|
cfg_panic,
|
||||||
|
cfg_relocation_model,
|
||||||
cfg_sanitize,
|
cfg_sanitize,
|
||||||
cfg_target_abi,
|
cfg_target_abi,
|
||||||
cfg_target_compact,
|
cfg_target_compact,
|
||||||
@ -661,6 +662,7 @@ symbols! {
|
|||||||
dyn_metadata,
|
dyn_metadata,
|
||||||
dyn_star,
|
dyn_star,
|
||||||
dyn_trait,
|
dyn_trait,
|
||||||
|
dynamic_no_pic: "dynamic-no-pic",
|
||||||
e,
|
e,
|
||||||
edition_panic,
|
edition_panic,
|
||||||
effects,
|
effects,
|
||||||
@ -1115,6 +1117,8 @@ symbols! {
|
|||||||
path,
|
path,
|
||||||
pattern_parentheses,
|
pattern_parentheses,
|
||||||
phantom_data,
|
phantom_data,
|
||||||
|
pic,
|
||||||
|
pie,
|
||||||
pin,
|
pin,
|
||||||
platform_intrinsics,
|
platform_intrinsics,
|
||||||
plugin,
|
plugin,
|
||||||
@ -1223,6 +1227,7 @@ symbols! {
|
|||||||
register_tool,
|
register_tool,
|
||||||
relaxed_adts,
|
relaxed_adts,
|
||||||
relaxed_struct_unsize,
|
relaxed_struct_unsize,
|
||||||
|
relocation_model,
|
||||||
rem,
|
rem,
|
||||||
rem_assign,
|
rem_assign,
|
||||||
repr,
|
repr,
|
||||||
@ -1243,6 +1248,8 @@ symbols! {
|
|||||||
rintf64,
|
rintf64,
|
||||||
riscv_target_feature,
|
riscv_target_feature,
|
||||||
rlib,
|
rlib,
|
||||||
|
ropi,
|
||||||
|
ropi_rwpi: "ropi-rwpi",
|
||||||
rotate_left,
|
rotate_left,
|
||||||
rotate_right,
|
rotate_right,
|
||||||
roundevenf32,
|
roundevenf32,
|
||||||
@ -1354,6 +1361,7 @@ symbols! {
|
|||||||
rustdoc_missing_doc_code_examples,
|
rustdoc_missing_doc_code_examples,
|
||||||
rustfmt,
|
rustfmt,
|
||||||
rvalue_static_promotion,
|
rvalue_static_promotion,
|
||||||
|
rwpi,
|
||||||
s,
|
s,
|
||||||
safety,
|
safety,
|
||||||
sanitize,
|
sanitize,
|
||||||
|
@ -42,7 +42,7 @@ use crate::spec::crt_objects::{CrtObjects, LinkSelfContainedDefault};
|
|||||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||||
use rustc_fs_util::try_canonicalize;
|
use rustc_fs_util::try_canonicalize;
|
||||||
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
|
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
|
||||||
use rustc_span::symbol::{sym, Symbol};
|
use rustc_span::symbol::{kw, sym, Symbol};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
@ -655,6 +655,43 @@ pub enum RelocModel {
|
|||||||
RopiRwpi,
|
RopiRwpi,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl RelocModel {
|
||||||
|
pub fn desc(&self) -> &str {
|
||||||
|
match *self {
|
||||||
|
RelocModel::Static => "static",
|
||||||
|
RelocModel::Pic => "pic",
|
||||||
|
RelocModel::Pie => "pie",
|
||||||
|
RelocModel::DynamicNoPic => "dynamic-no-pic",
|
||||||
|
RelocModel::Ropi => "ropi",
|
||||||
|
RelocModel::Rwpi => "rwpi",
|
||||||
|
RelocModel::RopiRwpi => "ropi-rwpi",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub const fn desc_symbol(&self) -> Symbol {
|
||||||
|
match *self {
|
||||||
|
RelocModel::Static => kw::Static,
|
||||||
|
RelocModel::Pic => sym::pic,
|
||||||
|
RelocModel::Pie => sym::pie,
|
||||||
|
RelocModel::DynamicNoPic => sym::dynamic_no_pic,
|
||||||
|
RelocModel::Ropi => sym::ropi,
|
||||||
|
RelocModel::Rwpi => sym::rwpi,
|
||||||
|
RelocModel::RopiRwpi => sym::ropi_rwpi,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub const fn all() -> [Symbol; 7] {
|
||||||
|
[
|
||||||
|
RelocModel::Static.desc_symbol(),
|
||||||
|
RelocModel::Pic.desc_symbol(),
|
||||||
|
RelocModel::Pie.desc_symbol(),
|
||||||
|
RelocModel::DynamicNoPic.desc_symbol(),
|
||||||
|
RelocModel::Ropi.desc_symbol(),
|
||||||
|
RelocModel::Rwpi.desc_symbol(),
|
||||||
|
RelocModel::RopiRwpi.desc_symbol(),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl FromStr for RelocModel {
|
impl FromStr for RelocModel {
|
||||||
type Err = ();
|
type Err = ();
|
||||||
|
|
||||||
@ -674,16 +711,7 @@ impl FromStr for RelocModel {
|
|||||||
|
|
||||||
impl ToJson for RelocModel {
|
impl ToJson for RelocModel {
|
||||||
fn to_json(&self) -> Json {
|
fn to_json(&self) -> Json {
|
||||||
match *self {
|
self.desc().to_json()
|
||||||
RelocModel::Static => "static",
|
|
||||||
RelocModel::Pic => "pic",
|
|
||||||
RelocModel::Pie => "pie",
|
|
||||||
RelocModel::DynamicNoPic => "dynamic-no-pic",
|
|
||||||
RelocModel::Ropi => "ropi",
|
|
||||||
RelocModel::Rwpi => "rwpi",
|
|
||||||
RelocModel::RopiRwpi => "ropi-rwpi",
|
|
||||||
}
|
|
||||||
.to_json()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
9
tests/ui/abi/relocation_model_pic.rs
Normal file
9
tests/ui/abi/relocation_model_pic.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// run-pass
|
||||||
|
// compile-flags: -C relocation-model=pic
|
||||||
|
// ignore-emscripten no pic
|
||||||
|
// ignore-wasm
|
||||||
|
|
||||||
|
#![feature(cfg_relocation_model)]
|
||||||
|
|
||||||
|
#[cfg(relocation_model = "pic")]
|
||||||
|
fn main() {}
|
@ -0,0 +1,4 @@
|
|||||||
|
#[cfg(relocation_model = "pic")] //~ ERROR
|
||||||
|
fn _foo() {}
|
||||||
|
|
||||||
|
fn main() {}
|
@ -0,0 +1,12 @@
|
|||||||
|
error[E0658]: `cfg(relocation_model)` is experimental and subject to change
|
||||||
|
--> $DIR/feature-gate-cfg-relocation-model.rs:1:7
|
||||||
|
|
|
||||||
|
LL | #[cfg(relocation_model = "pic")]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: see issue #114929 <https://github.com/rust-lang/rust/issues/114929> for more information
|
||||||
|
= help: add `#![feature(cfg_relocation_model)]` to the crate attributes to enable
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0658`.
|
Loading…
x
Reference in New Issue
Block a user