<div dir="ltr">Yes, double-checking on the handler side whether its resources are still operational, e.g. by calling weak_ptr::lock() may be a better idea than elimination of spurious handler calls in XRay at a cost of heavy synchronization objects. Ok, let's live with spurious handler calls.<div><br></div><div>Cheers,</div><div>Serge</div><div><div class="gmail_extra"><br><div class="gmail_quote">On 4 August 2016 at 10:57, Dean Michael Berris <span dir="ltr"><<a href="mailto:dean.berris@gmail.com" target="_blank">dean.berris@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On 4 Aug 2016, at 06:27, Serge Rogatch <<a href="mailto:serge.rogatch@gmail.com">serge.rogatch@gmail.com</a>> wrote:<br>
><br>
> Hi Dean,<br>
><br>
> I have a question about the following piece of code in compiler-rt/trunk/lib/xray/<wbr>xray_trampoline_x86.S :<br>
>   movq  _ZN6__<wbr>xray19XRayPatchedFunctionE(%<wbr>rip), %rax<br>
>   testq  %rax, %rax<br>
>   je  .Ltmp0<br>
><br>
>   // assume that %r10d has the function id.<br>
>   movl  %r10d, %edi<br>
>   xor  %esi,%esi<br>
>   callq  *%rax<br>
> What happens if someone unsets the handler function (i.e. calls __xray_remove_handler() ) or changes the handler (i.e. calls __xray_set_handler() with a different pointer to function) between "movq  _ZN6__<wbr>xray19XRayPatchedFunctionE(%<wbr>rip), %rax" and "callq  *%rax" ? I understood that the old handler will still be called, but isn't it a problem? What if the code removing the handler starts destructing some objects after that, so that a handler call would result in a crash or other bad things?<br>
<br>
</span>That would be unfortunate. :)<br>
<br>
Yes, you're right, it will be called despite having the handler be un-set from the global atomic. Though I'd suggest that log handler implementations really shouldn't be crashing, and should assume that it will be called at any given time (from multiple threads, so it should also be thread-safe). Consider also that we're taking a function pointer by design -- assuming that it will be a pointer to a function that will only deal with globals and the explicitly passed in arguments.<br>
<br>
An implementer of the log handler should really be responsible for "internal signalling" -- i.e. implementing it so that any required synchronisation happens internally.<br>
<br>
Does this help?<br>
<br>
PS. I think more definitive documentation for this is due, let me think about putting something some documentation on how to use XRay as it is currently implemented once we have the naive in-memory logging implementation land (<a href="https://reviews.llvm.org/D21982" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D21982</a>).<br>
<br>
Cheers<br>
<span class="HOEnZb"><font color="#888888"><br>
-- Dean<br>
<br>
</font></span></blockquote></div><br></div></div></div>