summaryrefslogtreecommitdiff
path: root/lib/xray/xray_flags.cc
diff options
context:
space:
mode:
authorDean Michael Berris <dberris@google.com>2017-02-18 02:09:51 +0000
committerDean Michael Berris <dberris@google.com>2017-02-18 02:09:51 +0000
commitcb4a476d3b02a7101d2fdcd56fafd4c38477255e (patch)
tree75d2433375599a9293a55429362f6c10b9793543 /lib/xray/xray_flags.cc
parente1e89fcf5087b93bc1ef62fb11d573cf2193ee93 (diff)
[XRay][compiler-rt] Allow for defining defaults at compile-time
Summary: Currently, defaulted options cannot be overriden easily. As an example, we always patch the binary pre-main unless the user defines the option at the commandline to inhibit this behaviour. This change allows for building different versions of the XRay archive with different defaults (whether to patch pre-main, or whether to use FDR mode by default, etc.) and giving that choice at link-time. For now we don't create different archives that have different defaults, but those could be added in later revisions. This change just enables the possibility. Reviewers: pelikan, kcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D30022 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@295534 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/xray/xray_flags.cc')
-rw-r--r--lib/xray/xray_flags.cc26
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/xray/xray_flags.cc b/lib/xray/xray_flags.cc
index 7465cb439..1ee4d10d7 100644
--- a/lib/xray/xray_flags.cc
+++ b/lib/xray/xray_flags.cc
@@ -37,6 +37,25 @@ static void registerXRayFlags(FlagParser *P, Flags *F) XRAY_NEVER_INSTRUMENT {
#undef XRAY_FLAG
}
+// This function, as defined with the help of a macro meant to be introduced at
+// build time of the XRay runtime, passes in a statically defined list of
+// options that control XRay. This means users/deployments can tweak the
+// defaults that override the hard-coded defaults in the xray_flags.inc at
+// compile-time using the XRAY_DEFAULT_OPTIONS macro.
+static const char *useCompilerDefinedFlags() XRAY_NEVER_INSTRUMENT {
+#ifdef XRAY_DEFAULT_OPTIONS
+// Do the double-layered string conversion to prevent badly crafted strings
+// provided through the XRAY_DEFAULT_OPTIONS from causing compilation issues (or
+// changing the semantics of the implementation through the macro). This ensures
+// that we convert whatever XRAY_DEFAULT_OPTIONS is defined as a string literal.
+#define XRAY_STRINGIZE(x) #x
+#define XRAY_STRINGIZE_OPTIONS(options) XRAY_STRINGIZE(options)
+ return XRAY_STRINGIZE_OPTIONS(XRAY_DEFAULT_OPTIONS);
+#else
+ return "";
+#endif
+}
+
void initializeFlags() XRAY_NEVER_INSTRUMENT {
SetCommonFlagsDefaults();
auto *F = flags();
@@ -46,9 +65,14 @@ void initializeFlags() XRAY_NEVER_INSTRUMENT {
registerXRayFlags(&XRayParser, F);
RegisterCommonFlags(&XRayParser);
- // Override from command line.
+ // Use options defaulted at compile-time for the runtime.
+ const char *XRayCompileFlags = useCompilerDefinedFlags();
+ XRayParser.ParseString(XRayCompileFlags);
+
+ // Override from environment variables.
XRayParser.ParseString(GetEnv("XRAY_OPTIONS"));
+ // Override from command line.
InitializeCommonFlags();
if (Verbosity())