[llvm] cddc1b6 - [TargetParser] Disallow Global Constructors
Archibald Elliott via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 10 07:53:31 PST 2023
Author: Archibald Elliott
Date: 2023-03-10T15:53:14Z
New Revision: cddc1b6b278399ea453903037f70e2cab356ead1
URL: https://github.com/llvm/llvm-project/commit/cddc1b6b278399ea453903037f70e2cab356ead1
DIFF: https://github.com/llvm/llvm-project/commit/cddc1b6b278399ea453903037f70e2cab356ead1.diff
LOG: [TargetParser] Disallow Global Constructors
Global Constructors are disallowed in the Support library. The
TargetParser library is likely to go along with the Support library in
most uses, because it contains llvm::Triple, so lets pre-emptively add
the same rule, rather than getting caught out later.
Differential Revision: https://reviews.llvm.org/D145249
Added:
Modified:
llvm/lib/TargetParser/CMakeLists.txt
Removed:
################################################################################
diff --git a/llvm/lib/TargetParser/CMakeLists.txt b/llvm/lib/TargetParser/CMakeLists.txt
index 392c67478007f..0bfea7b14e690 100644
--- a/llvm/lib/TargetParser/CMakeLists.txt
+++ b/llvm/lib/TargetParser/CMakeLists.txt
@@ -1,3 +1,13 @@
+# Ensure that libLLVMTargetParser does not carry any static global initializer.
+# ManagedStatic can be used to enable lazy-initialization of globals.
+#
+# HAS_WERROR_GLOBAL_CTORS and LLVM_HAS_NOGLOBAL_CTOR_MUTEX should have been set
+# by llvm/lib/Support/CMakeLists.txt (which provides the required Support
+# dependency).
+if (HAS_WERROR_GLOBAL_CTORS AND NOT LLVM_HAS_NOGLOBAL_CTOR_MUTEX)
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=global-constructors")
+endif()
+
add_llvm_component_library(LLVMTargetParser
AArch64TargetParser.cpp
ARMTargetParserCommon.cpp
More information about the llvm-commits
mailing list