[compiler-rt] r316342 - [scudo] Add a shared runtime

Kostya Kortchinsky via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 23 09:27:48 PDT 2017


Author: cryptoad
Date: Mon Oct 23 09:27:47 2017
New Revision: 316342

URL: http://llvm.org/viewvc/llvm-project?rev=316342&view=rev
Log:
[scudo] Add a shared runtime

Summary:
Up to now, the Scudo cmake target only provided a static library that had to be
linked to an executable to benefit from the hardened allocator.
This introduces a shared library as well, that can be LD_PRELOAD'ed.

Reviewers: alekseyshl

Reviewed By: alekseyshl

Subscribers: srhines, mgorny, llvm-commits

Differential Revision: https://reviews.llvm.org/D38980

Added:
    compiler-rt/trunk/test/scudo/preload.cpp
Modified:
    compiler-rt/trunk/lib/scudo/CMakeLists.txt
    compiler-rt/trunk/test/scudo/lit.cfg

Modified: compiler-rt/trunk/lib/scudo/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/scudo/CMakeLists.txt?rev=316342&r1=316341&r2=316342&view=diff
==============================================================================
--- compiler-rt/trunk/lib/scudo/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/scudo/CMakeLists.txt Mon Oct 23 09:27:47 2017
@@ -30,15 +30,32 @@ if (COMPILER_RT_HAS_MCRC_FLAG)
 endif()
 
 if(COMPILER_RT_HAS_SCUDO)
+  set(SCUDO_DYNAMIC_LIBS ${SANITIZER_COMMON_LINK_LIBS})
+  append_list_if(COMPILER_RT_HAS_LIBDL dl SCUDO_DYNAMIC_LIBS)
+  append_list_if(COMPILER_RT_HAS_LIBRT rt SCUDO_DYNAMIC_LIBS)
+  append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread SCUDO_DYNAMIC_LIBS)
+  append_list_if(COMPILER_RT_HAS_LIBLOG log SCUDO_DYNAMIC_LIBS)
+
   foreach(arch ${SCUDO_SUPPORTED_ARCH})
     add_compiler_rt_runtime(clang_rt.scudo
       STATIC
       ARCHS ${arch}
       SOURCES ${SCUDO_SOURCES}
-              $<TARGET_OBJECTS:RTInterception.${arch}>
-              $<TARGET_OBJECTS:RTSanitizerCommonNoTermination.${arch}>
-              $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
+      OBJECT_LIBS RTSanitizerCommonNoTermination
+                  RTSanitizerCommonLibc
+                  RTInterception
+      CFLAGS ${SCUDO_CFLAGS}
+      PARENT_TARGET scudo)
+
+    add_compiler_rt_runtime(clang_rt.scudo
+      SHARED
+      ARCHS ${arch}
+      SOURCES ${SCUDO_SOURCES}
+      OBJECT_LIBS RTSanitizerCommonNoTermination
+                  RTSanitizerCommonLibc
+                  RTInterception
       CFLAGS ${SCUDO_CFLAGS}
+      LINK_LIBS ${SCUDO_DYNAMIC_LIBS}
       PARENT_TARGET scudo)
   endforeach()
 endif()

Modified: compiler-rt/trunk/test/scudo/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/scudo/lit.cfg?rev=316342&r1=316341&r2=316342&view=diff
==============================================================================
--- compiler-rt/trunk/test/scudo/lit.cfg (original)
+++ compiler-rt/trunk/test/scudo/lit.cfg Mon Oct 23 09:27:47 2017
@@ -8,10 +8,10 @@ config.name = 'Scudo' + config.name_suff
 # Setup source root.
 config.test_source_root = os.path.dirname(__file__)
 
-# Path to the static library
-base_lib = os.path.join(config.compiler_rt_libdir,
-                        "libclang_rt.scudo-%s.a" % config.target_arch)
-whole_archive = "-Wl,-whole-archive %s -Wl,-no-whole-archive " % base_lib
+# Path to the shared & static libraries
+shared_libscudo = os.path.join(config.compiler_rt_libdir, "libclang_rt.scudo-%s.so" % config.target_arch)
+static_libscudo = os.path.join(config.compiler_rt_libdir, "libclang_rt.scudo-%s.a" % config.target_arch)
+whole_archive = "-Wl,-whole-archive %s -Wl,-no-whole-archive " % static_libscudo
 
 # Test suffixes.
 config.suffixes = ['.c', '.cc', '.cpp']
@@ -35,8 +35,9 @@ def build_invocation(compile_flags):
   return " " + " ".join([config.compile_wrapper, config.clang] + compile_flags) + " "                   
 
 # Add clang substitutions.
-config.substitutions.append(("%clang_scudo ",
-                             build_invocation(c_flags) + whole_archive))
+config.substitutions.append(("%clang ", build_invocation(c_flags)))
+config.substitutions.append(("%clang_scudo ", build_invocation(c_flags) + whole_archive))
+config.substitutions.append(("%shared_libscudo", shared_libscudo))
 
 # Platform-specific default SCUDO_OPTIONS for lit tests.
 default_scudo_opts = ''

Added: compiler-rt/trunk/test/scudo/preload.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/scudo/preload.cpp?rev=316342&view=auto
==============================================================================
--- compiler-rt/trunk/test/scudo/preload.cpp (added)
+++ compiler-rt/trunk/test/scudo/preload.cpp Mon Oct 23 09:27:47 2017
@@ -0,0 +1,20 @@
+// Test that the preloaded runtime works without linking the static library.
+
+// RUN: %clang %s -o %t
+// RUN: env LD_PRELOAD=%shared_libscudo not %run %t 2>&1 | FileCheck %s
+
+// This way of setting LD_PRELOAD does not work with Android test runner.
+// REQUIRES: !android
+
+#include <assert.h>
+#include <stdlib.h>
+
+int main(int argc, char *argv[]) {
+  void *p = malloc(sizeof(int));
+  assert(p);
+  free(p);
+  free(p);
+  return 0;
+}
+
+// CHECK: ERROR: invalid chunk state




More information about the llvm-commits mailing list