Skip to content

Initial version of AArch64 support. #20017

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/liballoc/heap.rs
Original file line number Diff line number Diff line change
@@ -120,7 +120,8 @@ unsafe fn exchange_free(ptr: *mut u8, old_size: uint, align: uint) {
target_arch = "mipsel"))]
const MIN_ALIGN: uint = 8;
#[cfg(any(target_arch = "x86",
target_arch = "x86_64"))]
target_arch = "x86_64",
target_arch = "aarch64"))]
const MIN_ALIGN: uint = 16;

#[cfg(external_funcs)]
6 changes: 6 additions & 0 deletions src/libcore/hash/sip.rs
Original file line number Diff line number Diff line change
@@ -424,6 +424,12 @@ mod tests {
}
}

#[test] #[cfg(target_arch = "aarch64")]
fn test_hash_uint() {
let val = 0xdeadbeef_deadbeef_u64;
assert_eq!(hash(&(val as u64)), hash(&(val as uint)));
assert!(hash(&(val as u32)) != hash(&(val as uint)));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't the 32-bit and 64-bit architectures reuse the same tests, one for each?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems/seemed to me that they could. However, I didn't want/dare to go against the practice I found here: fn test_hash_uint() is already cloned for arm and x86 targets, that's why I added a new version for aarch64, cloning the x86_64 version. Shall the refactoring (merging the clones) be part of this patch (which will make it not purely aarch64-focused)?

#[test] #[cfg(target_arch = "arm")]
fn test_hash_uint() {
let val = 0xdeadbeef_deadbeef_u64;
6 changes: 4 additions & 2 deletions src/libcoretest/mem.rs
Original file line number Diff line number Diff line change
@@ -29,7 +29,8 @@ fn size_of_32() {
}

#[test]
#[cfg(target_arch = "x86_64")]
#[cfg(any(target_arch = "x86_64",
target_arch = "aarch64"))]
fn size_of_64() {
assert_eq!(size_of::<uint>(), 8u);
assert_eq!(size_of::<*const uint>(), 8u);
@@ -61,7 +62,8 @@ fn align_of_32() {
}

#[test]
#[cfg(target_arch = "x86_64")]
#[cfg(any(target_arch = "x86_64",
target_arch = "aarch64"))]
fn align_of_64() {
assert_eq!(align_of::<uint>(), 8u);
assert_eq!(align_of::<*const uint>(), 8u);
67 changes: 63 additions & 4 deletions src/liblibc/lib.rs
Original file line number Diff line number Diff line change
@@ -720,10 +720,14 @@ pub mod types {

}

#[cfg(target_arch = "x86_64")]
#[cfg(any(target_arch = "x86_64",
target_arch = "aarch64"))]
pub mod arch {
pub mod c95 {
#[cfg(not(target_arch = "aarch64"))]
pub type c_char = i8;
#[cfg(target_arch = "aarch64")]
pub type c_char = u8;
pub type c_schar = i8;
pub type c_uchar = u8;
pub type c_short = i16;
@@ -739,7 +743,10 @@ pub mod types {
pub type clock_t = i64;
pub type time_t = i64;
pub type suseconds_t = i64;
#[cfg(not(target_arch = "aarch64"))]
pub type wchar_t = i32;
#[cfg(target_arch = "aarch64")]
pub type wchar_t = u32;
}
pub mod c99 {
pub type c_longlong = i64;
@@ -760,6 +767,7 @@ pub mod types {
pub type mode_t = u32;
pub type ssize_t = i64;
}
#[cfg(not(target_arch = "aarch64"))]
pub mod posix01 {
use types::os::arch::c95::{c_int, c_long, time_t};
use types::os::arch::posix88::{dev_t, gid_t, ino_t};
@@ -769,6 +777,7 @@ pub mod types {
pub type nlink_t = u64;
pub type blksize_t = i64;
pub type blkcnt_t = i64;

#[repr(C)]
#[deriving(Copy)] pub struct stat {
pub st_dev: dev_t,
@@ -802,6 +811,51 @@ pub mod types {
pub __size: [u64, ..7]
}
}
#[cfg(target_arch = "aarch64")]
pub mod posix01 {
use types::os::arch::c95::{c_int, c_long, time_t};
use types::os::arch::posix88::{dev_t, gid_t, ino_t};
use types::os::arch::posix88::{mode_t, off_t};
use types::os::arch::posix88::{uid_t};

pub type nlink_t = u32;
pub type blksize_t = i32;
pub type blkcnt_t = i64;

#[repr(C)]
#[deriving(Copy)] pub struct stat {
pub st_dev: dev_t,
pub st_ino: ino_t,
pub st_mode: mode_t,
pub st_nlink: nlink_t,
pub st_uid: uid_t,
pub st_gid: gid_t,
pub st_rdev: dev_t,
pub __pad1: dev_t,
pub st_size: off_t,
pub st_blksize: blksize_t,
pub __pad2: c_int,
pub st_blocks: blkcnt_t,
pub st_atime: time_t,
pub st_atime_nsec: c_long,
pub st_mtime: time_t,
pub st_mtime_nsec: c_long,
pub st_ctime: time_t,
pub st_ctime_nsec: c_long,
pub __unused: [c_int, ..2],
}

#[repr(C)]
#[deriving(Copy)] pub struct utimbuf {
pub actime: time_t,
pub modtime: time_t,
}

#[repr(C)]
#[deriving(Copy)] pub struct pthread_attr_t {
pub __size: [u64, ..8]
}
}
pub mod posix08 {
}
pub mod bsd44 {
@@ -2432,7 +2486,8 @@ pub mod consts {
}
#[cfg(any(target_arch = "x86",
target_arch = "x86_64",
target_arch = "arm"))]
target_arch = "arm",
target_arch = "aarch64"))]
pub mod posix88 {
use types::os::arch::c95::c_int;
use types::common::c95::c_void;
@@ -2927,7 +2982,9 @@ pub mod consts {
pub const PTHREAD_STACK_MIN: size_t = 16384;

#[cfg(all(target_os = "linux",
any(target_arch = "mips", target_arch = "mipsel")))]
any(target_arch = "mips",
target_arch = "mipsel",
target_arch = "aarch64")))]
pub const PTHREAD_STACK_MIN: size_t = 131072;

pub const CLOCK_REALTIME: c_int = 0;
@@ -2936,6 +2993,7 @@ pub mod consts {
pub mod posix08 {
}
#[cfg(any(target_arch = "arm",
target_arch = "aarch64",
target_arch = "x86",
target_arch = "x86_64"))]
pub mod bsd44 {
@@ -3031,7 +3089,8 @@ pub mod consts {
}
#[cfg(any(target_arch = "x86",
target_arch = "x86_64",
target_arch = "arm"))]
target_arch = "arm",
target_arch = "aarch64"))]
pub mod extra {
use types::os::arch::c95::c_int;

26 changes: 26 additions & 0 deletions src/librustc_back/target/aarch64_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2014 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.

use target::Target;

pub fn target() -> Target {
let base = super::linux_base::opts();
Target {
data_layout: "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-\
f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-\
n32:64-S128".to_string(),
llvm_target: "aarch64-unknown-linux-gnu".to_string(),
target_endian: "little".to_string(),
target_word_size: "64".to_string(),
arch: "aarch64".to_string(),
target_os: "linux".to_string(),
options: base,
}
}
6 changes: 4 additions & 2 deletions src/librustc_back/target/mod.rs
Original file line number Diff line number Diff line change
@@ -60,6 +60,7 @@ mod arm_apple_ios;
mod arm_linux_androideabi;
mod arm_unknown_linux_gnueabi;
mod arm_unknown_linux_gnueabihf;
mod aarch64_unknown_linux_gnu;
mod i686_apple_darwin;
mod i386_apple_ios;
mod i686_pc_windows_gnu;
@@ -88,8 +89,8 @@ pub struct Target {
pub target_word_size: String,
/// OS name to use for conditional compilation.
pub target_os: String,
/// Architecture to use for ABI considerations. Valid options: "x86", "x86_64", "arm", and
/// "mips". "mips" includes "mipsel".
/// Architecture to use for ABI considerations. Valid options: "x86", "x86_64", "arm",
/// "aarch64", and "mips". "mips" includes "mipsel".
pub arch: String,
/// Optional settings with defaults.
pub options: TargetOptions,
@@ -335,6 +336,7 @@ impl Target {
arm_linux_androideabi,
arm_unknown_linux_gnueabi,
arm_unknown_linux_gnueabihf,
aarch64_unknown_linux_gnu,

x86_64_unknown_freebsd,

11 changes: 11 additions & 0 deletions src/librustc_llvm/lib.rs
Original file line number Diff line number Diff line change
@@ -1986,6 +1986,11 @@ extern {
pub fn LLVMInitializeARMTargetMC();
pub fn LLVMInitializeARMAsmPrinter();
pub fn LLVMInitializeARMAsmParser();
pub fn LLVMInitializeAArch64TargetInfo();
pub fn LLVMInitializeAArch64Target();
pub fn LLVMInitializeAArch64TargetMC();
pub fn LLVMInitializeAArch64AsmPrinter();
pub fn LLVMInitializeAArch64AsmParser();
pub fn LLVMInitializeMipsTargetInfo();
pub fn LLVMInitializeMipsTarget();
pub fn LLVMInitializeMipsTargetMC();
@@ -2255,6 +2260,12 @@ pub unsafe fn static_link_hack_this_sucks() {
LLVMInitializeARMAsmPrinter();
LLVMInitializeARMAsmParser();

LLVMInitializeAArch64TargetInfo();
LLVMInitializeAArch64Target();
LLVMInitializeAArch64TargetMC();
LLVMInitializeAArch64AsmPrinter();
LLVMInitializeAArch64AsmParser();

LLVMInitializeMipsTargetInfo();
LLVMInitializeMipsTarget();
LLVMInitializeMipsTargetMC();
6 changes: 6 additions & 0 deletions src/librustc_trans/back/write.rs
Original file line number Diff line number Diff line change
@@ -1026,6 +1026,12 @@ unsafe fn configure_llvm(sess: &Session) {
llvm::LLVMInitializeARMAsmPrinter();
llvm::LLVMInitializeARMAsmParser();

llvm::LLVMInitializeAArch64TargetInfo();
llvm::LLVMInitializeAArch64Target();
llvm::LLVMInitializeAArch64TargetMC();
llvm::LLVMInitializeAArch64AsmPrinter();
llvm::LLVMInitializeAArch64AsmParser();

llvm::LLVMInitializeMipsTargetInfo();
llvm::LLVMInitializeMipsTarget();
llvm::LLVMInitializeMipsTargetMC();
1 change: 1 addition & 0 deletions src/librustc_trans/trans/asm.rs
Original file line number Diff line number Diff line change
@@ -165,6 +165,7 @@ pub fn trans_inline_asm<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ia: &ast::InlineAsm)
// Basically what clang does

#[cfg(any(target_arch = "arm",
target_arch = "aarch64",
target_arch = "mips",
target_arch = "mipsel"))]
fn get_clobbers() -> String {
4 changes: 3 additions & 1 deletion src/librustc_trans/trans/cabi.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
@@ -17,6 +17,7 @@ use trans::cabi_x86;
use trans::cabi_x86_64;
use trans::cabi_x86_win64;
use trans::cabi_arm;
use trans::cabi_aarch64;
use trans::cabi_mips;
use trans::type_::Type;

@@ -119,6 +120,7 @@ pub fn compute_abi_info(ccx: &CrateContext,
cabi_x86_64::compute_abi_info(ccx, atys, rty, ret_def)
},
"arm" => cabi_arm::compute_abi_info(ccx, atys, rty, ret_def),
"aarch64" => cabi_aarch64::compute_abi_info(ccx, atys, rty, ret_def),
"mips" => cabi_mips::compute_abi_info(ccx, atys, rty, ret_def),
a => ccx.sess().fatal((format!("unrecognized arch \"{}\" in target specification", a))
.as_slice()),
Loading