Skip to content

Commit 52fbf83

Browse files
committed
draft: Add support for hexagon-unknown-none-elf as target
Signed-off-by: Brian Cain <[email protected]>
1 parent 90fdc1f commit 52fbf83

File tree

6 files changed

+116
-1
lines changed

6 files changed

+116
-1
lines changed

compiler/rustc_target/src/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,7 @@ supported_targets! {
14941494
("mips64-unknown-linux-muslabi64", mips64_unknown_linux_muslabi64),
14951495
("mips64el-unknown-linux-muslabi64", mips64el_unknown_linux_muslabi64),
14961496
("hexagon-unknown-linux-musl", hexagon_unknown_linux_musl),
1497+
("hexagon-unknown-none-elf", hexagon_unknown_none_elf),
14971498

14981499
("mips-unknown-linux-uclibc", mips_unknown_linux_uclibc),
14991500
("mipsel-unknown-linux-uclibc", mipsel_unknown_linux_uclibc),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use crate::spec::{PanicStrategy, Target, TargetOptions};
2+
3+
pub fn target() -> Target {
4+
Target {
5+
llvm_target: "hexagon-unknown-none-elf".into(),
6+
pointer_width: 32,
7+
data_layout: concat!(
8+
"e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32",
9+
":32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32",
10+
":32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048",
11+
":2048:2048"
12+
)
13+
.into(),
14+
arch: "hexagon".into(),
15+
16+
options: TargetOptions {
17+
cpu: "hexagonv60".into(),
18+
panic_strategy: PanicStrategy::Abort,
19+
dynamic_linking: true,
20+
features: "-small-data,+hvx-length128b".into(),
21+
max_atomic_width: Some(32),
22+
emit_debug_gdb_scripts: false,
23+
c_enum_min_bits: Some(8),
24+
..Default::default()
25+
},
26+
}
27+
}

compiler/rustc_target/src/spec/tests/tests_impl.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ impl Target {
116116

117117
// Check dynamic linking stuff
118118
// BPF: when targeting user space vms (like rbpf), those can load dynamic libraries.
119-
if self.os == "none" && self.arch != "bpf" {
119+
// hexagon: when targeting QuRT, that OS can load dynamic libraries.
120+
if self.os == "none" && (self.arch != "bpf" && self.arch != "hexagon") {
120121
assert!(!self.dynamic_linking);
121122
}
122123
if self.only_cdylib

src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
- [\*-unknown-fuchsia](platform-support/fuchsia.md)
3535
- [\*-kmc-solid_\*](platform-support/kmc-solid.md)
3636
- [csky-unknown-linux-gnuabiv2\*](platform-support/csky-unknown-linux-gnuabiv2.md)
37+
- [hexagon-unknown-none-elf](platform-support/hexagon-unknown-none-elf.md)
3738
- [loongarch\*-unknown-linux-\*](platform-support/loongarch-linux.md)
3839
- [loongarch\*-unknown-none\*](platform-support/loongarch-none.md)
3940
- [m68k-unknown-linux-gnu](platform-support/m68k-unknown-linux-gnu.md)

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

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ target | std | host | notes
263263
`bpfel-unknown-none` | * | | BPF (little endian)
264264
`csky-unknown-linux-gnuabiv2` | ✓ | | C-SKY abiv2 Linux (little endian)
265265
`csky-unknown-linux-gnuabiv2hf` | ✓ | | C-SKY abiv2 Linux, hardfloat (little endian)
266+
[`hexagon-unknown-none-elf`](platform-support/hexagon-unknown-none-elf.md)| * | Bare Hexagon (v60+, HVX)
266267
`hexagon-unknown-linux-musl` | ? | |
267268
`i386-apple-ios` | ✓ | | 32-bit x86 iOS [^x86_32-floats-return-ABI]
268269
[`i586-pc-nto-qnx700`](platform-support/nto-qnx.md) | * | | 32-bit x86 QNX Neutrino 7.0 RTOS [^x86_32-floats-return-ABI]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# `hexagon-unknown-none-elf`
2+
3+
**Tier: 3**
4+
5+
Rust for baremetal Hexagon DSPs.
6+
7+
| Target | Descriptions |
8+
| ------------------------ | ----------------------------------------- |
9+
| hexagon-unknown-none-elf | Hexagon 32-bit (freestanding, hardfloat) |
10+
11+
## Target maintainers
12+
13+
- Brian Cain, `[email protected]`, https://github.com/androm3da
14+
15+
## Requirements
16+
17+
This target is cross-compiled. There is no support for `std`. There is no
18+
default allocator, but it's possible to use `alloc` by supplying an allocator.
19+
20+
Document the expectations of binaries built for the target. Do they assume
21+
specific minimum features beyond the baseline of the CPU/environment/etc? What
22+
version of the OS or environment do they expect?
23+
24+
By default, code generated with this target should run on Hexagon DSP hardware.
25+
26+
- `-Ctarget-cpu=hexagonv73` adds support for instructions defined up to Hexagon V73.
27+
28+
Functions marked `extern "C"` use the [Hexagon architecture calling convention](https://tbd).
29+
30+
This target generates PIC ELF binaries.
31+
32+
## Building the target
33+
34+
You can build Rust with support for the target by adding it to the `target`
35+
list in `config.toml`:
36+
37+
```toml
38+
[build]
39+
build-stage = 1
40+
host = ["<target for your host>"]
41+
target = ["<target for your host>", "hexagon-unknown-none-elf"]
42+
43+
[target.hexagon-unknown-none-elf]
44+
45+
cc = "hexagon-unknown-none-elf-clang"
46+
cxx = "hexagon-unknown-none-elf-clang++"
47+
linker = "hexagon-unknown-none-elf-clang"
48+
llvm-libunwind = 'in-tree'
49+
```
50+
51+
Replace `<target for your host>` with `x86_64-unknown-linux-gnu` or whatever
52+
else is appropriate for your host machine.
53+
54+
## Building Rust programs
55+
56+
Rust does not yet ship pre-compiled artifacts for this target. To compile for
57+
this target, you will either need to build Rust with the target enabled (see
58+
"Building the target" above), or build your own copy of `core` by using
59+
`build-std` or similar.
60+
61+
## Testing
62+
63+
Since `hexagon-unknown-none-elf` supports a variety of different environments and does
64+
not support `std`, this target does not support running the Rust test suite.
65+
66+
## Cross-compilation toolchains and C code
67+
68+
This target has been tested using `hexagon-sim` from the Hexagon SDK.
69+
70+
`.cargo/config.toml`:
71+
```toml
72+
[target.hexagon-unknown-none-elf]
73+
74+
cc = "hexagon-unknown-none-elf-clang"
75+
cxx = "hexagon-unknown-none-elf-clang++"
76+
linker = "hexagon-unknown-none-elf-clang"
77+
runner = "hexagon-sim FIXME foo bar baz"
78+
79+
[build]
80+
target = ["hexagon-unknown-none-elf"]
81+
rustflags = "-Ctarget-cpu=hexagonv73"
82+
```
83+
84+
FIXME EXAMPLE

0 commit comments

Comments
 (0)