aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Signals.cpp
diff options
context:
space:
mode:
authorMehdi Amini <joker.eph@gmail.com>2021-07-15 23:52:44 +0000
committerMehdi Amini <joker.eph@gmail.com>2021-07-16 03:33:20 +0000
commit42f588f39c5ce6f521e3709b8871d1fdd076292f (patch)
tree5ad9009fe09e82045e3a57cf39167e223ab00a27 /llvm/lib/Support/Signals.cpp
parentb4c93ece8e4f6e98a15daca10c8a3db33cf8c195 (diff)
downloadllvm-42f588f39c5ce6f521e3709b8871d1fdd076292f.zip
llvm-42f588f39c5ce6f521e3709b8871d1fdd076292f.tar.gz
llvm-42f588f39c5ce6f521e3709b8871d1fdd076292f.tar.bz2
Use ManagedStatic and lazy initialization of cl::opt in libSupport to make it free of global initializer
We can build it with -Werror=global-constructors now. This helps in situation where libSupport is embedded as a shared library, potential with dlopen/dlclose scenario, and when command-line parsing or other facilities may not be involved. Avoiding the implicit construction of these cl::opt can avoid double-registration issues and other kind of behavior. Reviewed By: lattner, jpienaar Differential Revision: https://reviews.llvm.org/D105959
Diffstat (limited to 'llvm/lib/Support/Signals.cpp')
-rw-r--r--llvm/lib/Support/Signals.cpp39
1 files changed, 30 insertions, 9 deletions
diff --git a/llvm/lib/Support/Signals.cpp b/llvm/lib/Support/Signals.cpp
index 4e70eed..dd4dded 100644
--- a/llvm/lib/Support/Signals.cpp
+++ b/llvm/lib/Support/Signals.cpp
@@ -12,6 +12,9 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/Signals.h"
+
+#include "DebugOptions.h"
+
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Config/llvm-config.h"
@@ -39,15 +42,33 @@ using namespace llvm;
// Use explicit storage to avoid accessing cl::opt in a signal handler.
static bool DisableSymbolicationFlag = false;
-static cl::opt<bool, true>
- DisableSymbolication("disable-symbolication",
- cl::desc("Disable symbolizing crash backtraces."),
- cl::location(DisableSymbolicationFlag), cl::Hidden);
-static std::string CrashDiagnosticsDirectory;
-static cl::opt<std::string, true>
- CrashDiagnosticsDir("crash-diagnostics-dir", cl::value_desc("directory"),
- cl::desc("Directory for crash diagnostic files."),
- cl::location(CrashDiagnosticsDirectory), cl::Hidden);
+static ManagedStatic<std::string> CrashDiagnosticsDirectory;
+namespace {
+struct CreateDisableSymbolication {
+ static void *call() {
+ return new cl::opt<bool, true>(
+ "disable-symbolication",
+ cl::desc("Disable symbolizing crash backtraces."),
+ cl::location(DisableSymbolicationFlag), cl::Hidden);
+ }
+};
+struct CreateCrashDiagnosticsDir {
+ static void *call() {
+ return new cl::opt<std::string, true>(
+ "crash-diagnostics-dir", cl::value_desc("directory"),
+ cl::desc("Directory for crash diagnostic files."),
+ cl::location(*CrashDiagnosticsDirectory), cl::Hidden);
+ }
+};
+} // namespace
+void llvm::initSignalsOptions() {
+ static ManagedStatic<cl::opt<bool, true>, CreateDisableSymbolication>
+ DisableSymbolication;
+ static ManagedStatic<cl::opt<std::string, true>, CreateCrashDiagnosticsDir>
+ CrashDiagnosticsDir;
+ *DisableSymbolication;
+ *CrashDiagnosticsDir;
+}
constexpr char DisableSymbolizationEnv[] = "LLVM_DISABLE_SYMBOLIZATION";
constexpr char LLVMSymbolizerPathEnv[] = "LLVM_SYMBOLIZER_PATH";