Update hexagon target linker configurations

* hexagon-unknown-qurt: Use hexagon-clang from Hexagon SDK instead of
rust-lld
* hexagon-unknown-linux-musl: Use hexagon-unknown-linux-musl-clang from
the open source toolchain instead of rust-lld.
* hexagon-unknown-none-elf: Keep rust-lld but fix the linker flavor.

rust-lld is appropriate for a baremetal target but for traditional
programs that depend on libc, using clang's driver makes the most
sense.
This commit is contained in:
Brian Cain 2026-01-23 15:00:11 -06:00
parent d222ddc4d9
commit f5cdd5d86e
5 changed files with 32 additions and 19 deletions

View file

@ -1,4 +1,4 @@
use crate::spec::{Arch, Cc, LinkerFlavor, Target, TargetMetadata, base};
use crate::spec::{Arch, Cc, LinkerFlavor, Lld, Target, TargetMetadata, base};
pub(crate) fn target() -> Target {
let mut base = base::linux_musl::opts();
@ -8,8 +8,8 @@ pub(crate) fn target() -> Target {
base.features = "-small-data,+hvx-length128b".into();
base.has_rpath = true;
base.linker = Some("rust-lld".into());
base.linker_flavor = LinkerFlavor::Unix(Cc::Yes);
base.linker = Some("hexagon-unknown-linux-musl-clang".into());
base.linker_flavor = LinkerFlavor::Gnu(Cc::Yes, Lld::No);
base.c_enum_min_bits = Some(8);

View file

@ -1,4 +1,6 @@
use crate::spec::{Arch, PanicStrategy, Target, TargetMetadata, TargetOptions};
use crate::spec::{
Arch, Cc, LinkerFlavor, Lld, PanicStrategy, Target, TargetMetadata, TargetOptions,
};
pub(crate) fn target() -> Target {
Target {
@ -28,6 +30,7 @@ pub(crate) fn target() -> Target {
emit_debug_gdb_scripts: false,
c_enum_min_bits: Some(8),
linker: Some("rust-lld".into()),
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
..Default::default()
},
}

View file

@ -24,8 +24,8 @@ pub(crate) fn target() -> Target {
os: Os::Qurt,
vendor: "unknown".into(),
cpu: "hexagonv69".into(),
linker: Some("rust-lld".into()),
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
linker: Some("hexagon-clang".into()),
linker_flavor: LinkerFlavor::Gnu(Cc::Yes, Lld::No),
exe_suffix: ".elf".into(),
dynamic_linking: true,
executables: true,

View file

@ -36,14 +36,19 @@ Also included in that toolchain is the C library that can be used when creating
dynamically linked executables.
```text
# /opt/clang+llvm-18.1.0-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/bin/qemu-hexagon -L /opt/clang+llvm-18.1.0-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/target/hexagon-unknown-linux-musl/usr/ ./hello
# /opt/clang+llvm-VERSION-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/bin/qemu-hexagon -L /opt/clang+llvm-VERSION-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/target/hexagon-unknown-linux-musl/usr/ ./hello
```
## 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 and the Hexagon SDK.
This target uses `hexagon-unknown-linux-musl-clang` as the default linker.
The linker is available from [the opensource hexagon toolchain](https://github.com/quic/toolchain_for_hexagon/releases)
at paths like `/opt/clang+llvm-21.1.8-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/bin/hexagon-unknown-linux-musl-clang`.
Alternative linkers include:
- [eld](https://github.com/qualcomm/eld), which is provided with
the opensource hexagon toolchain and the Hexagon SDK
- `rust-lld` can be used by specifying `-C linker=rust-lld`
## Building the target
Because it is Tier 3, rust does not yet ship pre-compiled artifacts for this
@ -63,9 +68,9 @@ cxx = "hexagon-unknown-linux-musl-clang++"
linker = "hexagon-unknown-linux-musl-clang"
ar = "hexagon-unknown-linux-musl-ar"
ranlib = "hexagon-unknown-linux-musl-ranlib"
musl-root = "/opt/clang+llvm-18.1.0-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/target/hexagon-unknown-linux-musl/usr"
musl-root = "/opt/clang+llvm-VERSION-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/target/hexagon-unknown-linux-musl/usr"
llvm-libunwind = 'in-tree'
qemu-rootfs = "/opt/clang+llvm-18.1.0-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/target/hexagon-unknown-linux-musl/usr"
qemu-rootfs = "/opt/clang+llvm-VERSION-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/target/hexagon-unknown-linux-musl/usr"
```
@ -88,7 +93,7 @@ target = "hexagon-unknown-linux-musl"
[target.hexagon-unknown-linux-musl]
linker = "hexagon-unknown-linux-musl-clang"
ar = "hexagon-unknown-linux-musl-ar"
runner = "qemu-hexagon -L /opt/clang+llvm-18.1.0-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/target/hexagon-unknown-linux-musl/usr"
runner = "qemu-hexagon -L /opt/clang+llvm-VERSION-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/target/hexagon-unknown-linux-musl/usr"
```
Edit the "runner" in `.cargo/config` to point to the path to your toolchain's
@ -96,13 +101,13 @@ C library.
```text
...
runner = "qemu-hexagon -L /path/to/my/inst/clang+llvm-18.1.0-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/target/hexagon-unknown-linux-musl/usr"
runner = "qemu-hexagon -L /path/to/my/inst/clang+llvm-VERSION-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/target/hexagon-unknown-linux-musl/usr"
...
```
Build/run your rust program with `qemu-hexagon` in your `PATH`:
```text
export PATH=/path/to/my/inst/clang+llvm-18.1.0-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/bin/:$PATH
export PATH=/path/to/my/inst/clang+llvm-VERSION-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/bin/:$PATH
cargo run -Zbuild-std -Zbuild-std-features=llvm-libunwind
```

View file

@ -33,10 +33,15 @@ 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.
This target uses `hexagon-clang` from the Hexagon SDK as the default linker.
The linker is available at paths like
`/opt/Hexagon_SDK/6.4.0.2/tools/HEXAGON_Tools/19.0.04/Tools/bin/hexagon-clang`.
Alternative linkers include:
- [eld](https://github.com/qualcomm/eld), which is provided with both
[the opensource hexagon toolchain](https://github.com/quic/toolchain_for_hexagon)
and the Hexagon SDK
- `rust-lld` can be used by specifying `-C linker=rust-lld`
## Building the target