Skip to content

Commit d9ea17b

Browse files
committed
Add support for hexagon-unknown-qurt target
1 parent 292db4a commit d9ea17b

File tree

9 files changed

+236
-3
lines changed

9 files changed

+236
-3
lines changed

compiler/rustc_target/src/spec/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,7 @@ supported_targets! {
14871487
("mips64el-unknown-linux-muslabi64", mips64el_unknown_linux_muslabi64),
14881488
("hexagon-unknown-linux-musl", hexagon_unknown_linux_musl),
14891489
("hexagon-unknown-none-elf", hexagon_unknown_none_elf),
1490+
("hexagon-unknown-qurt", hexagon_unknown_qurt),
14901491

14911492
("mips-unknown-linux-uclibc", mips_unknown_linux_uclibc),
14921493
("mipsel-unknown-linux-uclibc", mipsel_unknown_linux_uclibc),
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use crate::spec::{Cc, LinkerFlavor, Target, TargetMetadata, TargetOptions, cvs};
2+
3+
pub(crate) fn target() -> Target {
4+
let mut pre_link_args = std::collections::BTreeMap::<LinkerFlavor, Vec<_>>::new();
5+
pre_link_args.entry(LinkerFlavor::Unix(Cc::Yes)).or_default().extend(["-G0".into()]);
6+
7+
Target {
8+
llvm_target: "hexagon-unknown-elf".into(),
9+
metadata: TargetMetadata {
10+
description: Some("Hexagon QuRT".into()),
11+
tier: Some(3),
12+
host_tools: Some(false),
13+
std: Some(false),
14+
},
15+
pointer_width: 32,
16+
data_layout: "\
17+
e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32\
18+
:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32\
19+
:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048\
20+
:2048:2048"
21+
.into(),
22+
arch: "hexagon".into(),
23+
options: TargetOptions {
24+
os: "qurt".into(),
25+
vendor: "unknown".into(),
26+
cpu: "hexagonv69".into(),
27+
linker: Some("rust-lld".into()),
28+
linker_flavor: LinkerFlavor::Unix(Cc::Yes),
29+
exe_suffix: ".elf".into(),
30+
dynamic_linking: true,
31+
executables: true,
32+
families: cvs!["unix"],
33+
has_thread_local: true,
34+
has_rpath: false,
35+
crt_static_default: false,
36+
crt_static_respected: true,
37+
crt_static_allows_dylibs: true,
38+
no_default_libraries: false,
39+
max_atomic_width: Some(32),
40+
features: "-small-data,+hvx-length128b".into(),
41+
c_enum_min_bits: Some(8),
42+
pre_link_args,
43+
..Default::default()
44+
},
45+
}
46+
}

src/bootstrap/src/core/sanity.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub struct Finder {
3434
// Targets can be removed from this list once they are present in the stage0 compiler (usually by updating the beta compiler of the bootstrap).
3535
const STAGE0_MISSING_TARGETS: &[&str] = &[
3636
// just a dummy comment so the list doesn't get onelined
37+
"hexagon-unknown-qurt",
3738
];
3839

3940
/// Minimum version threshold for libstdc++ required when using prebuilt LLVM

src/doc/rustc/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
- [csky-unknown-linux-gnuabiv2\*](platform-support/csky-unknown-linux-gnuabiv2.md)
8888
- [hexagon-unknown-linux-musl](platform-support/hexagon-unknown-linux-musl.md)
8989
- [hexagon-unknown-none-elf](platform-support/hexagon-unknown-none-elf.md)
90+
- [hexagon-unknown-qurt](platform-support/hexagon-unknown-qurt.md)
9091
- [illumos](platform-support/illumos.md)
9192
- [loongarch\*-unknown-linux-\*](platform-support/loongarch-linux.md)
9293
- [loongarch\*-unknown-none\*](platform-support/loongarch-none.md)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ target | std | host | notes
314314
`csky-unknown-linux-gnuabiv2hf` | ✓ | | C-SKY abiv2 Linux, hardfloat (little endian)
315315
[`hexagon-unknown-linux-musl`](platform-support/hexagon-unknown-linux-musl.md) | ✓ | | Hexagon Linux with musl 1.2.3
316316
[`hexagon-unknown-none-elf`](platform-support/hexagon-unknown-none-elf.md)| * | | Bare Hexagon (v60+, HVX)
317+
[`hexagon-unknown-qurt`](platform-support/hexagon-unknown-qurt.md)| * | | Hexagon QuRT
317318
[`i386-apple-ios`](platform-support/apple-ios.md) | ✓ | | 32-bit x86 iOS (Penryn) [^x86_32-floats-return-ABI]
318319
[`i586-unknown-netbsd`](platform-support/netbsd.md) | ✓ | | 32-bit x86 (original Pentium) [^x86_32-floats-x87]
319320
[`i586-unknown-redox`](platform-support/redox.md) | ✓ | | 32-bit x86 Redox OS (PentiumPro) [^x86_32-floats-x87]
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# `hexagon-unknown-qurt`
2+
3+
**Tier: 3**
4+
5+
Rust for Hexagon QuRT (Qualcomm Real-Time OS).
6+
7+
| Target | Description |
8+
| -------------------- | ------------|
9+
| hexagon-unknown-qurt | Hexagon 32-bit QuRT |
10+
11+
## Target maintainers
12+
13+
[@androm3da](https://github.com/androm3da)
14+
15+
## Requirements
16+
17+
This target is cross-compiled. There is support for `std`. The target uses
18+
QuRT's standard library and runtime.
19+
20+
By default, code generated with this target should run on Hexagon DSP hardware
21+
running the QuRT real-time operating system.
22+
23+
- `-Ctarget-cpu=hexagonv69` targets Hexagon V69 architecture (default)
24+
- `-Ctarget-cpu=hexagonv73` adds support for instructions defined up to Hexagon V73
25+
26+
Functions marked `extern "C"` use the [Hexagon architecture calling convention](https://lists.llvm.org/pipermail/llvm-dev/attachments/20190916/21516a52/attachment-0001.pdf).
27+
28+
This target generates position-independent ELF binaries by default, making it
29+
suitable for both static images and dynamic shared objects.
30+
31+
The [Hexagon SDK](https://softwarecenter.qualcomm.com/catalog/item/Hexagon_SDK) is
32+
required for building programs for this target.
33+
34+
## Linking
35+
36+
This target selects `rust-lld` by default. Another option to use is
37+
[eld](https://github.com/qualcomm/eld), which is also provided with
38+
[the opensource hexagon toolchain](https://github.com/quic/toolchain_for_hexagon)
39+
and the Hexagon SDK.
40+
41+
## Building the target
42+
43+
You can build Rust with support for the target by adding it to the `target`
44+
list in `bootstrap.toml`:
45+
46+
```toml
47+
[build]
48+
build-stage = 1
49+
host = ["<target for your host>"]
50+
target = ["<target for your host>", "hexagon-unknown-qurt"]
51+
52+
[target.hexagon-unknown-qurt]
53+
cc = "hexagon-clang"
54+
cxx = "hexagon-clang++"
55+
ranlib = "llvm-ranlib"
56+
ar = "llvm-ar"
57+
llvm-libunwind = 'in-tree'
58+
```
59+
60+
Replace `<target for your host>` with `x86_64-unknown-linux-gnu` or whatever
61+
else is appropriate for your host machine.
62+
63+
## Building Rust programs
64+
65+
Rust does not yet ship pre-compiled artifacts for this target. To compile for
66+
this target, you will either need to build Rust with the target enabled (see
67+
"Building the target" above), or build your own copy of `core` by using
68+
`build-std` or similar.
69+
70+
## Static Image Targeting
71+
72+
For static executables that run directly on QuRT, use the default target
73+
configuration with additional linker flags:
74+
75+
```sh
76+
# Build a static executable for QuRT
77+
cargo rustc --target hexagon-unknown-qurt -- \
78+
-C link-args="-static -nostdlib" \
79+
-C link-args="-L/opt/Hexagon_SDK/6.3.0.0/rtos/qurt/computev69/lib" \
80+
-C link-args="-lqurt -lc"
81+
```
82+
83+
This approach is suitable for:
84+
- Standalone QuRT applications
85+
- System-level services
86+
- Boot-time initialization code
87+
- Applications that need deterministic memory layout
88+
89+
## User-Loadable Shared Object Targeting
90+
91+
For shared libraries that can be dynamically loaded by QuRT applications:
92+
93+
```sh
94+
# Build a shared object for QuRT
95+
cargo rustc --target hexagon-unknown-qurt \
96+
--crate-type=cdylib -- \
97+
-C link-args="-shared -fPIC" \
98+
-C link-args="-L/opt/Hexagon_SDK/6.3.0.0/rtos/qurt/computev69/lib"
99+
```
100+
101+
This approach is suitable for:
102+
- Plugin architectures
103+
- Runtime-loadable modules
104+
- Libraries shared between multiple applications
105+
- Code that needs to be updated without system restart
106+
107+
## Configuration Options
108+
109+
The target can be customized for different use cases:
110+
111+
### For Static Images
112+
```toml
113+
# In .cargo/config.toml
114+
[target.hexagon-unknown-qurt]
115+
rustflags = [
116+
"-C", "link-args=-static",
117+
"-C", "link-args=-nostdlib",
118+
"-C", "target-feature=-small-data"
119+
]
120+
```
121+
122+
### For Shared Objects
123+
```toml
124+
# In .cargo/config.toml
125+
[target.hexagon-unknown-qurt]
126+
rustflags = [
127+
"-C", "link-args=-shared",
128+
"-C", "link-args=-fPIC",
129+
"-C", "relocation-model=pic"
130+
]
131+
```
132+
133+
## Testing
134+
135+
Since `hexagon-unknown-qurt` requires the QuRT runtime environment, testing requires
136+
either:
137+
- Hexagon hardware with QuRT
138+
- `hexagon-sim`
139+
- QEMU (`qemu-system-hexagon`)
140+
141+
## Cross-compilation toolchains and C code
142+
143+
This target requires the proprietary [Hexagon SDK toolchain for C interoperability](https://softwarecenter.qualcomm.com/catalog/item/Hexagon_SDK):
144+
145+
- **Sample SDK Path**: `/opt/Hexagon_SDK/6.3.0.0/`
146+
- **Toolchain**: Use `hexagon-clang` from the Hexagon SDK
147+
- **Libraries**: Link against QuRT system libraries as needed
148+
149+
### C Interoperability Example
150+
151+
```rust
152+
// lib.rs
153+
#![no_std]
154+
extern crate std;
155+
156+
#[unsafe(no_mangle)]
157+
pub extern "C" fn rust_function() -> i32 {
158+
// Your Rust code here
159+
42
160+
}
161+
162+
fn main() {
163+
// Example usage
164+
let result = rust_function();
165+
assert_eq!(result, 42);
166+
}
167+
```
168+
169+
```c
170+
// wrapper.c
171+
extern int rust_function(void);
172+
173+
int main() {
174+
return rust_function();
175+
}
176+
```
177+
178+
The target supports both static linking for standalone applications and dynamic
179+
linking for modular architectures, making it flexible for various QuRT
180+
deployment scenarios.

tests/assembly-llvm/targets/targets-elf.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@
232232
//@ revisions: hexagon_unknown_none_elf
233233
//@ [hexagon_unknown_none_elf] compile-flags: --target hexagon-unknown-none-elf
234234
//@ [hexagon_unknown_none_elf] needs-llvm-components: hexagon
235+
//@ revisions: hexagon_unknown_qurt
236+
//@ [hexagon_unknown_qurt] compile-flags: --target hexagon-unknown-qurt
237+
//@ [hexagon_unknown_qurt] needs-llvm-components: hexagon
235238
//@ revisions: i686_pc_nto_qnx700
236239
//@ [i686_pc_nto_qnx700] compile-flags: --target i686-pc-nto-qnx700
237240
//@ [i686_pc_nto_qnx700] needs-llvm-components: x86

tests/ui/check-cfg/cfg-crate-features.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ warning: unexpected `cfg` condition value: `does_not_exist`
2424
LL | #![cfg(not(target(os = "does_not_exist")))]
2525
| ^^^^^^^^^^^^^^^^^^^^^
2626
|
27-
= note: expected values for `target_os` are: `aix`, `amdhsa`, `android`, `cuda`, `cygwin`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `lynxos178`, `macos`, `managarm`, `motor`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `psp`, `psx`, `redox`, `rtems`, `solaris`, `solid_asp3`, `teeos`, and `trusty` and 12 more
27+
= note: expected values for `target_os` are: `aix`, `amdhsa`, `android`, `cuda`, `cygwin`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `lynxos178`, `macos`, `managarm`, `motor`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `psp`, `psx`, `qurt`, `redox`, `rtems`, `solaris`, `solid_asp3`, and `teeos` and 13 more
2828
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
2929
= note: `#[warn(unexpected_cfgs)]` on by default
3030

tests/ui/check-cfg/well-known-values.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
201201
LL | target_os = "_UNEXPECTED_VALUE",
202202
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
203203
|
204-
= note: expected values for `target_os` are: `aix`, `amdhsa`, `android`, `cuda`, `cygwin`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `lynxos178`, `macos`, `managarm`, `motor`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `psp`, `psx`, `redox`, `rtems`, `solaris`, `solid_asp3`, `teeos`, `trusty`, `tvos`, `uefi`, `unknown`, `vexos`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, and `zkvm`
204+
= note: expected values for `target_os` are: `aix`, `amdhsa`, `android`, `cuda`, `cygwin`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `lynxos178`, `macos`, `managarm`, `motor`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `psp`, `psx`, `qurt`, `redox`, `rtems`, `solaris`, `solid_asp3`, `teeos`, `trusty`, `tvos`, `uefi`, `unknown`, `vexos`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, and `zkvm`
205205
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
206206

207207
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
@@ -274,7 +274,7 @@ LL | #[cfg(target_os = "linuz")] // testing that we suggest `linux`
274274
| |
275275
| help: there is a expected value with a similar name: `"linux"`
276276
|
277-
= note: expected values for `target_os` are: `aix`, `amdhsa`, `android`, `cuda`, `cygwin`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `lynxos178`, `macos`, `managarm`, `motor`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `psp`, `psx`, `redox`, `rtems`, `solaris`, `solid_asp3`, `teeos`, `trusty`, `tvos`, `uefi`, `unknown`, `vexos`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, and `zkvm`
277+
= note: expected values for `target_os` are: `aix`, `amdhsa`, `android`, `cuda`, `cygwin`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `lynxos178`, `macos`, `managarm`, `motor`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `psp`, `psx`, `qurt`, `redox`, `rtems`, `solaris`, `solid_asp3`, `teeos`, `trusty`, `tvos`, `uefi`, `unknown`, `vexos`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, and `zkvm`
278278
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
279279

280280
warning: 28 warnings emitted

0 commit comments

Comments
 (0)