]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake,ceph.in: preload libasan if WITH_ASAN
authorKefu Chai <kchai@redhat.com>
Mon, 22 Oct 2018 06:06:38 +0000 (14:06 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 22 Oct 2018 06:40:03 +0000 (14:40 +0800)
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 <kchai@redhat.com>
cmake/modules/FindSanitizers.cmake
src/ceph.in

index 648edc67f50667c0d477ad302be87a09c8013275..652ee659c9b2988da21306299fd61352913995cd 100644 (file)
@@ -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
index 82d6239486cb4c97ce0a0e5a066c1483771606e0..7a205c3886758ba100ec7c4e35e952c57bade9b3 100755 (executable)
@@ -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']])