Skip to content

Commit

Permalink
Ignore UserPresets and Use only C compiler for sanitizers (HDFGroup#4066
Browse files Browse the repository at this point in the history
)

* Remove user presets file

* Only use C compiler for sanitzers
  • Loading branch information
byrnHDF authored Mar 5, 2024
1 parent f5f6975 commit 42c7e1d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 266 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ src/H5version.h

/.classpath
/CMakeUserPresets.json
HDF5Examples/CMakeUserPresets.json
244 changes: 0 additions & 244 deletions HDF5Examples/CMakeUserPresets.json

This file was deleted.

44 changes: 22 additions & 22 deletions config/sanitizer/sanitizers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations under
# the License.

include(CheckCXXSourceCompiles)

set(USE_SANITIZER
""
CACHE
Expand Down Expand Up @@ -44,22 +42,24 @@ function(test_san_flags return_var flags)
unset(${return_var} CACHE)
set(FLAGS_BACKUP ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "${flags}")
check_cxx_source_compiles("int main() { return 0; }" ${return_var})
check_c_source_compiles("int main() { return 0; }" ${return_var})
set(CMAKE_REQUIRED_FLAGS "${FLAGS_BACKUP}")
set(CMAKE_REQUIRED_QUIET "${QUIET_BACKUP}")
endfunction()

message(STATUS "USE_SANITIZER=${USE_SANITIZER}, CMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID}")
if(USE_SANITIZER)
if(CMAKE_C_COMPILER_ID MATCHES "IntelLLVM" OR CMAKE_C_COMPILER_ID MATCHES "[Cc]lang")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

unset(SANITIZER_SELECTED_FLAGS)

if(UNIX)
append("-fno-omit-frame-pointer" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
append("-fno-omit-frame-pointer" CMAKE_C_FLAGS)
message(STATUS "Building with sanitize, base flags=${CMAKE_C_SANITIZER_FLAGS}")

if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
append("-O1" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
append("-O1" CMAKE_C_FLAGS)
endif()

if(USE_SANITIZER MATCHES "([Aa]ddress)")
Expand All @@ -72,10 +72,10 @@ if(USE_SANITIZER)
append("${SANITIZER_ADDR_FLAG}" SANITIZER_SELECTED_FLAGS)

if(AFL)
append_quoteless(AFL_USE_ASAN=1 CMAKE_C_COMPILER_LAUNCHER CMAKE_CXX_COMPILER_LAUNCHER)
append_quoteless(AFL_USE_ASAN=1 CMAKE_C_COMPILER_LAUNCHER)
endif()
else()
message(FATAL_ERROR "Address sanitizer not available for ${CMAKE_CXX_COMPILER}")
message(FATAL_ERROR "Address sanitizer not available for ${CMAKE_C_COMPILER}")
endif()
endif()

Expand All @@ -98,10 +98,10 @@ if(USE_SANITIZER)
append("${SANITIZER_MEM_FLAG}" SANITIZER_SELECTED_FLAGS)

if(AFL)
append_quoteless(AFL_USE_MSAN=1 CMAKE_C_COMPILER_LAUNCHER CMAKE_CXX_COMPILER_LAUNCHER)
append_quoteless(AFL_USE_MSAN=1 CMAKE_C_COMPILER_LAUNCHER)
endif()
else()
message(FATAL_ERROR "Memory [With Origins] sanitizer not available for ${CMAKE_CXX_COMPILER}")
message(FATAL_ERROR "Memory [With Origins] sanitizer not available for ${CMAKE_C_COMPILER}")
endif()
endif()

Expand All @@ -117,10 +117,10 @@ if(USE_SANITIZER)
append("${SANITIZER_UB_FLAG}" SANITIZER_SELECTED_FLAGS)

if(AFL)
append_quoteless(AFL_USE_UBSAN=1 CMAKE_C_COMPILER_LAUNCHER CMAKE_CXX_COMPILER_LAUNCHER)
append_quoteless(AFL_USE_UBSAN=1 CMAKE_C_COMPILER_LAUNCHER)
endif()
else()
message(FATAL_ERROR "Undefined Behaviour sanitizer not available for ${CMAKE_CXX_COMPILER}")
message(FATAL_ERROR "Undefined Behaviour sanitizer not available for ${CMAKE_C_COMPILER}")
endif()
endif()

Expand All @@ -133,10 +133,10 @@ if(USE_SANITIZER)
append("${SANITIZER_THREAD_FLAG}" SANITIZER_SELECTED_FLAGS)

if(AFL)
append_quoteless(AFL_USE_TSAN=1 CMAKE_C_COMPILER_LAUNCHER CMAKE_CXX_COMPILER_LAUNCHER)
append_quoteless(AFL_USE_TSAN=1 CMAKE_C_COMPILER_LAUNCHER)
endif()
else()
message(FATAL_ERROR "Thread sanitizer not available for ${CMAKE_CXX_COMPILER}")
message(FATAL_ERROR "Thread sanitizer not available for ${CMAKE_C_COMPILER}")
endif()
endif()

Expand All @@ -149,10 +149,10 @@ if(USE_SANITIZER)
append("${SANITIZER_LEAK_FLAG}" SANITIZER_SELECTED_FLAGS)

if(AFL)
append_quoteless(AFL_USE_LSAN=1 CMAKE_C_COMPILER_LAUNCHER CMAKE_CXX_COMPILER_LAUNCHER)
append_quoteless(AFL_USE_LSAN=1 CMAKE_C_COMPILER_LAUNCHER)
endif()
else()
message(FATAL_ERROR "Thread sanitizer not available for ${CMAKE_CXX_COMPILER}")
message(FATAL_ERROR "Thread sanitizer not available for ${CMAKE_C_COMPILER}")
endif()
endif()

Expand All @@ -165,28 +165,28 @@ if(USE_SANITIZER)
append("${SANITIZER_LEAK_FLAG}" SANITIZER_SELECTED_FLAGS)

if(AFL)
append_quoteless(AFL_USE_CFISAN=1 CMAKE_C_COMPILER_LAUNCHER CMAKE_CXX_COMPILER_LAUNCHER)
append_quoteless(AFL_USE_CFISAN=1 CMAKE_C_COMPILER_LAUNCHER)
endif()
else()
message(FATAL_ERROR "Control Flow Integrity(CFI) sanitizer not available for ${CMAKE_CXX_COMPILER}")
message(FATAL_ERROR "Control Flow Integrity(CFI) sanitizer not available for ${CMAKE_C_COMPILER}")
endif()
endif()

message(STATUS "Sanitizer flags: ${SANITIZER_SELECTED_FLAGS}")
test_san_flags(SANITIZER_SELECTED_COMPATIBLE ${SANITIZER_SELECTED_FLAGS})
if(SANITIZER_SELECTED_COMPATIBLE)
message(STATUS " Building with ${SANITIZER_SELECTED_FLAGS}")
append("${SANITIZER_SELECTED_FLAGS}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
append("${SANITIZER_SELECTED_FLAGS}" CMAKE_C_FLAGS)
else()
message(FATAL_ERROR " Sanitizer flags ${SANITIZER_SELECTED_FLAGS} are not compatible.")
message(FATAL_ERROR "Unsupported value of USE_SANITIZER: ${USE_SANITIZER}")
endif()
elseif(MSVC)
if(USE_SANITIZER MATCHES "([Aa]ddress)")
message(STATUS "Building with Address sanitizer")
append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
append("-fsanitize=address" CMAKE_C_FLAGS)

if(AFL)
append_quoteless(AFL_USE_ASAN=1 CMAKE_C_COMPILER_LAUNCHER CMAKE_CXX_COMPILER_LAUNCHER)
append_quoteless(AFL_USE_ASAN=1 CMAKE_C_COMPILER_LAUNCHER)
endif()
else()
message(FATAL_ERROR "This sanitizer not yet supported in the MSVC environment: ${USE_SANITIZER}")
Expand All @@ -197,7 +197,7 @@ if(USE_SANITIZER)
elseif(MSVC)
if(USE_SANITIZER MATCHES "([Aa]ddress)")
message(STATUS "Building with Address sanitizer")
append("/fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
append("/fsanitize=address" CMAKE_C_FLAGS)
else()
message(FATAL_ERROR "This sanitizer not yet supported in the MSVC environment: ${USE_SANITIZER}")
endif()
Expand Down

0 comments on commit 42c7e1d

Please sign in to comment.