Skip to content

Commit 3561dc9

Browse files
committed
Emit an error if -Z instrument-xray is not supported
This is somewhat important because LLVM enables the pass based on target architecture, but support by the target OS also matters. For example, XRay attributes are processed by codegen for macOS targets, but Apple linker fails to process relocations in XRay data sections, so the feature as a whole is not supported there for the time being.
1 parent 8e49c84 commit 3561dc9

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

compiler/rustc_error_messages/locales/en-US/session.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ session_profile_sample_use_file_does_not_exist = file `{$path}` passed to `-C pr
2525
2626
session_target_requires_unwind_tables = target requires unwind tables, they cannot be disabled with `-C force-unwind-tables=no`
2727
28+
session_instrumentation_not_supported = {$us} instrumentation is not supported for this target
29+
2830
session_sanitizer_not_supported = {$us} sanitizer is not supported for this target
2931
3032
session_sanitizers_not_supported = {$us} sanitizers are not supported for this target

compiler/rustc_session/src/errors.rs

+6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ pub struct ProfileSampleUseFileDoesNotExist<'a> {
7171
#[diag(session_target_requires_unwind_tables)]
7272
pub struct TargetRequiresUnwindTables;
7373

74+
#[derive(Diagnostic)]
75+
#[diag(session_instrumentation_not_supported)]
76+
pub struct InstrumentationNotSupported {
77+
pub us: String,
78+
}
79+
7480
#[derive(Diagnostic)]
7581
#[diag(session_sanitizer_not_supported)]
7682
pub struct SanitizerNotSupported {

compiler/rustc_session/src/session.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,10 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
15891589
{
15901590
sess.emit_err(errors::SplitDebugInfoUnstablePlatform { debuginfo: sess.split_debuginfo() });
15911591
}
1592+
1593+
if sess.opts.unstable_opts.instrument_xray.is_some() && !sess.target.options.supports_xray {
1594+
sess.emit_err(errors::InstrumentationNotSupported { us: "XRay".to_string() });
1595+
}
15921596
}
15931597

15941598
/// Holds data on the current incremental compilation session, if there is one.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Verifies that `-Z instrument-xray` cannot be used with unsupported targets,
2+
//
3+
// needs-llvm-components: x86
4+
// compile-flags: -Z instrument-xray --target x86_64-apple-darwin
5+
// error-pattern: error: XRay instrumentation is not supported for this target
6+
7+
#![feature(no_core)]
8+
#![no_core]
9+
#![no_main]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: XRay instrumentation is not supported for this target
2+
3+
error: aborting due to previous error
4+

0 commit comments

Comments
 (0)