<div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">On Wed, Aug 7, 2013 at 2:12 PM, Sergey Matveev <span dir="ltr"><<a href="mailto:earthdok@google.com" target="_blank">earthdok@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><br>
<br>
================<br>
Comment at: lib/lsan/lit_tests/TestCases/leak_check_at_exit.cc:12<br>
@@ +11,3 @@<br>
+int main(int argc, char *argv[]) {<br>
+  printf("printf to break optimization\n");<br>
+  if (argc > 1)<br>
----------------<br>
</div><div class="im">Alexey Samsonov wrote:<br>
> Sergey Matveev wrote:<br>
> > Alexey Samsonov wrote:<br>
> > > Sergey Matveev wrote:<br>
> > > > Alexey Samsonov wrote:<br>
> > > > > Do you really need this printf here?<br>
> > > > Somehow atexit handlers are not invoked if main is a no-op. I didn't investigate further.<br>
> > > That is, LSan wouldn't run leak checking if main() is empty? I think it's<br>
> > > worth investigating.<br>
> > ><br>
> > Ok, there are actually 2 separate issues here.<br>
> > 1. FileCheck barks at empty input (the last invocation, where we make sure that leak detection is not invoked, doesnt' produce any output).<br>
> > 2. Standalone LSan does not use preinit_array for initialization. Instead it initializes whenever an intercepted function is called for the first time. So if main() is a no-op, LSan will not print the "0 bytes leaked" line because we never call Init() (which is where the atexit handler is installed). This didn't matter before, because it used to be that no interceptors called = no leaks = no output. But now that we want to be able to print the summary even when no memory is leaked, this is no longer correct. Should probably fix that if only just to make it consistent with ASan.<br>

> Ah, I see. I won't bother with (2), as I assume LSan will surely initialize itself as soon as the first malloc() is called, so I don't think there's any reason in explicitly calling Init() somehow.<br>
</div>Unfortunately it could cause the atexit handler to be installed late, and there would be discrepancy between standalone and ASan tools.<br></blockquote><div><br></div><div>Looks like there's no matter when to install atexit handler for LSan (that would run __lsan_do_leak_check) in the program, is there?</div>
<div>If it won't be installed, than there's no malloc in the program, and we shouldn't care about it.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div class="HOEnZb"><div class="h5"><br>
<br>
<a href="http://llvm-reviews.chandlerc.com/D1258" target="_blank">http://llvm-reviews.chandlerc.com/D1258</a><br>
<br>
BRANCH<br>
  feat/detect_leaks_at_exit<br>
<br>
ARCANIST PROJECT<br>
  compiler-rt<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div>Alexey Samsonov, MSK</div>
</div></div>