-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[XRay] Add -fxray-default-options
to pass build-time defined XRay options
#116878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// RUN: %clang_cc1 -fxray-instrument -fxray-default-options='patch_premain=true,xray_mode=xray-basic' \ | ||
// RUN: -std=c11 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s | ||
|
||
void justAFunction() { | ||
} | ||
|
||
// CHECK: !{{[0-9]+}} = !{i32 1, !"xray-default-opts", !"patch_premain=true,xray_mode=xray-basic"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/*===----- xray_options_var.cpp - XRay option variable setup -------------===*\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|* | ||
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
|* See https://llvm.org/LICENSE.txt for license information. | ||
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|* | ||
\*===----------------------------------------------------------------------===*/ | ||
|
||
#include "xray_flags.h" | ||
|
||
// FIXME: Generalize these. See lib/profile/InstrProfilingPort.h and | ||
// include/profile/InstrProfData.inc | ||
#define COMPILER_RT_VISIBILITY __attribute__((visibility("hidden"))) | ||
#define COMPILER_RT_WEAK __attribute__((weak)) | ||
|
||
extern "C" { | ||
/* char __llvm_xray_options[1] | ||
* | ||
* The runtime should only provide its own definition of this symbol when the | ||
* user has not specified one. Set this up by moving the runtime's copy of this | ||
* symbol to an object file within the archive. | ||
*/ | ||
COMPILER_RT_WEAK COMPILER_RT_VISIBILITY char XRAY_OPTIONS_VAR[1] = {0}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// RUN: %clang_xray -g -fxray-default-options='patch_premain=true:verbosity=1:xray_mode=xray-basic' -o %t %s | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lld/test/ELF style |
||
// RUN: rm -f xray-log.default-options.* | ||
// RUN: %run %t 2>&1 | FileCheck %s | ||
// RUN: rm -f xray-log.default-options.* | ||
// | ||
// REQUIRES: target={{(aarch64|loongarch64|x86_64)-.*}} | ||
// REQUIRES: built-in-llvm-tree | ||
__attribute__((xray_always_instrument)) void always() {} | ||
|
||
int main() { always(); } | ||
|
||
// CHECK: =={{[0-9].*}}==XRay: Log file in '{{.*}}' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
llvm/include/llvm/Transforms/Instrumentation/XRayPreparation.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//===- XRayPreparation.h - Preparation for XRay instrumentation -*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This Pass does some IR-level preparations (e.g. inserting global variable | ||
// that carries default options, if there is any) for XRay instrumentation. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_XRAYPREPARATION_H | ||
#define LLVM_TRANSFORMS_INSTRUMENTATION_XRAYPREPARATION_H | ||
|
||
#include "llvm/IR/PassManager.h" | ||
|
||
namespace llvm { | ||
struct XRayPreparationPass : public PassInfoMixin<XRayPreparationPass> { | ||
PreservedAnalyses run(Module &, ModuleAnalysisManager &); | ||
}; | ||
} // namespace llvm | ||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//===- XRayPreparation.cpp - Preparation for XRay instrumentation -------- ===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This Pass does some IR-level preparations (e.g. inserting global variable | ||
// that carries default options, if there is any) for XRay instrumentation. | ||
// | ||
//===---------------------------------------------------------------------===// | ||
|
||
#include "llvm/Transforms/Instrumentation/XRayPreparation.h" | ||
#include "llvm/IR/Constants.h" | ||
#include "llvm/IR/Module.h" | ||
#include "llvm/TargetParser/Triple.h" | ||
|
||
using namespace llvm; | ||
|
||
static void createXRayDefaultOptionsVar(Module &M, StringRef DefaultOptions) { | ||
Constant *DefaultOptionsConst = | ||
ConstantDataArray::getString(M.getContext(), DefaultOptions, true); | ||
// This global variable will be passed into XRay's compiler-rt and used as | ||
// the initial set of XRay options. | ||
GlobalVariable *DefaultOptsVar = new GlobalVariable( | ||
M, DefaultOptionsConst->getType(), true, GlobalValue::WeakAnyLinkage, | ||
DefaultOptionsConst, "__llvm_xray_options"); | ||
DefaultOptsVar->setVisibility(GlobalValue::HiddenVisibility); | ||
Triple TT(M.getTargetTriple()); | ||
if (TT.supportsCOMDAT()) { | ||
DefaultOptsVar->setLinkage(GlobalValue::ExternalLinkage); | ||
DefaultOptsVar->setComdat(M.getOrInsertComdat("__llvm_xray_options")); | ||
} | ||
} | ||
|
||
PreservedAnalyses XRayPreparationPass::run(Module &M, | ||
ModuleAnalysisManager &MAM) { | ||
// XRay default options. | ||
if (const auto *DefaultOpts = | ||
dyn_cast_or_null<MDString>(M.getModuleFlag("xray-default-opts"))) { | ||
createXRayDefaultOptionsVar(M, DefaultOpts->getString()); | ||
PreservedAnalyses PA; | ||
PA.preserveSet<CFGAnalyses>(); | ||
return PA; | ||
} | ||
|
||
return PreservedAnalyses::all(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
; RUN: opt -S -p xray-preparation < %s | FileCheck %s | ||
|
||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
; CHECK: $__llvm_xray_options = comdat any | ||
; CHECK: @__llvm_xray_options = hidden constant [40 x i8] c"patch_premain=true,xray_mode=xray-basic\00", comdat | ||
|
||
!llvm.module.flags = !{!0} | ||
|
||
!0 = !{i32 1, !"xray-default-opts", !"patch_premain=true,xray_mode=xray-basic"} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem useful to introduce a capitalized alias
XRAY_OPTIONS_VAR
.If a TU doesn't include
xray_flags.h
, the compiled code will referenceXRAY_OPTIONS_VAR
.