diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index 9cd911e7fce14..c45fb132685c2 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -130,8 +130,8 @@ CODEGENOPT(XRayAlwaysEmitTypedEvents , 1, 0) ///< Set when -fxray-ignore-loops is enabled. CODEGENOPT(XRayIgnoreLoops , 1, 0) -///< Set with -fno-xray-function-index to omit the index section. -CODEGENOPT(XRayOmitFunctionIndex , 1, 0) +///< Emit the XRay function index section. +CODEGENOPT(XRayFunctionIndex , 1, 1) ///< Set the minimum number of instructions in a function to determine selective diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 3a8b03c4159d1..abb3254188aff 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -2216,10 +2216,10 @@ defm xray_ignore_loops : BoolFOption<"xray-ignore-loops", NegFlag>; defm xray_function_index : BoolFOption<"xray-function-index", - CodeGenOpts<"XRayOmitFunctionIndex">, DefaultTrue, - NegFlag, - PosFlag>; + CodeGenOpts<"XRayFunctionIndex">, DefaultFalse, + PosFlag, + NegFlag>; def fxray_link_deps : Flag<["-"], "fxray-link-deps">, Group, Flags<[CC1Option]>, diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index c736f38e01f65..73cd4a62f5d3e 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -429,7 +429,7 @@ static bool initTargetOptions(DiagnosticsEngine &Diags, Options.ForceDwarfFrameSection = CodeGenOpts.ForceDwarfFrameSection; Options.EmitCallSiteInfo = CodeGenOpts.EmitCallSiteInfo; Options.EnableAIXExtendedAltivecABI = LangOpts.EnableAIXExtendedAltivecABI; - Options.XRayOmitFunctionIndex = CodeGenOpts.XRayOmitFunctionIndex; + Options.XRayFunctionIndex = CodeGenOpts.XRayFunctionIndex; Options.LoopAlignment = CodeGenOpts.LoopAlignment; Options.DebugStrictDwarf = CodeGenOpts.DebugStrictDwarf; Options.ObjectFilenameForDebug = CodeGenOpts.ObjectFilenameForDebug; diff --git a/clang/lib/Driver/XRayArgs.cpp b/clang/lib/Driver/XRayArgs.cpp index f15a91f1aba44..89aeb20aa68cd 100644 --- a/clang/lib/Driver/XRayArgs.cpp +++ b/clang/lib/Driver/XRayArgs.cpp @@ -178,8 +178,8 @@ void XRayArgs::addArgs(const ToolChain &TC, const ArgList &Args, options::OPT_fno_xray_always_emit_typedevents); Args.addOptInFlag(CmdArgs, options::OPT_fxray_ignore_loops, options::OPT_fno_xray_ignore_loops); - Args.addOptOutFlag(CmdArgs, options::OPT_fxray_function_index, - options::OPT_fno_xray_function_index); + Args.addOptInFlag(CmdArgs, options::OPT_fxray_function_index, + options::OPT_fno_xray_function_index); if (const Arg *A = Args.getLastArg(options::OPT_fxray_instruction_threshold_EQ)) { diff --git a/clang/test/CodeGen/xray-function-index.c b/clang/test/CodeGen/xray-function-index.c new file mode 100644 index 0000000000000..bdaef655abcfc --- /dev/null +++ b/clang/test/CodeGen/xray-function-index.c @@ -0,0 +1,8 @@ +// REQUIRES: x86-registered-target +// RUN: %clang_cc1 -S -triple x86_64 -fxray-instrument -fxray-instruction-threshold=1 -fxray-function-index %s -o - | FileCheck %s +// RUN: %clang_cc1 -S -triple x86_64 -fxray-instrument -fxray-instruction-threshold=1 %s -o - | FileCheck %s --check-prefix=NO + +// CHECK: .section xray_fn_idx,"awo",@progbits,foo +// NO-NOT: .section xray_fn_idx + +void foo(void) {} diff --git a/clang/test/Driver/XRay/xray-function-index-flags.cpp b/clang/test/Driver/XRay/xray-function-index-flags.cpp deleted file mode 100644 index f0d1a8a8c7372..0000000000000 --- a/clang/test/Driver/XRay/xray-function-index-flags.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// This test ensures that when we invoke the clang compiler, that the -cc1 -// options respect the -fno-xray-function-index flag we provide in the -// invocation. The default should be to *include* the function index. -// -// RUN: %clang -### -fxray-instrument -target x86_64 -c %s 2>&1 | FileCheck %s -// RUN: %clang -### -fxray-instrument -target x86_64 -fxray-function-index -c %s 2>&1 | FileCheck %s - -// CHECK-NOT: -fno-xray-function-index - -// RUN: %clang -### -fxray-instrument -target x86_64 -fno-xray-function-index -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-DISABLED - -// CHECK-DISABLED: -fno-xray-function-index diff --git a/clang/test/Driver/xray-function-index.cpp b/clang/test/Driver/xray-function-index.cpp new file mode 100644 index 0000000000000..550de3d17305a --- /dev/null +++ b/clang/test/Driver/xray-function-index.cpp @@ -0,0 +1,5 @@ +// RUN: %clang -### -c --target=x86_64 -fxray-instrument -fxray-function-index %s 2>&1 | FileCheck %s +// RUN: %clang -### -c --target=x86_64 -fxray-instrument %s 2>&1 | FileCheck %s --check-prefix=DISABLED + +// CHECK: "-fxray-function-index" +// DISABLED-NOT: "-fxray-function-index" diff --git a/llvm/include/llvm/CodeGen/CommandFlags.h b/llvm/include/llvm/CodeGen/CommandFlags.h index ff7f1ba673b2e..27794eb63de0b 100644 --- a/llvm/include/llvm/CodeGen/CommandFlags.h +++ b/llvm/include/llvm/CodeGen/CommandFlags.h @@ -136,7 +136,7 @@ std::optional getExplicitValueTrackingVariableLocations(); bool getForceDwarfFrameSection(); -bool getXRayOmitFunctionIndex(); +bool getXRayFunctionIndex(); bool getDebugStrictDwarf(); diff --git a/llvm/include/llvm/Target/TargetOptions.h b/llvm/include/llvm/Target/TargetOptions.h index 5a04a7d5178cb..d6d767f3d22c7 100644 --- a/llvm/include/llvm/Target/TargetOptions.h +++ b/llvm/include/llvm/Target/TargetOptions.h @@ -140,7 +140,7 @@ namespace llvm { SupportsDefaultOutlining(false), EmitAddrsig(false), EmitCallSiteInfo(false), SupportsDebugEntryValues(false), EnableDebugEntryValues(false), ValueTrackingVariableLocations(false), - ForceDwarfFrameSection(false), XRayOmitFunctionIndex(false), + ForceDwarfFrameSection(false), XRayFunctionIndex(true), DebugStrictDwarf(false), Hotpatch(false), PPCGenScalarMASSEntries(false), JMCInstrument(false), EnableCFIFixup(false), MisExpect(false), XCOFFReadOnlyPointers(false), @@ -334,7 +334,7 @@ namespace llvm { unsigned ForceDwarfFrameSection : 1; /// Emit XRay Function Index section - unsigned XRayOmitFunctionIndex : 1; + unsigned XRayFunctionIndex : 1; /// When set to true, don't use DWARF extensions in later DWARF versions. /// By default, it is set to false. diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 162634cfb402b..253c072152376 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -4011,14 +4011,14 @@ void AsmPrinter::emitXRayTable() { Flags, 0, GroupName, F.hasComdat(), MCSection::NonUniqueID, LinkedToSym); - if (!TM.Options.XRayOmitFunctionIndex) + if (TM.Options.XRayFunctionIndex) FnSledIndex = OutContext.getELFSection( "xray_fn_idx", ELF::SHT_PROGBITS, Flags | ELF::SHF_WRITE, 0, GroupName, F.hasComdat(), MCSection::NonUniqueID, LinkedToSym); } else if (MF->getSubtarget().getTargetTriple().isOSBinFormatMachO()) { InstMap = OutContext.getMachOSection("__DATA", "xray_instr_map", 0, SectionKind::getReadOnlyWithRel()); - if (!TM.Options.XRayOmitFunctionIndex) + if (TM.Options.XRayFunctionIndex) FnSledIndex = OutContext.getMachOSection( "__DATA", "xray_fn_idx", 0, SectionKind::getReadOnlyWithRel()); } else { diff --git a/llvm/lib/CodeGen/CommandFlags.cpp b/llvm/lib/CodeGen/CommandFlags.cpp index 35263eabfc4f9..3c6964e7ac802 100644 --- a/llvm/lib/CodeGen/CommandFlags.cpp +++ b/llvm/lib/CodeGen/CommandFlags.cpp @@ -99,7 +99,7 @@ CGOPT(bool, EmitCallSiteInfo) CGOPT(bool, EnableMachineFunctionSplitter) CGOPT(bool, EnableDebugEntryValues) CGOPT(bool, ForceDwarfFrameSection) -CGOPT(bool, XRayOmitFunctionIndex) +CGOPT(bool, XRayFunctionIndex) CGOPT(bool, DebugStrictDwarf) CGOPT(unsigned, AlignLoops) CGOPT(bool, JMCInstrument) @@ -461,10 +461,10 @@ codegen::RegisterCodeGenFlags::RegisterCodeGenFlags() { cl::desc("Always emit a debug frame section."), cl::init(false)); CGBINDOPT(ForceDwarfFrameSection); - static cl::opt XRayOmitFunctionIndex( - "no-xray-index", cl::desc("Don't emit xray_fn_idx section"), - cl::init(false)); - CGBINDOPT(XRayOmitFunctionIndex); + static cl::opt XRayFunctionIndex("xray-function-index", + cl::desc("Emit xray_fn_idx section"), + cl::init(true)); + CGBINDOPT(XRayFunctionIndex); static cl::opt DebugStrictDwarf( "strict-dwarf", cl::desc("use strict dwarf"), cl::init(false)); @@ -559,7 +559,7 @@ codegen::InitTargetOptionsFromCodeGenFlags(const Triple &TheTriple) { Options.EmitCallSiteInfo = getEmitCallSiteInfo(); Options.EnableDebugEntryValues = getEnableDebugEntryValues(); Options.ForceDwarfFrameSection = getForceDwarfFrameSection(); - Options.XRayOmitFunctionIndex = getXRayOmitFunctionIndex(); + Options.XRayFunctionIndex = getXRayFunctionIndex(); Options.DebugStrictDwarf = getDebugStrictDwarf(); Options.LoopAlignment = getAlignLoops(); Options.JMCInstrument = getJMCInstrument(); diff --git a/llvm/test/CodeGen/AArch64/xray-omit-function-index.ll b/llvm/test/CodeGen/AArch64/xray-omit-function-index.ll index 5adf502af2afa..bc450d726202e 100644 --- a/llvm/test/CodeGen/AArch64/xray-omit-function-index.ll +++ b/llvm/test/CodeGen/AArch64/xray-omit-function-index.ll @@ -1,5 +1,5 @@ -; RUN: llc -no-xray-index -mtriple=aarch64-unknown-linux-gnu < %s | FileCheck %s --check-prefixes=CHECK,CHECK-LINUX -; RUN: llc -no-xray-index -mtriple=aarch64-apple-darwin < %s | FileCheck %s --check-prefixes=CHECK,CHECK-MACOS +; RUN: llc -mtriple=aarch64-unknown-linux-gnu -xray-function-index=0 < %s | FileCheck %s --check-prefixes=CHECK,CHECK-LINUX +; RUN: llc -mtriple=aarch64-apple-darwin -xray-function-index=0 < %s | FileCheck %s --check-prefixes=CHECK,CHECK-MACOS define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" { ; CHECK-LABEL: Lxray_sled_0: