Skip to content

Commit

Permalink
Build libswiftStdlibStubs.a with the same warnings about global ctors…
Browse files Browse the repository at this point in the history
…/dtors as the runtime.

We don't want unnecessary static constructors or destructors to leak into the stdlib or runtime. Add -Wexit-time-destructors to both targets too.
  • Loading branch information
jckarter committed Nov 14, 2015
1 parent 24f0753 commit 9d366f7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
8 changes: 8 additions & 0 deletions stdlib/public/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# C++ code in the runtime and standard library should generally avoid
# introducing static constructors or destructors.
set(SWIFT_CORE_CXX_FLAGS)
check_cxx_compiler_flag("-Werror -Wglobal-constructors" CXX_SUPPORTS_GLOBAL_CONSTRUCTORS_WARNING)
append_if(CXX_SUPPORTS_GLOBAL_CONSTRUCTORS_WARNING "-Wglobal-constructors" SWIFT_CORE_CXX_FLAGS)
check_cxx_compiler_flag("-Wexit-time-destructors" CXX_SUPPORTS_EXIT_TIME_DESTRUCTORS_WARNING)
append_if(CXX_SUPPORTS_EXIT_TIME_DESTRUCTORS_WARNING "-Wexit-time-destructors" SWIFT_CORE_CXX_FLAGS)

if(SWIFT_BUILD_STDLIB)
# These must be kept in dependency order so that any referenced targets
# exist at the time we look for them in add_swift_*.
Expand Down
6 changes: 1 addition & 5 deletions stdlib/public/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(swift_runtime_compile_flags)
set(swift_runtime_compile_flags ${SWIFT_CORE_CXX_FLAGS})

if(SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS)
list(APPEND swift_runtime_compile_flags
Expand Down Expand Up @@ -49,10 +49,6 @@ else()
${ICU_UC_INCLUDE_DIR} ${ICU_I18N_INCLUDE_DIR})
endif()

# Complain about static global constructors in the runtime.
check_cxx_compiler_flag("-Werror -Wglobal-constructors" CXX_SUPPORTS_GLOBAL_CONSTRUCTORS_WARNING)
append_if(CXX_SUPPORTS_GLOBAL_CONSTRUCTORS_WARNING "-Wglobal-constructors" swift_runtime_compile_flags)

add_swift_library(swiftRuntime IS_STDLIB IS_STDLIB_CORE
Casting.cpp
Demangle.cpp
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/stubs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ add_swift_library(swiftStdlibStubs IS_STDLIB IS_STDLIB_CORE
LibcShims.cpp
Stubs.cpp
${swift_stubs_objc_sources}
C_COMPILE_FLAGS ${SWIFT_CORE_CXX_FLAGS}
INSTALL_IN_COMPONENT stdlib)


0 comments on commit 9d366f7

Please sign in to comment.