Skip to content

Commit

Permalink
Rollup merge of rust-lang#81455 - Amanieu:aarch64_ilp32, r=sanxiyn
Browse files Browse the repository at this point in the history
Add AArch64 big-endian and ILP32 targets

This PR adds 3 new AArch64 targets:
- `aarch64_be-unknown-linux-gnu`
- `aarch64-unknown-linux-gnu_ilp32`
- `aarch64_be-unknown-linux-gnu_ilp32`

It also fixes some ABI issues on big-endian ARM and AArch64.
  • Loading branch information
jackh726 authored Feb 2, 2021
2 parents 51158fc + 3408c58 commit bdf621d
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 47 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1784,9 +1784,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"

[[package]]
name = "libc"
version = "0.2.79"
version = "0.2.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743"
checksum = "7ccac4b00700875e6a07c6cde370d44d32fa01c5a65cdd2fca6858c479d28bb3"
dependencies = [
"rustc-std-workspace-core",
]
Expand Down
12 changes: 8 additions & 4 deletions compiler/rustc_codegen_llvm/src/va_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ fn emit_aapcs_va_arg(
let mut end = bx.build_sibling_block("va_arg.end");
let zero = bx.const_i32(0);
let offset_align = Align::from_bytes(4).unwrap();
assert_eq!(bx.tcx().sess.target.endian, Endian::Little);

let gr_type = target_ty.is_any_ptr() || target_ty.is_integral();
let (reg_off, reg_top_index, slot_size) = if gr_type {
Expand Down Expand Up @@ -144,9 +143,14 @@ fn emit_aapcs_va_arg(
let top = in_reg.load(top, bx.tcx().data_layout.pointer_align.abi);

// reg_value = *(@top + reg_off_v);
let top = in_reg.gep(top, &[reg_off_v]);
let top = in_reg.bitcast(top, bx.cx.type_ptr_to(layout.llvm_type(bx)));
let reg_value = in_reg.load(top, layout.align.abi);
let mut reg_addr = in_reg.gep(top, &[reg_off_v]);
if bx.tcx().sess.target.endian == Endian::Big && layout.size.bytes() != slot_size {
// On big-endian systems the value is right-aligned in its slot.
let offset = bx.const_i32((slot_size - layout.size.bytes()) as i32);
reg_addr = in_reg.gep(reg_addr, &[offset]);
}
let reg_addr = in_reg.bitcast(reg_addr, bx.cx.type_ptr_to(layout.llvm_type(bx)));
let reg_value = in_reg.load(reg_addr, layout.align.abi);
in_reg.br(&end.llbb());

// On Stack block
Expand Down
24 changes: 2 additions & 22 deletions compiler/rustc_target/src/abi/call/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,7 @@ where
let size = ret.layout.size;
let bits = size.bits();
if bits <= 128 {
let unit = if bits <= 8 {
Reg::i8()
} else if bits <= 16 {
Reg::i16()
} else if bits <= 32 {
Reg::i32()
} else {
Reg::i64()
};

ret.cast_to(Uniform { unit, total: size });
ret.cast_to(Uniform { unit: Reg::i64(), total: size });
return;
}
ret.make_indirect();
Expand All @@ -72,17 +62,7 @@ where
let size = arg.layout.size;
let bits = size.bits();
if bits <= 128 {
let unit = if bits <= 8 {
Reg::i8()
} else if bits <= 16 {
Reg::i16()
} else if bits <= 32 {
Reg::i32()
} else {
Reg::i64()
};

arg.cast_to(Uniform { unit, total: size });
arg.cast_to(Uniform { unit: Reg::i64(), total: size });
return;
}
arg.make_indirect();
Expand Down
9 changes: 1 addition & 8 deletions compiler/rustc_target/src/abi/call/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,7 @@ where
let size = ret.layout.size;
let bits = size.bits();
if bits <= 32 {
let unit = if bits <= 8 {
Reg::i8()
} else if bits <= 16 {
Reg::i16()
} else {
Reg::i32()
};
ret.cast_to(Uniform { unit, total: size });
ret.cast_to(Uniform { unit: Reg::i32(), total: size });
return;
}
ret.make_indirect();
Expand Down
20 changes: 20 additions & 0 deletions compiler/rustc_target/src/spec/aarch64_be_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::abi::Endian;
use crate::spec::{Target, TargetOptions};

pub fn target() -> Target {
let mut base = super::linux_gnu_base::opts();
base.max_atomic_width = Some(128);

Target {
llvm_target: "aarch64_be-unknown-linux-gnu".to_string(),
pointer_width: 64,
data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
options: TargetOptions {
unsupported_abis: super::arm_base::unsupported_abis(),
mcount: "\u{1}_mcount".to_string(),
endian: Endian::Big,
..base
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::abi::Endian;
use crate::spec::{Target, TargetOptions};

pub fn target() -> Target {
let mut base = super::linux_gnu_base::opts();
base.max_atomic_width = Some(128);

Target {
llvm_target: "aarch64_be-unknown-linux-gnu_ilp32".to_string(),
pointer_width: 32,
data_layout: "E-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
options: TargetOptions {
unsupported_abis: super::arm_base::unsupported_abis(),
mcount: "\u{1}_mcount".to_string(),
endian: Endian::Big,
..base
},
}
}
18 changes: 18 additions & 0 deletions compiler/rustc_target/src/spec/aarch64_unknown_linux_gnu_ilp32.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use crate::spec::{Target, TargetOptions};

pub fn target() -> Target {
let mut base = super::linux_gnu_base::opts();
base.max_atomic_width = Some(128);

Target {
llvm_target: "aarch64-unknown-linux-gnu_ilp32".to_string(),
pointer_width: 32,
data_layout: "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
arch: "aarch64".to_string(),
options: TargetOptions {
unsupported_abis: super::arm_base::unsupported_abis(),
mcount: "\u{1}_mcount".to_string(),
..base
},
}
}
4 changes: 4 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,10 @@ supported_targets! {
("mipsel-sony-psp", mipsel_sony_psp),
("mipsel-unknown-none", mipsel_unknown_none),
("thumbv4t-none-eabi", thumbv4t_none_eabi),

("aarch64_be-unknown-linux-gnu", aarch64_be_unknown_linux_gnu),
("aarch64-unknown-linux-gnu_ilp32", aarch64_unknown_linux_gnu_ilp32),
("aarch64_be-unknown-linux-gnu_ilp32", aarch64_be_unknown_linux_gnu_ilp32),
}

/// Everything `rustc` knows about how to compile for a specific target.
Expand Down
16 changes: 8 additions & 8 deletions library/std/src/os/linux/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,17 @@ mod arch {
use crate::os::raw::{c_int, c_long};

#[stable(feature = "raw_ext", since = "1.1.0")]
pub type blkcnt_t = u64;
pub type blkcnt_t = i64;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type blksize_t = u64;
pub type blksize_t = i32;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type ino_t = u64;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type nlink_t = u64;
pub type nlink_t = u32;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type off_t = u64;
pub type off_t = i64;
#[stable(feature = "raw_ext", since = "1.1.0")]
pub type time_t = i64;
pub type time_t = c_long;

#[repr(C)]
#[derive(Clone)]
Expand Down Expand Up @@ -288,15 +288,15 @@ mod arch {
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_blocks: i64,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_atime: i64,
pub st_atime: time_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_atime_nsec: c_long,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_mtime: i64,
pub st_mtime: time_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_mtime_nsec: c_long,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_ctime: i64,
pub st_ctime: time_t,
#[stable(feature = "raw_ext", since = "1.1.0")]
pub st_ctime_nsec: c_long,
#[stable(feature = "raw_ext", since = "1.1.0")]
Expand Down
5 changes: 4 additions & 1 deletion library/unwind/src/libunwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ pub const unwinder_private_data_size: usize = 20;
#[cfg(all(target_arch = "arm", target_os = "ios"))]
pub const unwinder_private_data_size: usize = 5;

#[cfg(target_arch = "aarch64")]
#[cfg(all(target_arch = "aarch64", target_pointer_width = "64"))]
pub const unwinder_private_data_size: usize = 2;

#[cfg(all(target_arch = "aarch64", target_pointer_width = "32"))]
pub const unwinder_private_data_size: usize = 5;

#[cfg(target_arch = "mips")]
pub const unwinder_private_data_size: usize = 2;

Expand Down
3 changes: 3 additions & 0 deletions src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,14 @@ target | std | host | notes
`aarch64-apple-tvos` | * | | ARM64 tvOS
`aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD
`aarch64-unknown-hermit` | ? | |
`aarch64-unknown-linux-gnu_ilp32` | ✓ | ✓ | ARM64 Linux (ILP32 ABI)
`aarch64-unknown-netbsd` | ✓ | ✓ |
`aarch64-unknown-openbsd` | ✓ | ✓ | ARM64 OpenBSD
`aarch64-unknown-redox` | ? | | ARM64 Redox OS
`aarch64-uwp-windows-msvc` | ? | |
`aarch64-wrs-vxworks` | ? | |
`aarch64_be-unknown-linux-gnu` | ✓ | ✓ | ARM64 Linux (big-endian)
`aarch64_be-unknown-linux-gnu_ilp32` | ✓ | ✓ | ARM64 Linux (big-endian, ILP32 ABI)
`armv4t-unknown-linux-gnueabi` | ? | |
`armv5te-unknown-linux-uclibceabi` | ? | | ARMv5TE Linux with uClibc
`armv6-unknown-freebsd` | ✓ | ✓ | ARMv6 FreeBSD
Expand Down
6 changes: 5 additions & 1 deletion src/tools/compiletest/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const OS_TABLE: &[(&str, &str)] = &[

const ARCH_TABLE: &[(&str, &str)] = &[
("aarch64", "aarch64"),
("aarch64_be", "aarch64"),
("amd64", "x86_64"),
("arm", "arm"),
("arm64", "aarch64"),
Expand Down Expand Up @@ -110,6 +111,7 @@ pub const TSAN_SUPPORTED_TARGETS: &[&str] = &[
];

const BIG_ENDIAN: &[&str] = &[
"aarch64_be",
"armebv7r",
"mips",
"mips64",
Expand Down Expand Up @@ -160,7 +162,9 @@ pub fn matches_env(triple: &str, name: &str) -> bool {
}

pub fn get_pointer_width(triple: &str) -> &'static str {
if (triple.contains("64") && !triple.ends_with("gnux32")) || triple.starts_with("s390x") {
if (triple.contains("64") && !triple.ends_with("gnux32") && !triple.ends_with("gnu_ilp32"))
|| triple.starts_with("s390x")
{
"64bit"
} else if triple.starts_with("avr") {
"16bit"
Expand Down

0 comments on commit bdf621d

Please sign in to comment.