From 61041e8ca32452810fa41f8694efb49efda2950f Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Fri, 16 Jul 2021 03:32:59 +0000 Subject: [PATCH] Build libSupport with -Werror=global-constructors (NFC) Ensure that libSupport does not carry any static global initializer. libSupport can be embedded in use cases where we don't want to load all cl::opt unless we want to parse the command line. ManagedStatic can be used to enable lazy-initialization of globals. --- lib/Support/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Support/CMakeLists.txt b/lib/Support/CMakeLists.txt index 2242b0ec60a..57058c6704e 100644 --- a/lib/Support/CMakeLists.txt +++ b/lib/Support/CMakeLists.txt @@ -1,5 +1,11 @@ include(GetLibraryName) +# Ensure that libSupport does not carry any static global initializer. +# libSupport can be embedded in use cases where we don't want to load all +# cl::opt unless we want to parse the command line. +# ManagedStatic can be used to enable lazy-initialization of globals. +add_flag_if_supported("-Werror=global-constructors" WERROR_GLOBAL_CONSTRUCTOR) + if(LLVM_ENABLE_ZLIB) set(imported_libs ZLIB::ZLIB) endif()