-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Add support for hexagon-unknown-qurt target #147173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
androm3da
wants to merge
8
commits into
rust-lang:master
Choose a base branch
from
androm3da:bcain/hexagon_qurt
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d51f18f
Add support for hexagon-unknown-qurt target
androm3da 16aea11
Changes from review
androm3da 9d114dc
format hexagon_unknown_qurt.rs
androm3da ac1485f
Rename hexagon-unknown-qurt => hexagon-qurt
androm3da aa69d39
Fix test failure in tests/ui/
androm3da 52a6b8d
Update compiler/rustc_target/src/spec/targets/hexagon_qurt.rs
androm3da 9b20428
fixes from review
androm3da 8ab88d1
fix CI failures
androm3da File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use crate::spec::{Cc, LinkerFlavor, Target, TargetMetadata, TargetOptions, cvs}; | ||
|
||
pub(crate) fn target() -> Target { | ||
let mut pre_link_args = std::collections::BTreeMap::<LinkerFlavor, Vec<_>>::new(); | ||
pre_link_args.entry(LinkerFlavor::Unix(Cc::Yes)).or_default().extend(["-G0".into()]); | ||
|
||
Target { | ||
llvm_target: "hexagon-unknown-elf".into(), | ||
metadata: TargetMetadata { | ||
description: Some("Hexagon QuRT".into()), | ||
tier: Some(3), | ||
host_tools: Some(false), | ||
std: Some(false), | ||
}, | ||
pointer_width: 32, | ||
data_layout: "\ | ||
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 { | ||
os: "qurt".into(), | ||
vendor: "unknown".into(), | ||
cpu: "hexagonv69".into(), | ||
linker: Some("rust-lld".into()), | ||
linker_flavor: LinkerFlavor::Unix(Cc::Yes), | ||
exe_suffix: ".elf".into(), | ||
dynamic_linking: true, | ||
executables: true, | ||
families: cvs!["unix"], | ||
has_thread_local: true, | ||
has_rpath: false, | ||
crt_static_default: false, | ||
crt_static_respected: true, | ||
crt_static_allows_dylibs: true, | ||
no_default_libraries: false, | ||
max_atomic_width: Some(32), | ||
features: "-small-data,+hvx-length128b".into(), | ||
c_enum_min_bits: Some(8), | ||
pre_link_args, | ||
..Default::default() | ||
}, | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletions
174
src/doc/rustc/src/platform-support/hexagon-unknown-qurt.md
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
# `hexagon-qurt` | ||
|
||
**Tier: 3** | ||
|
||
Rust for Hexagon QuRT (Qualcomm Real-Time OS). | ||
|
||
| Target | Description | | ||
| -------------------- | ------------| | ||
| hexagon-qurt | Hexagon 32-bit QuRT | | ||
|
||
## Target maintainers | ||
|
||
[@androm3da](https://github.com/androm3da) | ||
|
||
## Requirements | ||
|
||
This target is cross-compiled. There is support for `std`. The target uses | ||
QuRT's standard library and runtime. | ||
|
||
By default, code generated with this target should run on Hexagon DSP hardware | ||
running the QuRT real-time operating system. | ||
|
||
- `-Ctarget-cpu=hexagonv69` targets Hexagon V69 architecture (default) | ||
- `-Ctarget-cpu=hexagonv73` adds support for instructions defined up to Hexagon V73 | ||
|
||
Functions marked `extern "C"` use the [Hexagon architecture calling convention](https://lists.llvm.org/pipermail/llvm-dev/attachments/20190916/21516a52/attachment-0001.pdf). | ||
|
||
This target generates position-independent ELF binaries by default, making it | ||
suitable for both static images and dynamic shared objects. | ||
|
||
The [Hexagon SDK](https://softwarecenter.qualcomm.com/catalog/item/Hexagon_SDK) is | ||
required for building programs for this target. | ||
|
||
## Linking | ||
|
||
This target selects `rust-lld` by default. Another option to use is | ||
[eld](https://github.com/qualcomm/eld), which is also provided with | ||
[the opensource hexagon toolchain](https://github.com/quic/toolchain_for_hexagon) | ||
and the Hexagon SDK. | ||
|
||
## Building the target | ||
|
||
You can build Rust with support for the target by adding it to the `target` | ||
list in `bootstrap.toml`: | ||
|
||
```toml | ||
[build] | ||
build-stage = 1 | ||
host = ["<target for your host>"] | ||
target = ["<target for your host>", "hexagon-qurt"] | ||
|
||
[target.hexagon-qurt] | ||
cc = "hexagon-clang" | ||
cxx = "hexagon-clang++" | ||
ranlib = "llvm-ranlib" | ||
ar = "llvm-ar" | ||
llvm-libunwind = 'in-tree' | ||
``` | ||
|
||
Replace `<target for your host>` 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. | ||
|
||
## Static Image Targeting | ||
|
||
For static executables that run directly on QuRT, use the default target | ||
configuration with additional linker flags: | ||
|
||
```sh | ||
# Build a static executable for QuRT | ||
cargo rustc --target hexagon-qurt -- \ | ||
-C link-args="-static -nostdlib" \ | ||
-C link-args="-L/opt/Hexagon_SDK/6.3.0.0/rtos/qurt/computev69/lib" \ | ||
-C link-args="-lqurt -lc" | ||
``` | ||
|
||
This approach is suitable for: | ||
- Standalone QuRT applications | ||
- System-level services | ||
- Boot-time initialization code | ||
- Applications that need deterministic memory layout | ||
|
||
## User-Loadable Shared Object Targeting | ||
|
||
For shared libraries that can be dynamically loaded by QuRT applications: | ||
|
||
```sh | ||
# Build a shared object for QuRT | ||
cargo rustc --target hexagon-qurt \ | ||
--crate-type=cdylib -- \ | ||
-C link-args="-shared -fPIC" \ | ||
-C link-args="-L/opt/Hexagon_SDK/6.3.0.0/rtos/qurt/computev69/lib" | ||
``` | ||
|
||
This approach is suitable for: | ||
- Plugin architectures | ||
- Runtime-loadable modules | ||
- Libraries shared between multiple applications | ||
- Code that needs to be updated without system restart | ||
|
||
## Configuration Options | ||
|
||
The target can be customized for different use cases: | ||
|
||
### For Static Images | ||
```toml | ||
# In .cargo/config.toml | ||
[target.hexagon-qurt] | ||
rustflags = [ | ||
"-C", "link-args=-static", | ||
"-C", "link-args=-nostdlib", | ||
"-C", "target-feature=-small-data" | ||
] | ||
``` | ||
|
||
### For Shared Objects | ||
```toml | ||
# In .cargo/config.toml | ||
[target.hexagon-qurt] | ||
rustflags = [ | ||
"-C", "link-args=-shared", | ||
"-C", "link-args=-fPIC", | ||
"-C", "relocation-model=pic" | ||
] | ||
``` | ||
|
||
## Testing | ||
|
||
Since `hexagon-qurt` requires the QuRT runtime environment, testing requires | ||
either: | ||
- Hexagon hardware with QuRT | ||
- `hexagon-sim` | ||
- QEMU (`qemu-system-hexagon`) | ||
|
||
## Cross-compilation toolchains and C code | ||
|
||
This target requires the proprietary [Hexagon SDK toolchain for C interoperability](https://softwarecenter.qualcomm.com/catalog/item/Hexagon_SDK): | ||
|
||
- **Sample SDK Path**: `/opt/Hexagon_SDK/6.3.0.0/` | ||
- **Toolchain**: Use `hexagon-clang` from the Hexagon SDK | ||
- **Libraries**: Link against QuRT system libraries as needed | ||
|
||
### C Interoperability Example | ||
|
||
```rust | ||
// lib.rs | ||
#![no_std] | ||
extern crate std; | ||
|
||
#[unsafe(no_mangle)] | ||
pub extern "C" fn rust_function() -> i32 { | ||
// Your Rust code here | ||
42 | ||
} | ||
``` | ||
|
||
```c | ||
// wrapper.c | ||
extern int rust_function(void); | ||
|
||
int main() { | ||
return rust_function(); | ||
} | ||
``` | ||
|
||
The target supports both static linking for standalone applications and dynamic | ||
linking for modular architectures, making it flexible for various QuRT | ||
deployment scenarios. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.