From 26a1849cca4e84feeaac303fba05f8dabca84050 Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Wed, 19 Jul 2023 11:00:34 -0500 Subject: [PATCH] [libc] Warn on use of global constructors in `libc` Clang supports the `-Wglobal-constructors` flag which will indicate if a global constructor is being used. The current goal in `libc` is to make the constructors `constexpr` to prevent this from happening with straight construction. However, there are many other cases where we can emit a constructor that this won't catch. This should give warning if someone accidentally introduces a global constructor. Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D155721 --- libc/cmake/modules/LLVMLibCObjectRules.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake index 2dfa7c09ae916..5c76cf285e637 100644 --- a/libc/cmake/modules/LLVMLibCObjectRules.cmake +++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake @@ -38,6 +38,7 @@ function(_get_common_compile_options output_var flags) list(APPEND compile_options "-Wnonportable-system-include-path") list(APPEND compile_options "-Wstrict-prototypes") list(APPEND compile_options "-Wthread-safety") + list(APPEND compile_options "-Wglobal-constructors") endif() if(ADD_FMA_FLAG) if(LIBC_TARGET_ARCHITECTURE_IS_X86)