Add address sanitizer build option
MODIFY
CMakeLists.txt
CMakeLists.txt
@@ -77,6 +77,8 @@ option(BUILD_TEST "Build tests" OFF)
option(BUILD_EXAMPLES "Build examples" OFF)
option(BUILD_BENCHMARKS "Build benchmarks" OFF)
option(DOWNLOAD_ROCPRIM "Download rocPRIM and do not search for rocPRIM package" OFF)
+option(BUILD_ADDRESS_SANITIZER "Build with address sanitizer enabled" OFF)
+
set(RNG_SEED_COUNT 0 CACHE STRING "Number of true random sequences to test each input size for")
set(PRNG_SEEDS 1 CACHE STRING "Seeds of pseudo random sequences to test each input size for")
@@ -105,6 +107,15 @@ else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
endif()
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --save-temps")
+
+# Address Sanitizer
+if(BUILD_ADDRESS_SANITIZER)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -shared-libasan")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -shared-libasan")
+ add_link_options(-fuse-ld=lld)
+endif()
+
# Get dependencies
include(cmake/Dependencies.cmake)

MODIFY
cmake/Summary.cmake
cmake/Summary.cmake
@@ -41,4 +41,5 @@ endif()
message(STATUS " BUILD_TEST : ${BUILD_TEST}")
message(STATUS " BUILD_EXAMPLES : ${BUILD_EXAMPLES}")
message(STATUS " BUILD_BENCHMARKS : ${BUILD_BENCHMARKS}")
+ message(STATUS " BUILD_ADDRESS_SANITIZER : ${BUILD_ADDRESS_SANITIZER}")
endfunction()

MODIFY
install
install
@@ -17,6 +17,7 @@ function display_help()
echo " [-c|--clients] build library clients too (combines with -i & -d)"
echo " [-g|--debug] -DCMAKE_BUILD_TYPE=Debug (default is =Release)"
echo " [--hip-clang] build library for amdgpu backend using hip-clang"
+ echo " [--address-sanitizer] build with address sanitizer enabled"
}
@@ -32,6 +33,7 @@ build_hip_clang=false
run_tests=false
rocm_path=/opt/rocm
build_relocatable=false
+build_address_sanitizer=false
# #################################################
# Parameter parsing
@@ -40,7 +42,7 @@ build_relocatable=false
# check if we have a modern version of getopt that can handle whitespace and long parameters
getopt -T
if [[ $? -eq 4 ]]; then
- GETOPT_PARSE=$(getopt --name "${0}" --longoptions help,install,clients,debug,hip-clang,test,package,relocatable --options hicdtprg -- "$@")
+ GETOPT_PARSE=$(getopt --name "${0}" --longoptions help,install,clients,debug,hip-clang,test,package,relocatable,address-sanitizer --options hicdtprg -- "$@")
else
echo "Need a new version of getopt"
exit 1
@@ -89,6 +91,9 @@ while true; do
--hip-clang)
build_hip_clang=true
shift ;;
+ --address-sanitizer)
+ build_address_sanitizer=true
+ shift ;;
--) shift ; break ;;
*) echo "Unexpected command line parameter received; aborting";
exit 1
@@ -129,20 +134,26 @@ fi
compiler="hipcc"
cmake_executable="cmake"
+cmake_common_options=""
if [[ "${build_clients}" == true ]]; then
build_test="-DBUILD_TEST=ON"
fi
+if [[ "${build_address_sanitizer}" == true ]]; then
+ cmake_common_options="$cmake_common_options -DBUILD_ADDRESS_SANITIZER=ON"
+fi
+
if [[ "${build_relocatable}" == true ]]; then
- CXX=$rocm_path/bin/${compiler} ${cmake_executable} \
+ CXX=$rocm_path/bin/${compiler} ${cmake_executable} ${cmake_common_options} \
-DCMAKE_INSTALL_PREFIX=${rocm_path} \
-DCMAKE_PREFIX_PATH="${rocm_path} ${rocm_path}/hip" \
-DCMAKE_MODULE_PATH="${rocm_path}/hip/cmake" \
-DROCPRIM_ROOT=${rocm_path}/rocprim ${build_test}\
../../. # or cmake-gui ../.
else
- CXX=$rocm_path/bin/${compiler} ${cmake_executable} ${build_test} -DCMAKE_BUILD_TYPE=${build_type} ../../. # or cmake-gui ../.
+ CXX=$rocm_path/bin/${compiler} ${cmake_executable} ${build_test} ${cmake_common_options} \
+ -DCMAKE_BUILD_TYPE=${build_type} ../../. # or cmake-gui ../.
fi
check_exit_code "$?"

Add address sanitizer build option (#175)