[PATCH] D145249: [TargetParser] Disallow Global Constructors

Sam Elliott via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 3 08:31:25 PST 2023


lenary created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
lenary requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145249

Files:
  llvm/lib/TargetParser/CMakeLists.txt


Index: llvm/lib/TargetParser/CMakeLists.txt
===================================================================
--- llvm/lib/TargetParser/CMakeLists.txt
+++ 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145249.502142.patch
Type: text/x-patch
Size: 790 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230303/5b4efdd5/attachment.bin>


More information about the llvm-commits mailing list