Skip to content

Commit

Permalink
[Driver] Allow XRay for more architectures on ELF systems
Browse files Browse the repository at this point in the history
Codegen OS-agnostic for ELF and the runtime is mostly OS-agnostic. It
seems unnecessary to make restriction.

While here, rewrite test/Driver/XRay/xray-instrument*.c to be more conventional:
specify --target= explicitly instead of relying on the configured default target
(which needs `REQUIRES:`).

I am not sure enumerating every supported architecture is useful, so we just test a few.
  • Loading branch information
MaskRay committed Jun 21, 2023
1 parent 08aeb7c commit e105141
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 29 deletions.
22 changes: 6 additions & 16 deletions clang/lib/Driver/XRayArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
options::OPT_fno_xray_instrument, false))
return;
XRayInstrument = Args.getLastArg(options::OPT_fxray_instrument);
if (Triple.getOS() == llvm::Triple::Linux) {
if (Triple.isMacOSX()) {
if (Triple.getArch() != llvm::Triple::x86_64) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< XRayInstrument->getSpelling() << Triple.str();
}
} else if (Triple.isOSBinFormatELF()) {
switch (Triple.getArch()) {
case llvm::Triple::x86_64:
case llvm::Triple::arm:
Expand All @@ -47,21 +52,6 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< XRayInstrument->getSpelling() << Triple.str();
}
} else if (Triple.isOSFreeBSD() || Triple.isOSOpenBSD() ||
Triple.isOSNetBSD() || Triple.isMacOSX()) {
if (Triple.getArch() != llvm::Triple::x86_64) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< XRayInstrument->getSpelling() << Triple.str();
}
} else if (Triple.getOS() == llvm::Triple::Fuchsia) {
switch (Triple.getArch()) {
case llvm::Triple::x86_64:
case llvm::Triple::aarch64:
break;
default:
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< XRayInstrument->getSpelling() << Triple.str();
}
} else {
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< XRayInstrument->getSpelling() << Triple.str();
Expand Down
5 changes: 0 additions & 5 deletions clang/test/Driver/XRay/xray-instrument-cpu.c

This file was deleted.

4 changes: 0 additions & 4 deletions clang/test/Driver/XRay/xray-instrument-macos.c

This file was deleted.

4 changes: 0 additions & 4 deletions clang/test/Driver/XRay/xray-instrument-os.c

This file was deleted.

8 changes: 8 additions & 0 deletions clang/test/Driver/XRay/xray-instrument.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %clang -### --target=aarch64-pc-freebsd -fxray-instrument -c %s -o /dev/null 2>&1 | FileCheck %s
// RUN: %clang -### --target=x86_64-apple-darwin -fxray-instrument -c %s -o /dev/null 2>&1 | FileCheck %s
// RUN: %clang -### --target=x86_64-pc-windows -fxray-instrument -c %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR

// CHECK: "-cc1" {{.*}}"-fxray-instrument"
// ERR: error: unsupported option '-fxray-instrument' for target

typedef int a;

0 comments on commit e105141

Please sign in to comment.