[PATCH] make msandr access tls directly

Qin Zhao zhaoqin at google.com
Tue Jan 21 07:26:54 PST 2014



================
Comment at: msandr.cc:373
@@ -368,1 +372,3 @@
 #else  /* !MSANDR_STANDALONE_TEST */
+# ifdef MSANDR_NATIVE_EXEC
+  /* For optimized native exec, -mangle_app_seg and -private_loader are turned off,
----------------
Evgeniy Stepanov wrote:
> In fact, since we control all transitions between instrumented and uninstrumented code, we can do this cleanup exactly once per transition.
> 
> This memory is only ever written non-zero values in instrumented code.
> 
> If I understand correctly, this is a correctness rather then optimization change. If so, LGTM, and the above can be addressed later.
In old mandr, the private loader is used and the app's TLS is mangled, so any app TLS (including msan's TLS) access should first get the segment base into eax, then access the TLS slots via eax. Thus the old code would be something like
save %rax
mov seg_base => %rax
mov 0 => [%rax, offset] 
restore %rax
And the code is generated by line 383:398

In hybrid execution msandr, app's TLS is not mangled, so we can directly access the TLS field without help of %rax.
e.g. mov 0 => [fs: msan_retval_tls_offset].
So it is not optimization but make it correct in hybrid execution.

My understanding the code is it blindly mark return value as defined. 
You are right that we need do only once when return from non-native module to native module, but it need to detect if the target is in native module, so not that easy to do. Should be done in a separate CL.

Sorry my commit message is not clear enough.


================
Comment at: msandr.cc:420
@@ -405,1 +419,3 @@
 #else  /* !MSANDR_STANDALONE_TEST */
+# ifdef MSANDR_NATIVE_EXEC
+  for (int i = 0; i < NUM_TLS_PARAM; ++i) {
----------------
Evgeniy Stepanov wrote:
> The same as retval_tls.
The same as retval_tls :)


http://llvm-reviews.chandlerc.com/D2568



More information about the llvm-commits mailing list