Skip to content

Commit 2352af9

Browse files
authored
Rollup merge of rust-lang#96971 - zhaixiaojuan:master, r=wesleywiser
Initial support for loongarch64-unknown-linux-gnu Hi, We hope to add a new port in rust for LoongArch. LoongArch intro LoongArch is a RISC style ISA which is independently designed by Loongson Technology in China. It is divided into two versions, the 32-bit version (LA32) and the 64-bit version (LA64). LA64 applications have application-level backward binary compatibility with LA32 applications. LoongArch is composed of a basic part (Loongson Base) and an expanded part. The expansion part includes Loongson Binary Translation (LBT), Loongson VirtualiZation (LVZ), Loongson SIMD EXtension (LSX) and Loongson Advanced SIMD EXtension(LASX). Currently the LA464 processor core supports LoongArch ISA and the Loongson 3A5000 processor integrates 4 64-bit LA464 cores. LA464 is a four-issue 64-bit high-performance processor core. It can be used as a single core for high-end embedded and desktop applications, or as a basic processor core to form an on-chip multi-core system for server and high-performance machine applications. Documentations: ISA: https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html ABI: https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html More docs can be found at: https://loongson.github.io/LoongArch-Documentation/README-EN.html Since last year, we have locally adapted two versions of rust, rust1.41 and rust1.57, and completed the test locally. I'm not sure if I'm submitting all the patches at once, so I split up the patches and here's one of the commits
2 parents dfe024e + a3f0046 commit 2352af9

File tree

21 files changed

+150
-4
lines changed

21 files changed

+150
-4
lines changed

compiler/rustc_codegen_gcc/example/alloc_system.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
const MIN_ALIGN: usize = 8;
1616
#[cfg(any(target_arch = "x86_64",
1717
target_arch = "aarch64",
18+
target_arch = "loongarch64",
1819
target_arch = "mips64",
1920
target_arch = "s390x",
2021
target_arch = "sparc64"))]

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
127127
"msp430" => Architecture::Msp430,
128128
"hexagon" => Architecture::Hexagon,
129129
"bpf" => Architecture::Bpf,
130+
"loongarch64" => Architecture::LoongArch64,
130131
// Unsupported architecture.
131132
_ => return None,
132133
};
@@ -190,6 +191,10 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
190191
}
191192
e_flags
192193
}
194+
Architecture::LoongArch64 => {
195+
// Source: https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_e_flags_identifies_abi_type_and_version
196+
elf::EF_LARCH_OBJABI_V1 | elf::EF_LARCH_ABI_DOUBLE_FLOAT
197+
}
193198
_ => 0,
194199
};
195200
// adapted from LLVM's `MCELFObjectTargetWriter::getOSABI`

compiler/rustc_llvm/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const OPTIONAL_COMPONENTS: &[&str] = &[
1010
"aarch64",
1111
"amdgpu",
1212
"avr",
13+
"loongarch",
1314
"m68k",
1415
"mips",
1516
"powerpc",

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ extern "C" void LLVMTimeTraceProfilerFinish(const char* FileName) {
146146
#define SUBTARGET_HEXAGON
147147
#endif
148148

149+
#ifdef LLVM_COMPONENT_LOONGARCH
150+
#define SUBTARGET_LOONGARCH SUBTARGET(LoongArch)
151+
#else
152+
#define SUBTARGET_LOONGARCH
153+
#endif
154+
149155
#define GEN_SUBTARGETS \
150156
SUBTARGET_X86 \
151157
SUBTARGET_ARM \
@@ -159,6 +165,7 @@ extern "C" void LLVMTimeTraceProfilerFinish(const char* FileName) {
159165
SUBTARGET_SPARC \
160166
SUBTARGET_HEXAGON \
161167
SUBTARGET_RISCV \
168+
SUBTARGET_LOONGARCH \
162169

163170
#define SUBTARGET(x) \
164171
namespace llvm { \

compiler/rustc_llvm/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ pub fn initialize_available_targets() {
102102
LLVMInitializeM68kAsmPrinter,
103103
LLVMInitializeM68kAsmParser
104104
);
105+
init_target!(
106+
llvm_component = "loongarch",
107+
LLVMInitializeLoongArchTargetInfo,
108+
LLVMInitializeLoongArchTarget,
109+
LLVMInitializeLoongArchTargetMC,
110+
LLVMInitializeLoongArchAsmPrinter,
111+
LLVMInitializeLoongArchAsmParser
112+
);
105113
init_target!(
106114
llvm_component = "mips",
107115
LLVMInitializeMipsTargetInfo,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use crate::spec::{Target, TargetOptions};
2+
3+
pub fn target() -> Target {
4+
Target {
5+
llvm_target: "loongarch64-unknown-linux-gnu".into(),
6+
pointer_width: 64,
7+
data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".into(),
8+
arch: "loongarch64".into(),
9+
options: TargetOptions {
10+
cpu: "generic".into(),
11+
features: "+f,+d".into(),
12+
llvm_abiname: "lp64d".into(),
13+
max_atomic_width: Some(64),
14+
..super::linux_gnu_base::opts()
15+
},
16+
}
17+
}

compiler/rustc_target/src/spec/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,7 @@ supported_targets! {
10211021
("x86_64-unknown-linux-gnux32", x86_64_unknown_linux_gnux32),
10221022
("i686-unknown-linux-gnu", i686_unknown_linux_gnu),
10231023
("i586-unknown-linux-gnu", i586_unknown_linux_gnu),
1024+
("loongarch64-unknown-linux-gnu", loongarch64_unknown_linux_gnu),
10241025
("m68k-unknown-linux-gnu", m68k_unknown_linux_gnu),
10251026
("mips-unknown-linux-gnu", mips_unknown_linux_gnu),
10261027
("mips64-unknown-linux-gnuabi64", mips64_unknown_linux_gnuabi64),

config.example.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ changelog-seen = 2
8888
# the resulting rustc being unable to compile for the disabled architectures.
8989
#
9090
# To add support for new targets, see https://rustc-dev-guide.rust-lang.org/building/new-target.html.
91-
#targets = "AArch64;ARM;BPF;Hexagon;MSP430;Mips;NVPTX;PowerPC;RISCV;Sparc;SystemZ;WebAssembly;X86"
91+
#targets = "AArch64;ARM;BPF;Hexagon;LoongArch;MSP430;Mips;NVPTX;PowerPC;RISCV;Sparc;SystemZ;WebAssembly;X86"
9292

9393
# LLVM experimental targets to build support for. These targets are specified in
9494
# the same format as above, but since these targets are experimental, they are

library/std/src/env.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,7 @@ pub mod consts {
895895
/// - x86_64
896896
/// - arm
897897
/// - aarch64
898+
/// - loongarch64
898899
/// - m68k
899900
/// - mips
900901
/// - mips64

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ mod arch {
231231
}
232232

233233
#[cfg(any(
234+
target_arch = "loongarch64",
234235
target_arch = "mips64",
235236
target_arch = "s390x",
236237
target_arch = "sparc64",

0 commit comments

Comments
 (0)