From: Kefu Chai Date: Mon, 22 Oct 2018 06:06:38 +0000 (+0800) Subject: cmake,ceph.in: preload libasan if WITH_ASAN X-Git-Tag: v14.1.0~1119^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fd58e5d4ad2035ce66b6a3de8a0967e75cb985de;p=ceph.git cmake,ceph.in: preload libasan if WITH_ASAN we need to preload libasan.so as the python exectuable is not likely to be compiled with ASan enabled. see: https://github.com/google/sanitizers/wiki/AddressSanitizerAsDso#asan-and-ld_preload just to ease the use of ASan, for fine-tuned behaviour, use `ASAN_OPTIONS`. Signed-off-by: Kefu Chai --- diff --git a/cmake/modules/FindSanitizers.cmake b/cmake/modules/FindSanitizers.cmake index 648edc67f506..652ee659c9b2 100644 --- a/cmake/modules/FindSanitizers.cmake +++ b/cmake/modules/FindSanitizers.cmake @@ -29,6 +29,15 @@ foreach(component ${Sanitizers_FIND_COMPONENTS}) list(APPEND Sanitizers_OPTIONS "${Sanitizers_${component}_COMPILE_OPTIONS}") endforeach() +if(Sanitizers_address_COMPILE_OPTIONS OR Sanitizers_leak_COMPILE_OPTIONS) + # ASAN_LIBRARY will be read by ceph.in to preload the asan library + find_library(ASAN_LIBRARY + NAMES + libasan.so.5 + libasan.so.4 + libasan.so.3) +endif() + if(Sanitizers_OPTIONS) string(REPLACE ";" "," Sanitizers_COMPILE_OPTIONS diff --git a/src/ceph.in b/src/ceph.in index 82d6239486cb..7a205c388675 100755 --- a/src/ceph.in +++ b/src/ceph.in @@ -68,7 +68,7 @@ MYPDIR = os.path.dirname(MYDIR) DEVMODEMSG = '*** DEVELOPER MODE: setting PATH, PYTHONPATH and LD_LIBRARY_PATH ***' -def respawn_in_path(lib_path, pybind_path, pythonlib_path): +def respawn_in_path(lib_path, pybind_path, pythonlib_path, asan_lib_path): execv_cmd = [] if 'CEPH_DBG' in os.environ: execv_cmd += ['@PYTHON_EXECUTABLE@', '-mpdb'] @@ -79,6 +79,8 @@ def respawn_in_path(lib_path, pybind_path, pythonlib_path): lib_path_var = "LD_LIBRARY_PATH" execv_cmd += sys.argv + if asan_lib_path: + os.environ['LD_PRELOAD'] = asan_lib_path if lib_path_var in os.environ: if lib_path not in os.environ[lib_path_var]: os.environ[lib_path_var] += ':' + lib_path @@ -114,8 +116,9 @@ def get_cmake_variables(names): if os.path.exists(os.path.join(MYPDIR, "CMakeCache.txt")) \ and os.path.exists(os.path.join(MYPDIR, "bin/init-ceph")): - src_path = get_cmake_variables(["ceph_SOURCE_DIR"])["ceph_SOURCE_DIR"] - + vars = get_cmake_variables(["ceph_SOURCE_DIR", "ASAN_LIBRARY"]) + src_path = vars["ceph_SOURCE_DIR"] + asan_lib_path = vars["ASAN_LIBRARY"] if src_path is None: # Huh, maybe we're not really in a cmake environment? pass @@ -128,7 +131,7 @@ if os.path.exists(os.path.join(MYPDIR, "CMakeCache.txt")) \ "cython_modules", get_pythonlib_dir()) - respawn_in_path(lib_path, pybind_path, pythonlib_path) + respawn_in_path(lib_path, pybind_path, pythonlib_path, asan_lib_path) if 'PATH' in os.environ and bin_path not in os.environ['PATH']: os.environ['PATH'] = os.pathsep.join([bin_path, os.environ['PATH']])