<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 7, 2014 at 12:10 PM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Tue, Oct 7, 2014 at 11:48 AM, Peter Collingbourne <span dir="ltr"><<a href="mailto:peter@pcc.me.uk" target="_blank">peter@pcc.me.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span>On Tue, Oct 07, 2014 at 10:04:30AM -0700, David Blaikie wrote:<br>
> Hi Peter,<br>
><br>
> After discovering several bugs in ArgumentPromotion and<br>
> DeadArgumentElimination where llvm::Functions were replaced with similar<br>
> functions (with the same name) to transform their type in some way, I<br>
> started looking at all calls to llvm::Function::takeName to see if there<br>
> were any other debug info quality bugs in similar callers.<br>
><br>
> One such caller is the DataFlowSanitizer, and I don't see any debug info<br>
> tests for this so I'm wondering what /should/ happen here.<br>
><br>
> Is DFSan+DebugInfo something that matters? I assume so.<br>
<br>
</span>It may be important in the future, but at the moment the dfsan runtime library<br>
does not make use of debug info. The debug info could still be useful for<br>
regular debugging tasks though.<br></blockquote><div><br></div></span><div>Yeah - that'd be the baseline. I assume some people probably care about being able to debug a dfsan binary. Not sure if your users have specifically highlighted this situation or come across the bugs I'm speculating about.</div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span>> It looks like DFSan is creating wrappers (in/around<br>
> DataFlowSanitizer.cpp:680-700) - when it does this, should it update the<br>
> debug info for these functions? Or are these internal instrumentation<br>
> functions & nothing to do with the code the user wrote? I can't quite tell<br>
> from the code.<br>
<br>
</span>The functions created by that part of the code replace the original functions,<br>
so they should inherit the debug info for those functions.<br></blockquote></span><div><br>Yep, that won't happen for free - we have to stitch it back into the debug info.<br> </div><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">But the code below that can also create wrapper functions which do not need<br>
debug info (lines 712-746). Wrappers normally show up for uninstrumented<br>
functions (e.g. main and many libc functions).<br>
<span><br>
> Could you provide any C/C++ source examples whis part of DFSan fires<br>
> reliably, so I could experiment with some examples and see how the debug<br>
> info looks?<br>
<br>
</span>This is an example of a program that exercises the replacement function and<br>
wrapper features.<br>
<br>
--------------------------------------------------------------------------------<br>
#include <stddef.h><br>
#include <string.h><br>
<br>
size_t len(size_t (*strlen_ptr)(const char *), const char *str) {<br>
  return strlen_ptr(str);<br>
}<br>
<br>
int main(void) {<br>
  return len(strlen, "foo");<br>
}<br>
--------------------------------------------------------------------------------<br>
<br>
In this example, 'len' is rewritten to 'dfs$len', 'main' keeps its original<br>
name (the pass treats it as an uninstrumented function), and wrappers are<br>
created for 'main' and 'strlen' (the wrapper for 'main' is unused as the<br>
C runtime calls the regular 'main' function directly).<br></blockquote><div><br></div></span><div>OK, so when you say wrappers are created - where does the name go? "main" keeps the name? (it's important which way this transformation is done - if the guts of main are moved to a new function and the name moved as well, that's not the same as keeping the same function as far as debug info metadata is concerned)</div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I compile this with '-O0 -g'. A 'break main'/'run'/'break strlen'/'cont'<br>
gives a relevant stack trace:<br>
<br>
#0  __strlen_sse2_pminub () at ../sysdeps/x86_64/multiarch/strlen-sse2-pminub.S:33<br>
#1  0x00005555555587ff in __dfsw_strlen (s=0x55555556fe17 "foo", s_label=<optimized out>, ret_label=0x7fffffffddee)<br>
    at llvm/projects/compiler-rt/lib/dfsan/dfsan_custom.cc:203<br>
#2  0x000055555556bbdc in dfsw$strlen ()<br>
#3  0x000055555556bb51 in len (strlen_ptr=0x55555556bbc0 <dfsw$strlen>, str=0x55555556fe17 "foo") at strlen.c:5<br>
#4  0x000055555556bb96 in main ()<br>
<br>
In this stack trace, #2 is the compiler-generated wrapper function for strlen.<br>
<br>
It looks like the debug info for 'len' is preserved correctly, but I don't<br>
know why the debug info for 'main' is missing.<br></blockquote><div><br></div></span><div>Yeah - not quite sure either. I'll poke around with it for a little bit.</div></div></div></div></blockquote><div><br></div><div>DataFlowSanitizer.cpp:719: F.replaceAllUsesWith(WrappedFnCst);<br><br>replaces the debug info metadata's pointer to main with a pointer to dfsw$main (this issue doesn't come up with DAE or ArgPromo because they both don</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
Thanks,<span class=""><font color="#888888"><br>
<span><font color="#888888">--<br>
Peter<br>
</font></span></font></span></blockquote></div><br></div></div>
</blockquote></div><br></div></div>