Skip to content

Commit 5489691

Browse files
committed
draft: Add support for hexagon-unknown-none-elf as target
Still TODO: document usage details for new target
1 parent 4b85902 commit 5489691

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use crate::spec::{Cc, LinkerFlavor, Lld, PanicStrategy, RelocModel, 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+
linker: Some("clang".into()),
19+
linker_flavor: LinkerFlavor::Gnu(Cc::Yes, Lld::No),
20+
relocation_model: RelocModel::Pic,
21+
position_independent_executables: true,
22+
panic_strategy: PanicStrategy::Abort,
23+
features: "-small-data,+hvx-length128b".into(),
24+
has_thread_local: true,
25+
max_atomic_width: Some(32),
26+
emit_debug_gdb_scripts: false,
27+
c_enum_min_bits: Some(8),
28+
..Default::default()
29+
},
30+
}
31+
}

compiler/rustc_target/src/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,7 @@ supported_targets! {
15281528
("mips64-unknown-linux-muslabi64", mips64_unknown_linux_muslabi64),
15291529
("mips64el-unknown-linux-muslabi64", mips64el_unknown_linux_muslabi64),
15301530
("hexagon-unknown-linux-musl", hexagon_unknown_linux_musl),
1531+
("hexagon-unknown-none-elf", hexagon_unknown_none_elf),
15311532

15321533
("mips-unknown-linux-uclibc", mips_unknown_linux_uclibc),
15331534
("mipsel-unknown-linux-uclibc", mipsel_unknown_linux_uclibc),

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)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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 v60 or later, HVX |
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+
By default, code generated with this target should run on Hexagon DSP
21+
hardware, v60 or later.
22+
23+
- `-Ctarget-cpu=hexagonv73` adds support for instructions defined up to Hexagon V73.
24+
25+
Functions marked `extern "C"` use the
26+
[Hexagon architecture calling convention](https://lists.llvm.org/pipermail/llvm-dev/attachments/20190916/21516a52/attachment-0001.pdf).
27+
28+
This target generates PIC ELF binaries.
29+
30+
## Building the target
31+
32+
You can build Rust with support for the target by adding it to the `target`
33+
list in `config.toml`:
34+
35+
```toml
36+
[build]
37+
build-stage = 1
38+
host = ["<target for your host>"]
39+
target = ["<target for your host>", "hexagon-unknown-none-elf"]
40+
41+
[target.hexagon-unknown-none-elf]
42+
43+
cc = "hexagon-unknown-none-elf-clang"
44+
cxx = "hexagon-unknown-none-elf-clang++"
45+
linker = "hexagon-unknown-none-elf-clang"
46+
llvm-libunwind = 'in-tree'
47+
```
48+
49+
Replace `<target for your host>` with `x86_64-unknown-linux-gnu` or whatever
50+
else is appropriate for your host machine.
51+
52+
## Building Rust programs
53+
54+
Rust does not yet ship pre-compiled artifacts for this target. To compile for
55+
this target, you will either need to build Rust with the target enabled (see
56+
"Building the target" above), or build your own copy of `core` by using
57+
`build-std` or similar.
58+
59+
## Testing
60+
61+
Since `hexagon-unknown-none-elf` supports a variety of different environments
62+
and does not support `std`, this target does not support running the Rust
63+
test suite.
64+
65+
## Cross-compilation toolchains and C code
66+
67+
This target has been tested using `hexagon-sim` from the Hexagon SDK.
68+
69+
`.cargo/config.toml`:
70+
```toml
71+
[target.hexagon-unknown-none-elf]
72+
73+
cc = "hexagon-unknown-none-elf-clang"
74+
cxx = "hexagon-unknown-none-elf-clang++"
75+
linker = "hexagon-unknown-none-elf-clang"
76+
runner = "hexagon-sim FIXME TBD details"
77+
78+
[build]
79+
target = ["hexagon-unknown-none-elf"]
80+
rustflags = "-Ctarget-cpu=hexagonv73"
81+
```
82+
83+
FIXME TBD details

0 commit comments

Comments
 (0)