From 52fbf83831b4ae275a70312adf798ccc57084e16 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Sat, 4 Nov 2023 16:01:05 -0700 Subject: [PATCH] draft: Add support for hexagon-unknown-none-elf as target Signed-off-by: Brian Cain --- compiler/rustc_target/src/spec/mod.rs | 1 + .../spec/targets/hexagon_unknown_none_elf.rs | 27 ++++++ .../rustc_target/src/spec/tests/tests_impl.rs | 3 +- src/doc/rustc/src/SUMMARY.md | 1 + src/doc/rustc/src/platform-support.md | 1 + .../hexagon-unknown-none-elf.md | 84 +++++++++++++++++++ 6 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 compiler/rustc_target/src/spec/targets/hexagon_unknown_none_elf.rs create mode 100644 src/doc/rustc/src/platform-support/hexagon-unknown-none-elf.md diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index f04799482c831..af23c7cbef4c0 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -1494,6 +1494,7 @@ supported_targets! { ("mips64-unknown-linux-muslabi64", mips64_unknown_linux_muslabi64), ("mips64el-unknown-linux-muslabi64", mips64el_unknown_linux_muslabi64), ("hexagon-unknown-linux-musl", hexagon_unknown_linux_musl), + ("hexagon-unknown-none-elf", hexagon_unknown_none_elf), ("mips-unknown-linux-uclibc", mips_unknown_linux_uclibc), ("mipsel-unknown-linux-uclibc", mipsel_unknown_linux_uclibc), diff --git a/compiler/rustc_target/src/spec/targets/hexagon_unknown_none_elf.rs b/compiler/rustc_target/src/spec/targets/hexagon_unknown_none_elf.rs new file mode 100644 index 0000000000000..205f195a701e0 --- /dev/null +++ b/compiler/rustc_target/src/spec/targets/hexagon_unknown_none_elf.rs @@ -0,0 +1,27 @@ +use crate::spec::{PanicStrategy, Target, TargetOptions}; + +pub fn target() -> Target { + Target { + llvm_target: "hexagon-unknown-none-elf".into(), + pointer_width: 32, + data_layout: concat!( + "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32", + ":32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32", + ":32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048", + ":2048:2048" + ) + .into(), + arch: "hexagon".into(), + + options: TargetOptions { + cpu: "hexagonv60".into(), + panic_strategy: PanicStrategy::Abort, + dynamic_linking: true, + features: "-small-data,+hvx-length128b".into(), + max_atomic_width: Some(32), + emit_debug_gdb_scripts: false, + c_enum_min_bits: Some(8), + ..Default::default() + }, + } +} diff --git a/compiler/rustc_target/src/spec/tests/tests_impl.rs b/compiler/rustc_target/src/spec/tests/tests_impl.rs index 257867b1b807b..3fefd60f7cd89 100644 --- a/compiler/rustc_target/src/spec/tests/tests_impl.rs +++ b/compiler/rustc_target/src/spec/tests/tests_impl.rs @@ -116,7 +116,8 @@ impl Target { // Check dynamic linking stuff // BPF: when targeting user space vms (like rbpf), those can load dynamic libraries. - if self.os == "none" && self.arch != "bpf" { + // hexagon: when targeting QuRT, that OS can load dynamic libraries. + if self.os == "none" && (self.arch != "bpf" && self.arch != "hexagon") { assert!(!self.dynamic_linking); } if self.only_cdylib diff --git a/src/doc/rustc/src/SUMMARY.md b/src/doc/rustc/src/SUMMARY.md index 1b27b77b3e6b2..da5c98b1f7c66 100644 --- a/src/doc/rustc/src/SUMMARY.md +++ b/src/doc/rustc/src/SUMMARY.md @@ -34,6 +34,7 @@ - [\*-unknown-fuchsia](platform-support/fuchsia.md) - [\*-kmc-solid_\*](platform-support/kmc-solid.md) - [csky-unknown-linux-gnuabiv2\*](platform-support/csky-unknown-linux-gnuabiv2.md) + - [hexagon-unknown-none-elf](platform-support/hexagon-unknown-none-elf.md) - [loongarch\*-unknown-linux-\*](platform-support/loongarch-linux.md) - [loongarch\*-unknown-none\*](platform-support/loongarch-none.md) - [m68k-unknown-linux-gnu](platform-support/m68k-unknown-linux-gnu.md) diff --git a/src/doc/rustc/src/platform-support.md b/src/doc/rustc/src/platform-support.md index 907e9c59f316c..ec5c365c59200 100644 --- a/src/doc/rustc/src/platform-support.md +++ b/src/doc/rustc/src/platform-support.md @@ -263,6 +263,7 @@ target | std | host | notes `bpfel-unknown-none` | * | | BPF (little endian) `csky-unknown-linux-gnuabiv2` | ✓ | | C-SKY abiv2 Linux (little endian) `csky-unknown-linux-gnuabiv2hf` | ✓ | | C-SKY abiv2 Linux, hardfloat (little endian) +[`hexagon-unknown-none-elf`](platform-support/hexagon-unknown-none-elf.md)| * | Bare Hexagon (v60+, HVX) `hexagon-unknown-linux-musl` | ? | | `i386-apple-ios` | ✓ | | 32-bit x86 iOS [^x86_32-floats-return-ABI] [`i586-pc-nto-qnx700`](platform-support/nto-qnx.md) | * | | 32-bit x86 QNX Neutrino 7.0 RTOS [^x86_32-floats-return-ABI] diff --git a/src/doc/rustc/src/platform-support/hexagon-unknown-none-elf.md b/src/doc/rustc/src/platform-support/hexagon-unknown-none-elf.md new file mode 100644 index 0000000000000..baa831090bd21 --- /dev/null +++ b/src/doc/rustc/src/platform-support/hexagon-unknown-none-elf.md @@ -0,0 +1,84 @@ +# `hexagon-unknown-none-elf` + +**Tier: 3** + +Rust for baremetal Hexagon DSPs. + +| Target | Descriptions | +| ------------------------ | ----------------------------------------- | +| hexagon-unknown-none-elf | Hexagon 32-bit (freestanding, hardfloat) | + +## Target maintainers + +- Brian Cain, `bcain@quicinc.com`, https://github.com/androm3da + +## Requirements + +This target is cross-compiled. There is no support for `std`. There is no +default allocator, but it's possible to use `alloc` by supplying an allocator. + +Document the expectations of binaries built for the target. Do they assume +specific minimum features beyond the baseline of the CPU/environment/etc? What +version of the OS or environment do they expect? + +By default, code generated with this target should run on Hexagon DSP hardware. + +- `-Ctarget-cpu=hexagonv73` adds support for instructions defined up to Hexagon V73. + +Functions marked `extern "C"` use the [Hexagon architecture calling convention](https://tbd). + +This target generates PIC ELF binaries. + +## Building the target + +You can build Rust with support for the target by adding it to the `target` +list in `config.toml`: + +```toml +[build] +build-stage = 1 +host = [""] +target = ["", "hexagon-unknown-none-elf"] + +[target.hexagon-unknown-none-elf] + +cc = "hexagon-unknown-none-elf-clang" +cxx = "hexagon-unknown-none-elf-clang++" +linker = "hexagon-unknown-none-elf-clang" +llvm-libunwind = 'in-tree' +``` + +Replace `` with `x86_64-unknown-linux-gnu` or whatever +else is appropriate for your host machine. + +## Building Rust programs + +Rust does not yet ship pre-compiled artifacts for this target. To compile for +this target, you will either need to build Rust with the target enabled (see +"Building the target" above), or build your own copy of `core` by using +`build-std` or similar. + +## Testing + +Since `hexagon-unknown-none-elf` supports a variety of different environments and does +not support `std`, this target does not support running the Rust test suite. + +## Cross-compilation toolchains and C code + +This target has been tested using `hexagon-sim` from the Hexagon SDK. + +`.cargo/config.toml`: +```toml +[target.hexagon-unknown-none-elf] + +cc = "hexagon-unknown-none-elf-clang" +cxx = "hexagon-unknown-none-elf-clang++" +linker = "hexagon-unknown-none-elf-clang" +runner = "hexagon-sim FIXME foo bar baz" + +[build] +target = ["hexagon-unknown-none-elf"] +rustflags = "-Ctarget-cpu=hexagonv73" +``` + +FIXME EXAMPLE