[libc] Switch to using the generic `<gpuintrin.h>` implementations (#121810)
[llvm-project.git] / compiler-rt / lib / xray / xray_flags.cpp
blob9d3ee3ea85528857df1483a4c53bbed9c6398b3d
1 //===-- xray_flags.cpp ------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is a part of XRay, a dynamic runtime instrumentation system.
11 // XRay flag parsing logic.
12 //===----------------------------------------------------------------------===//
14 #include "xray_flags.h"
15 #include "sanitizer_common/sanitizer_common.h"
16 #include "sanitizer_common/sanitizer_flag_parser.h"
17 #include "sanitizer_common/sanitizer_libc.h"
18 #include "xray_defs.h"
20 using namespace __sanitizer;
22 namespace __xray {
24 Flags xray_flags_dont_use_directly; // use via flags().
26 void Flags::setDefaults() XRAY_NEVER_INSTRUMENT {
27 #define XRAY_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
28 #include "xray_flags.inc"
29 #undef XRAY_FLAG
32 void registerXRayFlags(FlagParser *P, Flags *F) XRAY_NEVER_INSTRUMENT {
33 #define XRAY_FLAG(Type, Name, DefaultValue, Description) \
34 RegisterFlag(P, #Name, Description, &F->Name);
35 #include "xray_flags.inc"
36 #undef XRAY_FLAG
39 // This function, as defined with the help of a macro meant to be introduced at
40 // build time of the XRay runtime, passes in a statically defined list of
41 // options that control XRay. This means users/deployments can tweak the
42 // defaults that override the hard-coded defaults in the xray_flags.inc at
43 // compile-time using the XRAY_DEFAULT_OPTIONS macro.
44 const char *useCompilerDefinedFlags() XRAY_NEVER_INSTRUMENT {
45 #ifdef XRAY_DEFAULT_OPTIONS
46 // Do the double-layered string conversion to prevent badly crafted strings
47 // provided through the XRAY_DEFAULT_OPTIONS from causing compilation issues
48 // (or changing the semantics of the implementation through the macro). This
49 // ensures that we convert whatever XRAY_DEFAULT_OPTIONS is defined as a
50 // string literal.
51 return SANITIZER_STRINGIFY(XRAY_DEFAULT_OPTIONS);
52 #else
53 return "";
54 #endif
57 void initializeFlags() XRAY_NEVER_INSTRUMENT {
58 SetCommonFlagsDefaults();
59 auto *F = flags();
60 F->setDefaults();
62 FlagParser XRayParser;
63 registerXRayFlags(&XRayParser, F);
64 RegisterCommonFlags(&XRayParser);
66 // Use options defaulted at compile-time for the runtime.
67 const char *XRayCompileFlags = useCompilerDefinedFlags();
68 XRayParser.ParseString(XRayCompileFlags);
70 // Use options provided at build time of the instrumented program.
71 const char *XRayDefaultOptions = __xray_default_options();
72 XRayParser.ParseString(XRayDefaultOptions);
74 // Override from environment variables.
75 XRayParser.ParseStringFromEnv("XRAY_OPTIONS");
77 // Override from command line.
78 InitializeCommonFlags();
80 if (Verbosity())
81 ReportUnrecognizedFlags();
83 if (common_flags()->help) {
84 XRayParser.PrintFlagDescriptions();
88 } // namespace __xray
90 SANITIZER_INTERFACE_WEAK_DEF(const char *, __xray_default_options, void) {
91 return "";