|
37 | 37 | use crate::abi::call::Conv;
|
38 | 38 | use crate::abi::{Endian, Integer, Size, TargetDataLayout, TargetDataLayoutErrors};
|
39 | 39 | use crate::json::{Json, ToJson};
|
40 |
| -use crate::spec::abi::{lookup as lookup_abi, Abi}; |
| 40 | +use crate::spec::abi::Abi; |
41 | 41 | use crate::spec::crt_objects::CrtObjects;
|
42 | 42 | use rustc_fs_util::try_canonicalize;
|
43 | 43 | use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
|
@@ -1915,6 +1915,19 @@ impl HasTargetSpec for Target {
|
1915 | 1915 | }
|
1916 | 1916 | }
|
1917 | 1917 |
|
| 1918 | +/// Which C ABI to use for `wasm32-unknown-unknown`. |
| 1919 | +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] |
| 1920 | +pub enum WasmCAbi { |
| 1921 | + /// Spec-compliant C ABI. |
| 1922 | + Spec, |
| 1923 | + /// Legacy ABI. Which is non-spec-compliant. |
| 1924 | + Legacy, |
| 1925 | +} |
| 1926 | + |
| 1927 | +pub trait HasWasmCAbiOpt { |
| 1928 | + fn wasm_c_abi_opt(&self) -> WasmCAbi; |
| 1929 | +} |
| 1930 | + |
1918 | 1931 | type StaticCow<T> = Cow<'static, T>;
|
1919 | 1932 |
|
1920 | 1933 | /// Optional aspects of a target specification.
|
@@ -2273,9 +2286,6 @@ pub struct TargetOptions {
|
2273 | 2286 | /// distributed with the target, the sanitizer should still appear in this list for the target.
|
2274 | 2287 | pub supported_sanitizers: SanitizerSet,
|
2275 | 2288 |
|
2276 |
| - /// If present it's a default value to use for adjusting the C ABI. |
2277 |
| - pub default_adjusted_cabi: Option<Abi>, |
2278 |
| - |
2279 | 2289 | /// Minimum number of bits in #[repr(C)] enum. Defaults to the size of c_int
|
2280 | 2290 | pub c_enum_min_bits: Option<u64>,
|
2281 | 2291 |
|
@@ -2507,7 +2517,6 @@ impl Default for TargetOptions {
|
2507 | 2517 | // `Off` is supported by default, but targets can remove this manually, e.g. Windows.
|
2508 | 2518 | supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]),
|
2509 | 2519 | supported_sanitizers: SanitizerSet::empty(),
|
2510 |
| - default_adjusted_cabi: None, |
2511 | 2520 | c_enum_min_bits: None,
|
2512 | 2521 | generate_arange_section: true,
|
2513 | 2522 | supports_stack_protector: true,
|
@@ -2538,9 +2547,21 @@ impl DerefMut for Target {
|
2538 | 2547 |
|
2539 | 2548 | impl Target {
|
2540 | 2549 | /// Given a function ABI, turn it into the correct ABI for this target.
|
2541 |
| - pub fn adjust_abi(&self, abi: Abi, c_variadic: bool) -> Abi { |
| 2550 | + pub fn adjust_abi<C>(&self, cx: &C, abi: Abi, c_variadic: bool) -> Abi |
| 2551 | + where |
| 2552 | + C: HasWasmCAbiOpt, |
| 2553 | + { |
2542 | 2554 | match abi {
|
2543 |
| - Abi::C { .. } => self.default_adjusted_cabi.unwrap_or(abi), |
| 2555 | + Abi::C { .. } => { |
| 2556 | + if self.arch == "wasm32" |
| 2557 | + && self.os == "unknown" |
| 2558 | + && cx.wasm_c_abi_opt() == WasmCAbi::Legacy |
| 2559 | + { |
| 2560 | + Abi::Wasm |
| 2561 | + } else { |
| 2562 | + abi |
| 2563 | + } |
| 2564 | + } |
2544 | 2565 |
|
2545 | 2566 | // On Windows, `extern "system"` behaves like msvc's `__stdcall`.
|
2546 | 2567 | // `__stdcall` only applies on x86 and on non-variadic functions:
|
@@ -3079,16 +3100,6 @@ impl Target {
|
3079 | 3100 | }
|
3080 | 3101 | }
|
3081 | 3102 | } );
|
3082 |
| - ($key_name:ident, Option<Abi>) => ( { |
3083 |
| - let name = (stringify!($key_name)).replace("_", "-"); |
3084 |
| - obj.remove(&name).and_then(|o| o.as_str().and_then(|s| { |
3085 |
| - match lookup_abi(s) { |
3086 |
| - Ok(abi) => base.$key_name = Some(abi), |
3087 |
| - _ => return Some(Err(format!("'{}' is not a valid value for abi", s))), |
3088 |
| - } |
3089 |
| - Some(Ok(())) |
3090 |
| - })).unwrap_or(Ok(())) |
3091 |
| - } ); |
3092 | 3103 | ($key_name:ident, TargetFamilies) => ( {
|
3093 | 3104 | if let Some(value) = obj.remove("target-family") {
|
3094 | 3105 | if let Some(v) = value.as_array() {
|
@@ -3238,7 +3249,6 @@ impl Target {
|
3238 | 3249 | key!(split_debuginfo, SplitDebuginfo)?;
|
3239 | 3250 | key!(supported_split_debuginfo, fallible_list)?;
|
3240 | 3251 | key!(supported_sanitizers, SanitizerSet)?;
|
3241 |
| - key!(default_adjusted_cabi, Option<Abi>)?; |
3242 | 3252 | key!(generate_arange_section, bool);
|
3243 | 3253 | key!(supports_stack_protector, bool);
|
3244 | 3254 | key!(entry_name);
|
@@ -3502,10 +3512,6 @@ impl ToJson for Target {
|
3502 | 3512 | target_option_val!(entry_abi);
|
3503 | 3513 | target_option_val!(supports_xray);
|
3504 | 3514 |
|
3505 |
| - if let Some(abi) = self.default_adjusted_cabi { |
3506 |
| - d.insert("default-adjusted-cabi".into(), Abi::name(abi).to_json()); |
3507 |
| - } |
3508 |
| - |
3509 | 3515 | // Serializing `-Clink-self-contained` needs a dynamic key to support the
|
3510 | 3516 | // backwards-compatible variants.
|
3511 | 3517 | d.insert(self.link_self_contained.json_key().into(), self.link_self_contained.to_json());
|
|
0 commit comments