Skip to content

Commit

Permalink
[libc] Warn on use of global constructors in libc
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jhuber6 committed Jul 20, 2023
1 parent 805ce9a commit 26a1849
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions libc/cmake/modules/LLVMLibCObjectRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 26a1849

Please sign in to comment.