]> git.proxmox.com Git - rustc.git/blame - src/libcompiler_builtins/compiler-rt/lib/xray/xray_flags.cc
New upstream version 1.25.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / lib / xray / xray_flags.cc
CommitLineData
7cac9316
XL
1//===-- xray_flags.cc -------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file is a part of XRay, a dynamic runtime instrumentation system.
11//
12// XRay flag parsing logic.
13//===----------------------------------------------------------------------===//
14
15#include "xray_flags.h"
16#include "sanitizer_common/sanitizer_common.h"
17#include "sanitizer_common/sanitizer_flag_parser.h"
18#include "sanitizer_common/sanitizer_libc.h"
19#include "xray_defs.h"
20
21using namespace __sanitizer;
22
23namespace __xray {
24
25Flags xray_flags_dont_use_directly; // use via flags().
26
2c00a5a8 27void Flags::setDefaults() XRAY_NEVER_INSTRUMENT {
7cac9316
XL
28#define XRAY_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
29#include "xray_flags.inc"
30#undef XRAY_FLAG
31}
32
2c00a5a8 33static void registerXRayFlags(FlagParser *P, Flags *F) XRAY_NEVER_INSTRUMENT {
7cac9316
XL
34#define XRAY_FLAG(Type, Name, DefaultValue, Description) \
35 RegisterFlag(P, #Name, Description, &F->Name);
36#include "xray_flags.inc"
37#undef XRAY_FLAG
38}
39
2c00a5a8
XL
40// This function, as defined with the help of a macro meant to be introduced at
41// build time of the XRay runtime, passes in a statically defined list of
42// options that control XRay. This means users/deployments can tweak the
43// defaults that override the hard-coded defaults in the xray_flags.inc at
44// compile-time using the XRAY_DEFAULT_OPTIONS macro.
45static const char *useCompilerDefinedFlags() XRAY_NEVER_INSTRUMENT {
46#ifdef XRAY_DEFAULT_OPTIONS
47// Do the double-layered string conversion to prevent badly crafted strings
48// provided through the XRAY_DEFAULT_OPTIONS from causing compilation issues (or
49// changing the semantics of the implementation through the macro). This ensures
50// that we convert whatever XRAY_DEFAULT_OPTIONS is defined as a string literal.
51#define XRAY_STRINGIZE(x) #x
52#define XRAY_STRINGIZE_OPTIONS(options) XRAY_STRINGIZE(options)
53 return XRAY_STRINGIZE_OPTIONS(XRAY_DEFAULT_OPTIONS);
54#else
55 return "";
56#endif
57}
58
59void initializeFlags() XRAY_NEVER_INSTRUMENT {
7cac9316
XL
60 SetCommonFlagsDefaults();
61 auto *F = flags();
2c00a5a8 62 F->setDefaults();
7cac9316
XL
63
64 FlagParser XRayParser;
2c00a5a8 65 registerXRayFlags(&XRayParser, F);
7cac9316
XL
66 RegisterCommonFlags(&XRayParser);
67
2c00a5a8
XL
68 // Use options defaulted at compile-time for the runtime.
69 const char *XRayCompileFlags = useCompilerDefinedFlags();
70 XRayParser.ParseString(XRayCompileFlags);
71
72 // Override from environment variables.
7cac9316
XL
73 XRayParser.ParseString(GetEnv("XRAY_OPTIONS"));
74
2c00a5a8 75 // Override from command line.
7cac9316
XL
76 InitializeCommonFlags();
77
78 if (Verbosity())
79 ReportUnrecognizedFlags();
80
81 if (common_flags()->help) {
82 XRayParser.PrintFlagDescriptions();
83 }
84}
85
86} // namespace __xray