Skip to content

Commit 220de1f

Browse files
committed
Revert "[CMake] Avoid accidental C++ standard library dependency in sanitizers"
This reverts commit 287c318 which broke sanitizer tests that use C++ standard library.
1 parent 287c318 commit 220de1f

File tree

8 files changed

+37
-36
lines changed

8 files changed

+37
-36
lines changed

compiler-rt/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -437,13 +437,6 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Fuchsia")
437437
list(APPEND SANITIZER_COMMON_LINK_LIBS zircon)
438438
endif()
439439

440-
# We don't use the C++ standard library, so avoid including it by mistake.
441-
append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ SANITIZER_COMMON_CFLAGS)
442-
append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ SANITIZER_COMMON_LINK_FLAGS)
443-
444-
# Remove -stdlib= which is unused when passing -nostdinc++.
445-
string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
446-
447440
macro(append_libcxx_libs var)
448441
if (${var}_INTREE)
449442
if (SANITIZER_USE_STATIC_LLVM_UNWINDER AND (TARGET unwind_static OR HAVE_LIBUNWIND))

compiler-rt/cmake/Modules/CompilerRTUtils.cmake

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,6 @@ function(list_replace input_list old new)
8080
set(${input_list} "${replaced_list}" PARENT_SCOPE)
8181
endfunction()
8282

83-
macro(list_filter list element)
84-
list(FIND ${list} ${element} index)
85-
if(NOT index EQUAL -1)
86-
list(REMOVE_AT ${list} ${index})
87-
endif()
88-
endmacro()
89-
9083
# Takes ${ARGN} and puts only supported architectures in @out_var list.
9184
function(filter_available_targets out_var)
9285
set(archs ${${out_var}})

compiler-rt/cmake/config-ix.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ check_symbol_exists(__func__ "" COMPILER_RT_HAS_FUNC_SYMBOL)
123123

124124
# Includes.
125125
check_cxx_compiler_flag(-nostdinc++ COMPILER_RT_HAS_NOSTDINCXX_FLAG)
126-
check_cxx_compiler_flag(-nostdlib++ COMPILER_RT_HAS_NOSTDLIBXX_FLAG)
127126
check_include_files("sys/auxv.h" COMPILER_RT_HAS_AUXV)
128127

129128
# Libraries.

compiler-rt/lib/asan/CMakeLists.txt

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread ASAN_DYNAMIC_LIBS)
111111
append_list_if(COMPILER_RT_HAS_LIBLOG log ASAN_DYNAMIC_LIBS)
112112
append_list_if(MINGW "${MINGW_LIBRARIES}" ASAN_DYNAMIC_LIBS)
113113

114+
if (TARGET cxx-headers OR HAVE_LIBCXX)
115+
set(ASAN_DEPS cxx-headers)
116+
endif()
117+
114118
# Compile ASan sources into an object library.
115119

116120
add_compiler_rt_object_libraries(RTAsan_dynamic
@@ -119,34 +123,39 @@ add_compiler_rt_object_libraries(RTAsan_dynamic
119123
SOURCES ${ASAN_SOURCES} ${ASAN_CXX_SOURCES}
120124
ADDITIONAL_HEADERS ${ASAN_HEADERS}
121125
CFLAGS ${ASAN_DYNAMIC_CFLAGS}
122-
DEFS ${ASAN_DYNAMIC_DEFINITIONS})
126+
DEFS ${ASAN_DYNAMIC_DEFINITIONS}
127+
DEPS ${ASAN_DEPS})
123128

124129
if(NOT APPLE)
125130
add_compiler_rt_object_libraries(RTAsan
126131
ARCHS ${ASAN_SUPPORTED_ARCH}
127132
SOURCES ${ASAN_SOURCES}
128133
ADDITIONAL_HEADERS ${ASAN_HEADERS}
129134
CFLAGS ${ASAN_CFLAGS}
130-
DEFS ${ASAN_COMMON_DEFINITIONS})
135+
DEFS ${ASAN_COMMON_DEFINITIONS}
136+
DEPS ${ASAN_DEPS})
131137
add_compiler_rt_object_libraries(RTAsan_cxx
132138
ARCHS ${ASAN_SUPPORTED_ARCH}
133139
SOURCES ${ASAN_CXX_SOURCES}
134140
ADDITIONAL_HEADERS ${ASAN_HEADERS}
135141
CFLAGS ${ASAN_CFLAGS}
136-
DEFS ${ASAN_COMMON_DEFINITIONS})
142+
DEFS ${ASAN_COMMON_DEFINITIONS}
143+
DEPS ${ASAN_DEPS})
137144
add_compiler_rt_object_libraries(RTAsan_preinit
138145
ARCHS ${ASAN_SUPPORTED_ARCH}
139146
SOURCES ${ASAN_PREINIT_SOURCES}
140147
ADDITIONAL_HEADERS ${ASAN_HEADERS}
141148
CFLAGS ${ASAN_CFLAGS}
142-
DEFS ${ASAN_COMMON_DEFINITIONS})
149+
DEFS ${ASAN_COMMON_DEFINITIONS}
150+
DEPS ${ASAN_DEPS})
143151

144152
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "")
145153
add_compiler_rt_object_libraries(RTAsan_dynamic_version_script_dummy
146154
ARCHS ${ASAN_SUPPORTED_ARCH}
147155
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
148156
CFLAGS ${ASAN_DYNAMIC_CFLAGS}
149-
DEFS ${ASAN_DYNAMIC_DEFINITIONS})
157+
DEFS ${ASAN_DYNAMIC_DEFINITIONS}
158+
DEPS ${ASAN_DEPS})
150159
endif()
151160

152161
# Build ASan runtimes shipped with Clang.
@@ -241,7 +250,8 @@ else()
241250
ARCHS ${arch}
242251
SOURCES asan_win_weak_interception.cpp
243252
CFLAGS ${ASAN_CFLAGS} -DSANITIZER_DYNAMIC
244-
DEFS ${ASAN_COMMON_DEFINITIONS})
253+
DEFS ${ASAN_COMMON_DEFINITIONS}
254+
DEPS ${ASAN_DEPS})
245255
set(ASAN_DYNAMIC_WEAK_INTERCEPTION
246256
AsanWeakInterception
247257
UbsanWeakInterception
@@ -286,7 +296,8 @@ else()
286296
SOURCES asan_globals_win.cpp
287297
asan_win_dll_thunk.cpp
288298
CFLAGS ${ASAN_CFLAGS} -DSANITIZER_DLL_THUNK
289-
DEFS ${ASAN_COMMON_DEFINITIONS})
299+
DEFS ${ASAN_COMMON_DEFINITIONS}
300+
DEPS ${ASAN_DEPS})
290301

291302
add_compiler_rt_runtime(clang_rt.asan_dll_thunk
292303
STATIC
@@ -311,7 +322,8 @@ else()
311322
SOURCES asan_globals_win.cpp
312323
asan_win_dynamic_runtime_thunk.cpp
313324
CFLAGS ${ASAN_CFLAGS} ${DYNAMIC_RUNTIME_THUNK_CFLAGS}
314-
DEFS ${ASAN_COMMON_DEFINITIONS})
325+
DEFS ${ASAN_COMMON_DEFINITIONS}
326+
DEPS ${ASAN_DEPS})
315327

316328
add_compiler_rt_runtime(clang_rt.asan_dynamic_runtime_thunk
317329
STATIC

compiler-rt/lib/fuzzer/CMakeLists.txt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,11 @@ set(LIBFUZZER_CFLAGS ${SANITIZER_COMMON_CFLAGS})
6060
if(OS_NAME MATCHES "Linux|Fuchsia" AND
6161
COMPILER_RT_LIBCXX_PATH AND
6262
COMPILER_RT_LIBCXXABI_PATH)
63-
list(APPEND LIBFUZZER_CFLAGS -D_LIBCPP_ABI_VERSION=Fuzzer)
63+
list(APPEND LIBFUZZER_CFLAGS -nostdinc++ -D_LIBCPP_ABI_VERSION=Fuzzer)
6464
# Remove -stdlib= which is unused when passing -nostdinc++.
6565
string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
66-
else()
67-
# libFuzzer uses C++ standard library headers so drop -nostdinc++.
68-
list_filter(LIBFUZZER_CFLAGS "-nostdinc++")
69-
if(TARGET cxx-headers OR HAVE_LIBCXX)
70-
set(LIBFUZZER_DEPS cxx-headers)
71-
endif()
66+
elseif(TARGET cxx-headers OR HAVE_LIBCXX)
67+
set(LIBFUZZER_DEPS cxx-headers)
7268
endif()
7369

7470
append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG -fno-omit-frame-pointer LIBFUZZER_CFLAGS)

compiler-rt/lib/hwasan/CMakeLists.txt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ append_list_if(COMPILER_RT_HAS_LIBRT rt HWASAN_DYNAMIC_LIBS)
7171
append_list_if(COMPILER_RT_HAS_LIBM m HWASAN_DYNAMIC_LIBS)
7272
append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread HWASAN_DYNAMIC_LIBS)
7373

74+
if (TARGET cxx-headers OR HAVE_LIBCXX)
75+
set(HWASAN_DEPS cxx-headers)
76+
endif()
77+
7478
# Static runtime library.
7579
add_compiler_rt_component(hwasan)
7680

@@ -79,26 +83,30 @@ add_compiler_rt_object_libraries(RTHwasan
7983
SOURCES ${HWASAN_RTL_SOURCES}
8084
ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
8185
CFLAGS ${HWASAN_RTL_CFLAGS}
82-
DEFS ${HWASAN_DEFINITIONS})
86+
DEFS ${HWASAN_DEFINITIONS}
87+
DEPS ${HWASAN_DEPS})
8388
add_compiler_rt_object_libraries(RTHwasan_cxx
8489
ARCHS ${HWASAN_SUPPORTED_ARCH}
8590
SOURCES ${HWASAN_RTL_CXX_SOURCES}
8691
ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
8792
CFLAGS ${HWASAN_RTL_CFLAGS}
88-
DEFS ${HWASAN_DEFINITIONS})
93+
DEFS ${HWASAN_DEFINITIONS}
94+
DEPS ${HWASAN_DEPS})
8995
add_compiler_rt_object_libraries(RTHwasan_dynamic
9096
ARCHS ${HWASAN_SUPPORTED_ARCH}
9197
SOURCES ${HWASAN_RTL_SOURCES} ${HWASAN_RTL_CXX_SOURCES}
9298
ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
9399
CFLAGS ${HWASAN_DYNAMIC_CFLAGS}
94-
DEFS ${HWASAN_DEFINITIONS})
100+
DEFS ${HWASAN_DEFINITIONS}
101+
DEPS ${HWASAN_DEPS})
95102

96103
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "")
97104
add_compiler_rt_object_libraries(RTHwasan_dynamic_version_script_dummy
98105
ARCHS ${HWASAN_SUPPORTED_ARCH}
99106
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
100107
CFLAGS ${HWASAN_DYNAMIC_CFLAGS}
101-
DEFS ${HWASAN_DEFINITIONS})
108+
DEFS ${HWASAN_DEFINITIONS}
109+
DEPS ${HWASAN_DEPS})
102110

103111
foreach(arch ${HWASAN_SUPPORTED_ARCH})
104112
add_compiler_rt_runtime(clang_rt.hwasan

compiler-rt/lib/profile/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ endif()
113113

114114
# We don't use the C++ Standard Library here, so avoid including it by mistake.
115115
append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ EXTRA_FLAGS)
116+
# Remove -stdlib= which is unused when passing -nostdinc++.
117+
string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
116118

117119
# This appears to be a C-only warning banning the use of locals in aggregate
118120
# initializers. All other compilers accept this, though.

compiler-rt/lib/xray/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ set(XRAY_COMMON_RUNTIME_OBJECT_LIBS
149149
RTSanitizerCommon
150150
RTSanitizerCommonLibc)
151151

152-
# XRay uses C++ standard library headers so drop -nostdinc++.
153-
list_filter(XRAY_CFLAGS "-nostdinc++")
154152
if (TARGET cxx-headers OR HAVE_LIBCXX)
155153
set(XRAY_DEPS cxx-headers)
156154
endif()

0 commit comments

Comments
 (0)