Skip to content

Commit bdf621d

Browse files
authored
Rollup merge of rust-lang#81455 - Amanieu:aarch64_ilp32, r=sanxiyn
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.
2 parents 51158fc + 3408c58 commit bdf621d

File tree

13 files changed

+96
-47
lines changed

13 files changed

+96
-47
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1784,9 +1784,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
17841784

17851785
[[package]]
17861786
name = "libc"
1787-
version = "0.2.79"
1787+
version = "0.2.85"
17881788
source = "registry+https://github.com/rust-lang/crates.io-index"
1789-
checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743"
1789+
checksum = "7ccac4b00700875e6a07c6cde370d44d32fa01c5a65cdd2fca6858c479d28bb3"
17901790
dependencies = [
17911791
"rustc-std-workspace-core",
17921792
]

compiler/rustc_codegen_llvm/src/va_arg.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ fn emit_aapcs_va_arg(
105105
let mut end = bx.build_sibling_block("va_arg.end");
106106
let zero = bx.const_i32(0);
107107
let offset_align = Align::from_bytes(4).unwrap();
108-
assert_eq!(bx.tcx().sess.target.endian, Endian::Little);
109108

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

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

152156
// On Stack block

compiler/rustc_target/src/abi/call/aarch64.rs

+2-22
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,7 @@ where
4040
let size = ret.layout.size;
4141
let bits = size.bits();
4242
if bits <= 128 {
43-
let unit = if bits <= 8 {
44-
Reg::i8()
45-
} else if bits <= 16 {
46-
Reg::i16()
47-
} else if bits <= 32 {
48-
Reg::i32()
49-
} else {
50-
Reg::i64()
51-
};
52-
53-
ret.cast_to(Uniform { unit, total: size });
43+
ret.cast_to(Uniform { unit: Reg::i64(), total: size });
5444
return;
5545
}
5646
ret.make_indirect();
@@ -72,17 +62,7 @@ where
7262
let size = arg.layout.size;
7363
let bits = size.bits();
7464
if bits <= 128 {
75-
let unit = if bits <= 8 {
76-
Reg::i8()
77-
} else if bits <= 16 {
78-
Reg::i16()
79-
} else if bits <= 32 {
80-
Reg::i32()
81-
} else {
82-
Reg::i64()
83-
};
84-
85-
arg.cast_to(Uniform { unit, total: size });
65+
arg.cast_to(Uniform { unit: Reg::i64(), total: size });
8666
return;
8767
}
8868
arg.make_indirect();

compiler/rustc_target/src/abi/call/arm.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,7 @@ where
4545
let size = ret.layout.size;
4646
let bits = size.bits();
4747
if bits <= 32 {
48-
let unit = if bits <= 8 {
49-
Reg::i8()
50-
} else if bits <= 16 {
51-
Reg::i16()
52-
} else {
53-
Reg::i32()
54-
};
55-
ret.cast_to(Uniform { unit, total: size });
48+
ret.cast_to(Uniform { unit: Reg::i32(), total: size });
5649
return;
5750
}
5851
ret.make_indirect();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use crate::abi::Endian;
2+
use crate::spec::{Target, TargetOptions};
3+
4+
pub fn target() -> Target {
5+
let mut base = super::linux_gnu_base::opts();
6+
base.max_atomic_width = Some(128);
7+
8+
Target {
9+
llvm_target: "aarch64_be-unknown-linux-gnu".to_string(),
10+
pointer_width: 64,
11+
data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
12+
arch: "aarch64".to_string(),
13+
options: TargetOptions {
14+
unsupported_abis: super::arm_base::unsupported_abis(),
15+
mcount: "\u{1}_mcount".to_string(),
16+
endian: Endian::Big,
17+
..base
18+
},
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use crate::abi::Endian;
2+
use crate::spec::{Target, TargetOptions};
3+
4+
pub fn target() -> Target {
5+
let mut base = super::linux_gnu_base::opts();
6+
base.max_atomic_width = Some(128);
7+
8+
Target {
9+
llvm_target: "aarch64_be-unknown-linux-gnu_ilp32".to_string(),
10+
pointer_width: 32,
11+
data_layout: "E-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
12+
arch: "aarch64".to_string(),
13+
options: TargetOptions {
14+
unsupported_abis: super::arm_base::unsupported_abis(),
15+
mcount: "\u{1}_mcount".to_string(),
16+
endian: Endian::Big,
17+
..base
18+
},
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use crate::spec::{Target, TargetOptions};
2+
3+
pub fn target() -> Target {
4+
let mut base = super::linux_gnu_base::opts();
5+
base.max_atomic_width = Some(128);
6+
7+
Target {
8+
llvm_target: "aarch64-unknown-linux-gnu_ilp32".to_string(),
9+
pointer_width: 32,
10+
data_layout: "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
11+
arch: "aarch64".to_string(),
12+
options: TargetOptions {
13+
unsupported_abis: super::arm_base::unsupported_abis(),
14+
mcount: "\u{1}_mcount".to_string(),
15+
..base
16+
},
17+
}
18+
}

compiler/rustc_target/src/spec/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,10 @@ supported_targets! {
808808
("mipsel-sony-psp", mipsel_sony_psp),
809809
("mipsel-unknown-none", mipsel_unknown_none),
810810
("thumbv4t-none-eabi", thumbv4t_none_eabi),
811+
812+
("aarch64_be-unknown-linux-gnu", aarch64_be_unknown_linux_gnu),
813+
("aarch64-unknown-linux-gnu_ilp32", aarch64_unknown_linux_gnu_ilp32),
814+
("aarch64_be-unknown-linux-gnu_ilp32", aarch64_be_unknown_linux_gnu_ilp32),
811815
}
812816

813817
/// Everything `rustc` knows about how to compile for a specific target.

library/std/src/os/linux/raw.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -247,17 +247,17 @@ mod arch {
247247
use crate::os::raw::{c_int, c_long};
248248

249249
#[stable(feature = "raw_ext", since = "1.1.0")]
250-
pub type blkcnt_t = u64;
250+
pub type blkcnt_t = i64;
251251
#[stable(feature = "raw_ext", since = "1.1.0")]
252-
pub type blksize_t = u64;
252+
pub type blksize_t = i32;
253253
#[stable(feature = "raw_ext", since = "1.1.0")]
254254
pub type ino_t = u64;
255255
#[stable(feature = "raw_ext", since = "1.1.0")]
256-
pub type nlink_t = u64;
256+
pub type nlink_t = u32;
257257
#[stable(feature = "raw_ext", since = "1.1.0")]
258-
pub type off_t = u64;
258+
pub type off_t = i64;
259259
#[stable(feature = "raw_ext", since = "1.1.0")]
260-
pub type time_t = i64;
260+
pub type time_t = c_long;
261261

262262
#[repr(C)]
263263
#[derive(Clone)]
@@ -288,15 +288,15 @@ mod arch {
288288
#[stable(feature = "raw_ext", since = "1.1.0")]
289289
pub st_blocks: i64,
290290
#[stable(feature = "raw_ext", since = "1.1.0")]
291-
pub st_atime: i64,
291+
pub st_atime: time_t,
292292
#[stable(feature = "raw_ext", since = "1.1.0")]
293293
pub st_atime_nsec: c_long,
294294
#[stable(feature = "raw_ext", since = "1.1.0")]
295-
pub st_mtime: i64,
295+
pub st_mtime: time_t,
296296
#[stable(feature = "raw_ext", since = "1.1.0")]
297297
pub st_mtime_nsec: c_long,
298298
#[stable(feature = "raw_ext", since = "1.1.0")]
299-
pub st_ctime: i64,
299+
pub st_ctime: time_t,
300300
#[stable(feature = "raw_ext", since = "1.1.0")]
301301
pub st_ctime_nsec: c_long,
302302
#[stable(feature = "raw_ext", since = "1.1.0")]

library/unwind/src/libunwind.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ pub const unwinder_private_data_size: usize = 20;
3636
#[cfg(all(target_arch = "arm", target_os = "ios"))]
3737
pub const unwinder_private_data_size: usize = 5;
3838

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

42+
#[cfg(all(target_arch = "aarch64", target_pointer_width = "32"))]
43+
pub const unwinder_private_data_size: usize = 5;
44+
4245
#[cfg(target_arch = "mips")]
4346
pub const unwinder_private_data_size: usize = 2;
4447

src/doc/rustc/src/platform-support.md

+3
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,14 @@ target | std | host | notes
156156
`aarch64-apple-tvos` | * | | ARM64 tvOS
157157
`aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD
158158
`aarch64-unknown-hermit` | ? | |
159+
`aarch64-unknown-linux-gnu_ilp32` | ✓ | ✓ | ARM64 Linux (ILP32 ABI)
159160
`aarch64-unknown-netbsd` | ✓ | ✓ |
160161
`aarch64-unknown-openbsd` | ✓ | ✓ | ARM64 OpenBSD
161162
`aarch64-unknown-redox` | ? | | ARM64 Redox OS
162163
`aarch64-uwp-windows-msvc` | ? | |
163164
`aarch64-wrs-vxworks` | ? | |
165+
`aarch64_be-unknown-linux-gnu` | ✓ | ✓ | ARM64 Linux (big-endian)
166+
`aarch64_be-unknown-linux-gnu_ilp32` | ✓ | ✓ | ARM64 Linux (big-endian, ILP32 ABI)
164167
`armv4t-unknown-linux-gnueabi` | ? | |
165168
`armv5te-unknown-linux-uclibceabi` | ? | | ARMv5TE Linux with uClibc
166169
`armv6-unknown-freebsd` | ✓ | ✓ | ARMv6 FreeBSD

src/tools/compiletest/src/util.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const OS_TABLE: &[(&str, &str)] = &[
3838

3939
const ARCH_TABLE: &[(&str, &str)] = &[
4040
("aarch64", "aarch64"),
41+
("aarch64_be", "aarch64"),
4142
("amd64", "x86_64"),
4243
("arm", "arm"),
4344
("arm64", "aarch64"),
@@ -110,6 +111,7 @@ pub const TSAN_SUPPORTED_TARGETS: &[&str] = &[
110111
];
111112

112113
const BIG_ENDIAN: &[&str] = &[
114+
"aarch64_be",
113115
"armebv7r",
114116
"mips",
115117
"mips64",
@@ -160,7 +162,9 @@ pub fn matches_env(triple: &str, name: &str) -> bool {
160162
}
161163

162164
pub fn get_pointer_width(triple: &str) -> &'static str {
163-
if (triple.contains("64") && !triple.ends_with("gnux32")) || triple.starts_with("s390x") {
165+
if (triple.contains("64") && !triple.ends_with("gnux32") && !triple.ends_with("gnu_ilp32"))
166+
|| triple.starts_with("s390x")
167+
{
164168
"64bit"
165169
} else if triple.starts_with("avr") {
166170
"16bit"

0 commit comments

Comments
 (0)