[compiler-rt] r199655 - [msandr] Access app TLS directly in native exec mode.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Mon Jan 20 05:09:29 PST 2014


Author: eugenis
Date: Mon Jan 20 07:09:29 2014
New Revision: 199655

URL: http://llvm.org/viewvc/llvm-project?rev=199655&view=rev
Log:
[msandr] Access app TLS directly in native exec mode.

In optimized hybrid execution we do not use DynamoRIO private loader, which
mangles TLS access, so we can access the application's TLS directly.

Patch by Qin Zhao.

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

Modified: compiler-rt/trunk/lib/msandr/msandr.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msandr/msandr.cc?rev=199655&r1=199654&r2=199655&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msandr/msandr.cc (original)
+++ compiler-rt/trunk/lib/msandr/msandr.cc Mon Jan 20 07:09:29 2014
@@ -92,6 +92,10 @@
 # define SHADOW_MEMORY_MASK 0x3fffffffffffULL
 #endif /* MSANDR_STANDALONE_TEST */
 
+typedef void *(*WrapperFn)(void *);
+extern "C" void __msan_set_indirect_call_wrapper(WrapperFn wrapper);
+extern "C" void __msan_dr_is_initialized();
+
 namespace {
 
 int msan_retval_tls_offset;
@@ -366,8 +370,18 @@ void InstrumentReturn(void *drcontext, i
                                        OPSZ_PTR),
              OPND_CREATE_INT32(0)));
 #else  /* !MSANDR_STANDALONE_TEST */
+# ifdef MSANDR_NATIVE_EXEC
+  /* For optimized native exec, -mangle_app_seg and -private_loader are turned off,
+   * so we can reference msan_retval_tls_offset directly.
+   */
+  PRE(instr,
+      mov_st(drcontext,
+             opnd_create_far_base_disp(DR_SEG_FS, DR_REG_NULL, DR_REG_NULL, 0,
+                                       msan_retval_tls_offset, OPSZ_PTR),
+             OPND_CREATE_INT32(0)));
+# else /* !MSANDR_NATIVE_EXEC */
   /* XXX: the code below only works if -mangle_app_seg and -private_loader, 
-   * which is turned of for optimized native exec
+   * which is turned off for optimized native exec
    */
   dr_save_reg(drcontext, bb, instr, DR_REG_XAX, SPILL_SLOT_1);
 
@@ -382,7 +396,7 @@ void InstrumentReturn(void *drcontext, i
              OPND_CREATE_INT32(0)));
 
   dr_restore_reg(drcontext, bb, instr, DR_REG_XAX, SPILL_SLOT_1);
-
+# endif /* !MSANDR_NATIVE_EXEC */
   // The original instruction is left untouched. The above instrumentation is just
   // a prefix.
 #endif  /* !MSANDR_STANDALONE_TEST */
@@ -403,6 +417,16 @@ void InstrumentIndirectBranch(void *drco
                  OPND_CREATE_INT32(0)));
   }
 #else  /* !MSANDR_STANDALONE_TEST */
+# ifdef MSANDR_NATIVE_EXEC
+  for (int i = 0; i < NUM_TLS_PARAM; ++i) {
+    PRE(instr,
+        mov_st(drcontext,
+               opnd_create_far_base_disp(DR_SEG_FS, DR_REG_NULL, DR_REG_NULL, 0,
+                                         msan_param_tls_offset + i*sizeof(void*),
+                                         OPSZ_PTR),
+               OPND_CREATE_INT32(0)));
+  }
+# else /* !MSANDR_NATIVE_EXEC */
   /* XXX: the code below only works if -mangle_app_seg and -private_loader, 
    * which is turned off for optimized native exec
    */
@@ -422,7 +446,7 @@ void InstrumentIndirectBranch(void *drco
   }
 
   dr_restore_reg(drcontext, bb, instr, DR_REG_XAX, SPILL_SLOT_1);
-
+# endif /* !MSANDR_NATIVE_EXEC */
   // The original instruction is left untouched. The above instrumentation is just
   // a prefix.
 #endif  /* !MSANDR_STANDALONE_TEST */
@@ -869,6 +893,8 @@ DR_EXPORT void dr_init(client_id_t id) {
   drmgr_register_module_load_event(event_module_load);
   drmgr_register_module_unload_event(event_module_unload);
 #endif /* MSANDR_NATIVE_EXEC */
+  __msan_dr_is_initialized();
+  __msan_set_indirect_call_wrapper(dr_app_handle_mbr_target);
   if (VERBOSITY > 0)
     dr_printf("==MSANDR== Starting!\n");
 }





More information about the llvm-commits mailing list