Skip to content

Commit 8eb7f8f

Browse files
authored
Rollup merge of rust-lang#140790 - quininer:mac-xray, r=jieyouxu
Enable xray support for Mac rust-lang#102921 Upstream has supported Mac for a while, let's enable it. I've tested it on M4 and it generates nop sled correctly. * https://maskray.me/blog/2023-06-18-port-llvm-xray-to-apple-systems * https://github.com/llvm/llvm-project/blob/llvmorg-20.1.4/clang/lib/Driver/XRayArgs.cpp#L31
2 parents 3e674b0 + 4a619fb commit 8eb7f8f

File tree

6 files changed

+44
-10
lines changed

6 files changed

+44
-10
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub(crate) fn target() -> Target {
2222
max_atomic_width: Some(128),
2323
// FIXME: The leak sanitizer currently fails the tests, see #88132.
2424
supported_sanitizers: SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD,
25+
supports_xray: true,
2526
..opts
2627
},
2728
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub(crate) fn target() -> Target {
2323
| SanitizerSet::CFI
2424
| SanitizerSet::LEAK
2525
| SanitizerSet::THREAD,
26+
supports_xray: true,
2627
..opts
2728
},
2829
}

tests/assembly/x86_64-xray.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ assembly-output: emit-asm
2+
//@ compile-flags: --crate-type lib -Zinstrument-xray=always -C llvm-args=-x86-asm-syntax=intel
3+
//@ only-x86_64
4+
//@ ignore-sgx
5+
6+
// CHECK-LABEL: xray_func:
7+
#[no_mangle]
8+
pub fn xray_func() {
9+
// CHECK: nop word ptr [rax + rax + 512]
10+
11+
std::hint::black_box(());
12+
13+
// CHECK: ret
14+
// CHECK-NEXT: nop word ptr cs:[rax + rax + 512]
15+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//@ only-nightly (flag is still unstable)
2+
//@ needs-xray
3+
4+
//@ revisions: unsupported
5+
//@[unsupported] needs-llvm-components: x86
6+
//@[unsupported] compile-flags: -Z instrument-xray --target=x86_64-pc-windows-msvc
7+
8+
//@ revisions: x86_64-linux
9+
//@[x86_64-linux] needs-llvm-components: x86
10+
//@[x86_64-linux] compile-flags: -Z instrument-xray --target=x86_64-unknown-linux-gnu
11+
//@[x86_64-linux] check-pass
12+
13+
//@ revisions: x86_64-darwin
14+
//@[x86_64-darwin] needs-llvm-components: x86
15+
//@[x86_64-darwin] compile-flags: -Z instrument-xray --target=x86_64-apple-darwin
16+
//@[x86_64-darwin] check-pass
17+
18+
//@ revisions: aarch64-darwin
19+
//@[aarch64-darwin] needs-llvm-components: aarch64
20+
//@[aarch64-darwin] compile-flags: -Z instrument-xray --target=aarch64-apple-darwin
21+
//@[aarch64-darwin] check-pass
22+
23+
#![feature(no_core)]
24+
#![no_core]
25+
#![no_main]
26+
27+
//[unsupported]~? ERROR XRay instrumentation is not supported for this target

tests/ui/instrument-xray/target-not-supported.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)