Skip to content

Commit 93e516b

Browse files
Rollup merge of #148666 - odlot:master, r=wesleywiser
Add support for xray in aarch64 unknown none targets I am currently working on an embedded project and use the target `aarch64-unknown-none`, which I want to profile. I found the following compiler flag `-Z instrument-xray` (https://doc.rust-lang.org/unstable-book/compiler-flags/instrument-xray.html) available and I locally built a toolchain that sets the `supports_xray: true` option in `TargetOptions` for `compiler/rustc_target/src/spec/targets/aarch64_unknown_none.rs`. Using this toolchain in `rustup` I am able to use the instrumentation pass and I verified that the disassembly looks as what I want. I understand that it isn't available upstream while being supported due to the separate runtime library which has to be linked (e.g., https://www.llvm.org/docs/XRay.html#xray-runtime-library), which is not available for `aarch64-unknown-none`. I argue that someone who cross-compiles for `aarch64-unknown-none` would be okay with writing a separate runtime library themselves, which I intend to do. As far as I understood it is not necessarily required to have a runtime library at this point, i.e., the user of this API should link it, e.g., from their `build.rs` file using `cargo::rustc-link-lib=LIB` if there is an XRay LIB available for the respective target, e.g., `clang+llvm-19.1.1-aarch64-linux-gnu/lib/clang/19/lib/aarch64-unknown-linux-gnu/libclang_rt.xray-fdr.a` (which afaik there isn't for `aarch64-unknown-none`) and do "configuration as code" of XRay's options. It should not be part of the compiler, because the instrumentation and the runtime library are completely decoupled. One can modify the instrumented code by the compiler pass however one wants to, this again pushes me into the direction of telling the developer to bring his own runtime library. I would like to bring my change that enables this instrumentation back into upstream to facilitate my developer experience.
2 parents c8cb78d + 743c6a6 commit 93e516b

3 files changed

Lines changed: 3 additions & 0 deletions

File tree

compiler/rustc_target/src/spec/targets/aarch64_unknown_none.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub(crate) fn target() -> Target {
3030
stack_probes: StackProbeType::Inline,
3131
panic_strategy: PanicStrategy::Abort,
3232
default_uwtable: true,
33+
supports_xray: true,
3334
..Default::default()
3435
};
3536
Target {

compiler/rustc_target/src/spec/targets/aarch64_unknown_none_softfloat.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub(crate) fn target() -> Target {
2727
stack_probes: StackProbeType::Inline,
2828
panic_strategy: PanicStrategy::Abort,
2929
default_uwtable: true,
30+
supports_xray: true,
3031
..Default::default()
3132
};
3233
Target {

src/doc/unstable-book/src/compiler-flags/instrument-xray.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ which on their own don't do anything useful.
3737
In order to actually trace the functions,
3838
you will need to link a separate runtime library of your choice,
3939
such as Clang's [XRay Runtime Library](https://www.llvm.org/docs/XRay.html#xray-runtime-library).
40+
On targets where such a runtime is not available but instrumentation is supported, you must supply and link your own runtime library.

0 commit comments

Comments
 (0)