[compiler-rt] r223517 - [DFSAN][MIPS] adding support of DFSAN for MIPS64

Peter Collingbourne peter at pcc.me.uk
Fri Dec 5 13:22:37 PST 2014


Author: pcc
Date: Fri Dec  5 15:22:36 2014
New Revision: 223517

URL: http://llvm.org/viewvc/llvm-project?rev=223517&view=rev
Log:
[DFSAN][MIPS] adding support of DFSAN for MIPS64

Minor changes to enable DFSAN on MIPS64

Patch by Kumar Sukhani!

Differential Revision: http://reviews.llvm.org/D6437

Modified:
    compiler-rt/trunk/cmake/config-ix.cmake
    compiler-rt/trunk/lib/dfsan/CMakeLists.txt
    compiler-rt/trunk/lib/dfsan/dfsan.cc
    compiler-rt/trunk/lib/dfsan/dfsan.h

Modified: compiler-rt/trunk/cmake/config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/config-ix.cmake?rev=223517&r1=223516&r2=223517&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/config-ix.cmake (original)
+++ compiler-rt/trunk/cmake/config-ix.cmake Fri Dec  5 15:22:36 2014
@@ -173,7 +173,7 @@ filter_available_targets(SANITIZER_COMMO
   x86_64 i386 i686 powerpc64 powerpc64le arm aarch64 mips mips64 mipsel mips64el)
 filter_available_targets(ASAN_SUPPORTED_ARCH
   x86_64 i386 i686 powerpc64 powerpc64le arm mips mipsel mips64 mips64el)
-filter_available_targets(DFSAN_SUPPORTED_ARCH x86_64)
+filter_available_targets(DFSAN_SUPPORTED_ARCH x86_64 mips64 mips64el)
 filter_available_targets(LSAN_SUPPORTED_ARCH x86_64)
 # LSan common files should be available on all architectures supported
 # by other sanitizers (even if they build into dummy object files).

Modified: compiler-rt/trunk/lib/dfsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/CMakeLists.txt?rev=223517&r1=223516&r2=223517&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/dfsan/CMakeLists.txt Fri Dec  5 15:22:36 2014
@@ -11,8 +11,7 @@ append_list_if(COMPILER_RT_HAS_FFREESTAN
 
 # Static runtime library.
 add_custom_target(dfsan)
-set(arch "x86_64")
-if(CAN_TARGET_${arch})
+foreach(arch ${DFSAN_SUPPORTED_ARCH})
   set(DFSAN_CFLAGS ${DFSAN_COMMON_CFLAGS})
   append_list_if(COMPILER_RT_HAS_FPIE_FLAG -fPIE DFSAN_CFLAGS)
   add_compiler_rt_runtime(clang_rt.dfsan-${arch} ${arch} STATIC
@@ -30,7 +29,7 @@ if(CAN_TARGET_${arch})
   add_dependencies(dfsan
     clang_rt.dfsan-${arch}
     clang_rt.dfsan-${arch}-symbols)
-endif()
+endforeach()
 
 set(dfsan_abilist_filename ${COMPILER_RT_OUTPUT_DIR}/dfsan_abilist.txt)
 add_custom_target(dfsan_abilist ALL

Modified: compiler-rt/trunk/lib/dfsan/dfsan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/dfsan.cc?rev=223517&r1=223516&r2=223517&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/dfsan.cc (original)
+++ compiler-rt/trunk/lib/dfsan/dfsan.cc Fri Dec  5 15:22:36 2014
@@ -63,12 +63,37 @@ SANITIZER_INTERFACE_ATTRIBUTE THREADLOCA
 // account for the double byte representation of shadow labels and move the
 // address into the shadow memory range.  See the function shadow_for below.
 
+// On Linux/MIPS64, memory is laid out as follows:
+//
+// +--------------------+ 0x10000000000 (top of memory)
+// | application memory |
+// +--------------------+ 0xF000008000 (kAppAddr)
+// |                    |
+// |       unused       |
+// |                    |
+// +--------------------+ 0x2200000000 (kUnusedAddr)
+// |    union table     |
+// +--------------------+ 0x2000000000 (kUnionTableAddr)
+// |   shadow memory    |
+// +--------------------+ 0x0000010000 (kShadowAddr)
+// | reserved by kernel |
+// +--------------------+ 0x0000000000
+
 typedef atomic_dfsan_label dfsan_union_table_t[kNumLabels][kNumLabels];
 
+#if defined(__x86_64__)
 static const uptr kShadowAddr = 0x10000;
 static const uptr kUnionTableAddr = 0x200000000000;
 static const uptr kUnusedAddr = kUnionTableAddr + sizeof(dfsan_union_table_t);
 static const uptr kAppAddr = 0x700000008000;
+#elif defined(__mips64)
+static const uptr kShadowAddr = 0x10000;
+static const uptr kUnionTableAddr = 0x2000000000;
+static const uptr kUnusedAddr = kUnionTableAddr + sizeof(dfsan_union_table_t);
+static const uptr kAppAddr = 0xF000008000;
+#else
+# error "DFSan not supported for this platform!"
+#endif
 
 static atomic_dfsan_label *union_table(dfsan_label l1, dfsan_label l2) {
   return &(*(dfsan_union_table_t *) kUnionTableAddr)[l1][l2];

Modified: compiler-rt/trunk/lib/dfsan/dfsan.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/dfsan.h?rev=223517&r1=223516&r2=223517&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/dfsan.h (original)
+++ compiler-rt/trunk/lib/dfsan/dfsan.h Fri Dec  5 15:22:36 2014
@@ -44,7 +44,11 @@ namespace __dfsan {
 void InitializeInterceptors();
 
 inline dfsan_label *shadow_for(void *ptr) {
+#if defined(__x86_64__)
   return (dfsan_label *) ((((uptr) ptr) & ~0x700000000000) << 1);
+#elif defined(__mips64)
+  return (dfsan_label *) ((((uptr) ptr) & ~0xF000000000) << 1);
+#endif
 }
 
 inline const dfsan_label *shadow_for(const void *ptr) {





More information about the llvm-commits mailing list