From cddc1b6b278399ea453903037f70e2cab356ead1 Mon Sep 17 00:00:00 2001 From: Archibald Elliott Date: Sat, 4 Feb 2023 13:27:32 +0000 Subject: [PATCH] [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 --- llvm/lib/TargetParser/CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/llvm/lib/TargetParser/CMakeLists.txt b/llvm/lib/TargetParser/CMakeLists.txt index 392c674..0bfea7b 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 -- 2.7.4