Skip to content

Commit

Permalink
[#287] Add support for Address Sanitizer (ASAN)
Browse files Browse the repository at this point in the history
Requires irods-dev, irods-runtime, and irods-server packages
built with ASAN enabled. Also adds an option to the build
hook to enable ASAN from the development environment.
  • Loading branch information
alanking committed Dec 20, 2024
1 parent 574c07a commit 6ea5c5e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
30 changes: 29 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set(IRODS_PACKAGE_REVISION "0")

include(IrodsCXXCompiler)
set(CMAKE_CXX_STANDARD ${IRODS_CXX_STANDARD})
set(CMAKE_MODULE_LINKER_FLAGS_INIT "-Wl,--enable-new-dtags -Wl,--as-needed -Wl,-z,defs")
set(CMAKE_MODULE_LINKER_FLAGS_INIT "-Wl,--enable-new-dtags -Wl,--as-needed")
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE_INIT "-Wl,--gc-sections -Wl,-z,combreloc")
include(IrodsRunpathDefaults)

Expand Down Expand Up @@ -39,6 +39,34 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fpermissive>)
endif()

option(IRODS_ENABLE_ADDRESS_SANITIZER "Enables detection of memory leaks and other features provided by Address Sanitizer." OFF)
if (IRODS_ENABLE_ADDRESS_SANITIZER)
# Make sure the correct llvm-symbolizer binary is available to Address Sanitizer. This binary
# allows debug symbols to be reported appropriately. There are two ways to do this:
#
# export PATH=/opt/irods-externals/clang13.0.1-0/bin:$PATH
#
# - or -
#
# export ASAN_SYMBOLIZER_PATH=/opt/irods-externals/clang13.0.1-0/bin/llvm-symbolizer
#
# detect_container_overflow is disabled to guard against false positives which occur when
# parts of the binary are compiled with ASAN and other parts are not.
add_compile_definitions(IRODS_ADDRESS_SANITIZER_DEFAULT_OPTIONS="log_path=/tmp/irods_storage_tiering_asan_output:detect_container_overflow=0")
add_compile_options(
-fsanitize=address
-fno-omit-frame-pointer
-fno-optimize-sibling-calls
-O1)
add_link_options(
-fsanitize=address
-fno-omit-frame-pointer
-fno-optimize-sibling-calls
-O1)
else()
set(CMAKE_MODULE_LINKER_FLAGS_INIT "${CMAKE_MODULE_LINKER_FLAGS_INIT} -Wl,-z,defs")
endif()

if (NOT DEFINED THREADS_PREFER_PTHREAD_FLAG)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
endif()
Expand Down
12 changes: 8 additions & 4 deletions irods_consortium_continuous_integration_build_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ def copy_output_packages(build_directory, output_root_directory):
irods_python_ci_utilities.append_os_specific_directory(output_root_directory),
lambda s:s.endswith(irods_python_ci_utilities.get_package_suffix()))

def main(build_directory, output_root_directory, irods_packages_root_directory, externals_directory, debug_build=False):
def main(build_directory, output_root_directory, irods_packages_root_directory, externals_directory, debug_build=False, enable_asan=False):
install_building_dependencies(externals_directory)
if irods_packages_root_directory:
irods_python_ci_utilities.install_irods_dev_and_runtime_packages(irods_packages_root_directory)
build_directory = os.path.abspath(build_directory or tempfile.mkdtemp(prefix='irods_storage_tiering_plugin_build_directory'))
build_type = "Debug" if debug_build else "Release"
cmake_command = ['cmake', f"-DCMAKE_BUILD_TYPE={build_type}", os.path.dirname(os.path.realpath(__file__))]
print(cmake_command)
cmake_options = [f"-DCMAKE_BUILD_TYPE={build_type}"]
if enable_asan:
cmake_options.append("-DIRODS_ENABLE_ADDRESS_SANITIZER=YES")
cmake_command = ['cmake', os.path.dirname(os.path.realpath(__file__))] + cmake_options
irods_python_ci_utilities.subprocess_get_output(cmake_command, check_rc=True, cwd=build_directory)
irods_python_ci_utilities.subprocess_get_output(['make', '-j', str(multiprocessing.cpu_count()), 'package'], check_rc=True, cwd=build_directory)
if output_root_directory:
Expand All @@ -79,10 +81,12 @@ def main(build_directory, output_root_directory, irods_packages_root_directory,
parser.add_argument('--irods_packages_root_directory')
parser.add_argument('--externals_packages_directory')
parser.add_argument('--debug_build', action='store_true')
parser.add_argument("--enable_address_sanitizer", dest="enable_asan", action="store_true")
args = parser.parse_args()

main(args.build_directory,
args.output_root_directory,
args.irods_packages_root_directory,
args.externals_packages_directory,
args.debug_build)
args.debug_build,
args.enable_asan)

0 comments on commit 6ea5c5e

Please sign in to comment.