[compiler-rt] r193411 - [msandr] Add NATIVE_EXEC macro for building client for running in DynamoRIO hybrid mode only.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Fri Oct 25 07:57:03 PDT 2013


Author: eugenis
Date: Fri Oct 25 09:57:02 2013
New Revision: 193411

URL: http://llvm.org/viewvc/llvm-project?rev=193411&view=rev
Log:
[msandr] Add NATIVE_EXEC macro for building client for running in DynamoRIO hybrid mode only.

When running application in DynamoRIO hybrid mode only, only uninstrumented
modules will run in DynamoRIO and be instrumented by the client, so we do not
need module table in MSanDR.

Patch by Qin Zhao.


Modified:
    compiler-rt/trunk/lib/msandr/CMakeLists.txt
    compiler-rt/trunk/lib/msandr/msandr.cc

Modified: compiler-rt/trunk/lib/msandr/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msandr/CMakeLists.txt?rev=193411&r1=193410&r2=193411&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msandr/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/msandr/CMakeLists.txt Fri Oct 25 09:57:02 2013
@@ -4,6 +4,11 @@ if(DynamoRIO_DIR AND DrMemoryFramework_D
   find_package(DynamoRIO)
   find_package(DrMemoryFramework)
 
+  option(MSANDR_NATIVE_EXEC "Building msandr client for running in DynamoRIO hybrid mode, which allows some module running natively" OFF)
+  if (MSANDR_NATIVE_EXEC)
+    add_definitions(-DMSANDR_NATIVE_EXEC)
+  endif (MSANDR_NATIVE_EXEC)
+
   set(arch "x86_64")
   add_library(clang_rt.msandr-${arch} SHARED msandr.cc)
   configure_DynamoRIO_client(clang_rt.msandr-${arch})

Modified: compiler-rt/trunk/lib/msandr/msandr.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msandr/msandr.cc?rev=193411&r1=193410&r2=193411&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msandr/msandr.cc (original)
+++ compiler-rt/trunk/lib/msandr/msandr.cc Fri Oct 25 09:57:02 2013
@@ -62,6 +62,12 @@
 
 namespace {
 
+std::string g_app_path;
+
+int msan_retval_tls_offset;
+int msan_param_tls_offset;
+
+#ifndef MSANDR_NATIVE_EXEC
 class ModuleData {
 public:
   ModuleData();
@@ -78,11 +84,6 @@ public:
   bool executed_;
 };
 
-std::string g_app_path;
-
-int msan_retval_tls_offset;
-int msan_param_tls_offset;
-
 // A vector of loaded modules sorted by module bounds.  We lookup the current PC
 // in here from the bb event.  This is better than an rb tree because the lookup
 // is faster and the bb event occurs far more than the module load event.
@@ -99,6 +100,7 @@ ModuleData::ModuleData(const module_data
       // We'll check the black/white lists later and adjust this.
       should_instrument_(true), executed_(false) {
 }
+#endif /* !MSANDR_NATIVE_EXEC */
 
 int(*__msan_get_retval_tls_offset)();
 int(*__msan_get_param_tls_offset)();
@@ -319,6 +321,7 @@ void InstrumentIndirectBranch(void *drco
   // a prefix.
 }
 
+#ifndef MSANDR_NATIVE_EXEC
 // For use with binary search.  Modules shouldn't overlap, so we shouldn't have
 // to look at end_.  If that can happen, we won't support such an application.
 bool ModuleDataCompareStart(const ModuleData &left, const ModuleData &right) {
@@ -373,22 +376,26 @@ bool ShouldInstrumentPc(app_pc pc, Modul
   }
   return true;
 }
+#endif /* !NATIVE_CLIENT */
 
 // TODO(rnk): Make sure we instrument after __msan_init.
 dr_emit_flags_t
 event_basic_block_app2app(void *drcontext, void *tag, instrlist_t *bb,
                           bool for_trace, bool translating) {
+#ifndef MSANDR_NATIVE_EXEC
   app_pc pc = dr_fragment_app_pc(tag);
-
   if (ShouldInstrumentPc(pc, NULL))
     CHECK(drutil_expand_rep_string(drcontext, bb));
-
+#else  /* MSANDR_NATIVE_EXEC */
+  CHECK(drutil_expand_rep_string(drcontext, bb));
+#endif /* MSANDR_NATIVE_EXEC */
   return DR_EMIT_PERSISTABLE;
 }
 
 dr_emit_flags_t event_basic_block(void *drcontext, void *tag, instrlist_t *bb,
                                   bool for_trace, bool translating) {
   app_pc pc = dr_fragment_app_pc(tag);
+#ifndef MSANDR_NATIVE_EXEC
   ModuleData *mod_data;
 
   if (!ShouldInstrumentPc(pc, &mod_data))
@@ -411,6 +418,8 @@ dr_emit_flags_t event_basic_block(void *
           pc - mod_data->start_);
     }
   }
+#endif /* !MSANDR_NATIVE_EXEC */
+
   if (VERBOSITY > 1) {
     instrlist_disassemble(drcontext, pc, bb, STDOUT);
     instr_t *instr;
@@ -474,6 +483,7 @@ dr_emit_flags_t event_basic_block(void *
   return DR_EMIT_PERSISTABLE;
 }
 
+#ifndef MSANDR_NATIVE_EXEC
 void event_module_load(void *drcontext, const module_data_t *info,
                        bool loaded) {
   // Insert the module into the list while maintaining the ordering.
@@ -507,6 +517,7 @@ void event_module_unload(void *drcontext
         it->end_ == mod_data.end_ && it->path_ == mod_data.path_);
   g_module_list.erase(it);
 }
+#endif /* !MSANDR_NATIVE_EXEC */
 
 void event_exit() {
   // Clean up so DR doesn't tell us we're leaking memory.
@@ -551,6 +562,7 @@ bool drsys_iter_memarg_cb(drsys_arg_t *a
     drsys_syscall_t *syscall = (drsys_syscall_t *)user_data;
     const char *name;
     res = drsys_syscall_name(syscall, &name);
+    CHECK(res == DRMF_SUCCESS);
     dr_printf("drsyscall: syscall '%s' arg %d wrote range [%p, %p)\n",
               name, arg->ordinal, arg->start_addr,
               (char *)arg->start_addr + sz);
@@ -719,8 +731,10 @@ DR_EXPORT void dr_init(client_id_t id) {
 
   drmgr_register_bb_app2app_event(event_basic_block_app2app, &priority);
   drmgr_register_bb_instru2instru_event(event_basic_block, &priority);
+#ifndef MSANDR_NATIVE_EXEC
   drmgr_register_module_load_event(event_module_load);
   drmgr_register_module_unload_event(event_module_unload);
+#endif /* MSANDR_NATIVE_EXEC */
   if (VERBOSITY > 0)
     dr_printf("==MSANDR== Starting!\n");
 }





More information about the llvm-commits mailing list