Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specification of the system V AMD64 ABI constraint. #34494

Merged
merged 9 commits into from
Sep 1, 2016
Merged
1 change: 1 addition & 0 deletions src/doc/book/ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ This is currently hidden behind the `abi_vectorcall` gate and is subject to chan
* `system`
* `C`
* `win64`
* `sysv64`

Most of the abis in this list are self-explanatory, but the `system` abi may
seem a little odd. This constraint selects whatever the appropriate ABI is for
Expand Down
4 changes: 4 additions & 0 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1677,6 +1677,7 @@ There are also some platform-specific ABI strings:
* `extern "cdecl"` -- The default for x86\_32 C code.
* `extern "stdcall"` -- The default for the Win32 API on x86\_32.
* `extern "win64"` -- The default for C code on x86\_64 Windows.
* `extern "sysv64"` -- The default for C code on non-Windows x86\_64.
* `extern "aapcs"` -- The default for ARM.
* `extern "fastcall"` -- The `fastcall` ABI -- corresponds to MSVC's
`__fastcall` and GCC and clang's `__attribute__((fastcall))`
Expand Down Expand Up @@ -2485,6 +2486,9 @@ The currently implemented features of the reference compiler are:

* - `dotdot_in_tuple_patterns` - Allows `..` in tuple (struct) patterns.

* - `abi_sysv64` - Allows the usage of the system V AMD64 calling convention
(e.g. `extern "sysv64" func fn_();`)

If a feature is promoted to a language feature, then all existing programs will
start to receive compilation warnings about `#![feature]` directives which enabled
the new feature (because the directive is no longer necessary). However, if a
Expand Down
1 change: 1 addition & 0 deletions src/librustc_llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub enum CallConv {
ColdCallConv = 9,
X86StdcallCallConv = 64,
X86FastcallCallConv = 65,
X86_64_SysV = 78,
X86_64_Win64 = 79,
X86_VectorCall = 80
}
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_trans/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ impl FnType {
Vectorcall => llvm::X86_VectorCall,
C => llvm::CCallConv,
Win64 => llvm::X86_64_Win64,
SysV64 => llvm::X86_64_SysV,

// These API constants ought to be more specific...
Cdecl => llvm::CCallConv,
Expand Down Expand Up @@ -483,7 +484,9 @@ impl FnType {

match &ccx.sess().target.target.arch[..] {
"x86" => cabi_x86::compute_abi_info(ccx, self),
"x86_64" => if ccx.sess().target.target.options.is_like_windows {
"x86_64" => if abi == Abi::SysV64 {
cabi_x86_64::compute_abi_info(ccx, self);
} else if abi == Abi::Win64 || ccx.sess().target.target.options.is_like_windows {
cabi_x86_win64::compute_abi_info(ccx, self);
} else {
cabi_x86_64::compute_abi_info(ccx, self);
Expand Down
2 changes: 2 additions & 0 deletions src/libsyntax/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub enum Abi {
Vectorcall,
Aapcs,
Win64,
SysV64,

// Multiplatform ABIs second
Rust,
Expand Down Expand Up @@ -86,6 +87,7 @@ const AbiDatas: &'static [AbiData] = &[
AbiData {abi: Abi::Vectorcall, name: "vectorcall"},
AbiData {abi: Abi::Aapcs, name: "aapcs" },
AbiData {abi: Abi::Win64, name: "win64" },
AbiData {abi: Abi::SysV64, name: "sysv64" },

// Cross-platform ABIs
//
Expand Down
23 changes: 16 additions & 7 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,11 @@ declare_features! (
(active, never_type, "1.13.0", Some(35121)),

// Allows all literals in attribute lists and values of key-value pairs.
(active, attr_literals, "1.13.0", Some(34981))
(active, attr_literals, "1.13.0", Some(34981)),

// Allows the sysV64 ABI to be specified on all platforms
// instead of just the platforms on which it is the C ABI
(active, abi_sysv64, "1.13.0", Some(36167))
);

declare_features! (
Expand Down Expand Up @@ -811,21 +815,26 @@ macro_rules! gate_feature_post {
impl<'a> PostExpansionVisitor<'a> {
fn check_abi(&self, abi: Abi, span: Span) {
match abi {
Abi::RustIntrinsic =>
Abi::RustIntrinsic => {
gate_feature_post!(&self, intrinsics, span,
"intrinsics are subject to change"),
"intrinsics are subject to change");
},
Abi::PlatformIntrinsic => {
gate_feature_post!(&self, platform_intrinsics, span,
"platform intrinsics are experimental and possibly buggy")
"platform intrinsics are experimental and possibly buggy");
},
Abi::Vectorcall => {
gate_feature_post!(&self, abi_vectorcall, span,
"vectorcall is experimental and subject to change")
}
"vectorcall is experimental and subject to change");
},
Abi::RustCall => {
gate_feature_post!(&self, unboxed_closures, span,
"rust-call ABI is subject to change");
}
},
Abi::SysV64 => {
gate_feature_post!(&self, abi_sysv64, span,
"sysv64 ABI is experimental and subject to change");
},
_ => {}
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/test/codegen/abi-sysv64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Checks if the correct annotation for the sysv64 ABI is passed to
// llvm. Also checks that the abi-sysv64 feature gate allows usage
// of the sysv64 abi.

// compile-flags: -C no-prepopulate-passes

#![crate_type = "lib"]
#![feature(abi_sysv64)]

// CHECK: define x86_64_sysvcc i64 @has_sysv64_abi
#[no_mangle]
pub extern "sysv64" fn has_sysv64_abi(a: i64) -> i64 {
a * 2
}
19 changes: 19 additions & 0 deletions src/test/compile-fail/feature-gate-abi-sysv64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Test that the sysv64 ABI cannot be used when abi-sysv64 feature
// gate is not used.

extern "sysv64" fn foo() {}
//~^ ERROR sysv64 ABI is experimental and subject to change

fn main() {
foo();
}
Loading