<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 24, 2017, at 2:55 PM, Kostya Serebryany <<a href="mailto:kcc@google.com" class="">kcc@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Interesting. <div class="">This is a relatively new addition (fsanitize-coverage=pc-tables, which is now a part of -fsanitize=fuzzer). </div><div class="">The tests worked (did they? On Mac?) so I thought everything is ok. </div></div></div></blockquote><div><br class=""></div><div>For tests we never compile the tested target with -O3 (and that wouldn’t be sufficient),</div><div>and for testing fuzzers I was always building them in debug </div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">Yea, we need to make sure the pc-tables are not stripped (this is a separate section with globals). </div><div class="">(I still haven't documented pc-tables, will do soon)</div></div></div></blockquote><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class="">Do you know what's the analog of Wl,-dead_strip on Linux?</div></div></blockquote><div><br class=""></div>Apparently -Wl,—gc-sections.</div><div>For some reason LLVM does not do it for gold, even though it seems to support this flag as well.</div><div>(that could be another reason why you don’t see the failure on Linux)</div><div><div><br class=""></div><div><div style="margin: 0px; line-height: normal; font-family: Courier; color: rgb(255, 135, 0); -webkit-text-stroke-width: initial; -webkit-text-stroke-color: rgb(255, 135, 0); background-color: rgb(18, 18, 18);" class=""><span style="-webkit-font-kerning: none; color: rgb(188, 188, 188); background-color: rgb(48, 48, 48); -webkit-text-stroke-color: rgb(188, 188, 188);" class=""> 1 </span><span style="-webkit-font-kerning: none; color: rgb(215, 0, 95); -webkit-text-stroke-color: rgb(215, 0, 95);" class=""><b class="">if</b></span><span style="font-kerning: none" class="">(</span><span style="-webkit-font-kerning: none; color: rgb(215, 0, 95); -webkit-text-stroke-color: rgb(215, 0, 95);" class="">NOT</span><span style="font-kerning: none" class=""> LLVM_NO_DEAD_STRIP)</span></div><div style="margin: 0px; line-height: normal; font-family: Courier; color: rgb(95, 215, 255); -webkit-text-stroke-width: initial; -webkit-text-stroke-color: rgb(95, 215, 255); background-color: rgb(18, 18, 18);" class=""><span style="-webkit-font-kerning: none; color: rgb(188, 188, 188); background-color: rgb(48, 48, 48); -webkit-text-stroke-color: rgb(188, 188, 188);" class=""> 2 </span><span style="-webkit-font-kerning: none; color: rgb(208, 208, 208); -webkit-text-stroke-color: rgb(208, 208, 208);" class="">  </span><span style="-webkit-font-kerning: none; color: rgb(215, 0, 95); -webkit-text-stroke-color: rgb(215, 0, 95);" class=""><b class="">if</b></span><span style="-webkit-font-kerning: none; color: rgb(255, 135, 0); -webkit-text-stroke-color: rgb(255, 135, 0);" class="">(</span><span style="font-kerning: none" class="">${CMAKE_SYSTEM_NAME}</span><span style="-webkit-font-kerning: none; color: rgb(255, 135, 0); -webkit-text-stroke-color: rgb(255, 135, 0);" class=""> </span><span style="-webkit-font-kerning: none; color: rgb(215, 0, 95); -webkit-text-stroke-color: rgb(215, 0, 95);" class="">MATCHES</span><span style="-webkit-font-kerning: none; color: rgb(255, 135, 0); -webkit-text-stroke-color: rgb(255, 135, 0);" class=""> </span><span style="-webkit-font-kerning: none; color: rgb(175, 175, 135); -webkit-text-stroke-color: rgb(175, 175, 135);" class="">"Darwin"</span><span style="-webkit-font-kerning: none; color: rgb(255, 135, 0); -webkit-text-stroke-color: rgb(255, 135, 0);" class="">)</span></div><div style="margin: 0px; line-height: normal; font-family: Courier; color: rgb(95, 95, 95); -webkit-text-stroke-width: initial; -webkit-text-stroke-color: rgb(95, 95, 95); background-color: rgb(18, 18, 18);" class=""><span style="-webkit-font-kerning: none; color: rgb(188, 188, 188); background-color: rgb(48, 48, 48); -webkit-text-stroke-color: rgb(188, 188, 188);" class=""> 3 </span><span style="-webkit-font-kerning: none; color: rgb(208, 208, 208); -webkit-text-stroke-color: rgb(208, 208, 208);" class="">    </span><span style="font-kerning: none" class=""># ld64's implementation of -dead_strip breaks tools that use plugins.</span></div><div style="margin: 0px; line-height: normal; font-family: Courier; color: rgb(255, 135, 0); -webkit-text-stroke-width: initial; -webkit-text-stroke-color: rgb(255, 135, 0); background-color: rgb(18, 18, 18);" class=""><span style="-webkit-font-kerning: none; color: rgb(188, 188, 188); background-color: rgb(48, 48, 48); -webkit-text-stroke-color: rgb(188, 188, 188);" class=""> 4 </span><span style="-webkit-font-kerning: none; color: rgb(208, 208, 208); -webkit-text-stroke-color: rgb(208, 208, 208);" class="">    set_property</span><span style="font-kerning: none" class="">(TARGET </span><span style="-webkit-font-kerning: none; color: rgb(95, 215, 255); -webkit-text-stroke-color: rgb(95, 215, 255);" class="">${target_name}</span><span style="font-kerning: none" class=""> APPEND_STRING PROPERTY</span></div><div style="margin: 0px; line-height: normal; font-family: Courier; color: rgb(255, 135, 0); -webkit-text-stroke-width: initial; -webkit-text-stroke-color: rgb(255, 135, 0); background-color: rgb(18, 18, 18);" class=""><span style="-webkit-font-kerning: none; color: rgb(188, 188, 188); background-color: rgb(48, 48, 48); -webkit-text-stroke-color: rgb(188, 188, 188);" class=""> 5 </span><span style="font-kerning: none" class="">                 LINK_FLAGS </span><span style="-webkit-font-kerning: none; color: rgb(175, 175, 135); -webkit-text-stroke-color: rgb(175, 175, 135);" class="">" -Wl,-dead_strip"</span><span style="font-kerning: none" class="">)</span></div><div style="margin: 0px; line-height: normal; font-family: Courier; color: rgb(95, 215, 255); -webkit-text-stroke-width: initial; -webkit-text-stroke-color: rgb(95, 215, 255); background-color: rgb(18, 18, 18);" class=""><span style="-webkit-font-kerning: none; color: rgb(188, 188, 188); background-color: rgb(48, 48, 48); -webkit-text-stroke-color: rgb(188, 188, 188);" class=""> 6 </span><span style="-webkit-font-kerning: none; color: rgb(208, 208, 208); -webkit-text-stroke-color: rgb(208, 208, 208);" class="">  </span><span style="-webkit-font-kerning: none; color: rgb(215, 0, 95); -webkit-text-stroke-color: rgb(215, 0, 95);" class=""><b class="">elseif</b></span><span style="-webkit-font-kerning: none; color: rgb(255, 135, 0); -webkit-text-stroke-color: rgb(255, 135, 0);" class="">(</span><span style="font-kerning: none" class="">${CMAKE_SYSTEM_NAME}</span><span style="-webkit-font-kerning: none; color: rgb(255, 135, 0); -webkit-text-stroke-color: rgb(255, 135, 0);" class=""> </span><span style="-webkit-font-kerning: none; color: rgb(215, 0, 95); -webkit-text-stroke-color: rgb(215, 0, 95);" class="">MATCHES</span><span style="-webkit-font-kerning: none; color: rgb(255, 135, 0); -webkit-text-stroke-color: rgb(255, 135, 0);" class=""> </span><span style="-webkit-font-kerning: none; color: rgb(175, 175, 135); -webkit-text-stroke-color: rgb(175, 175, 135);" class="">"SunOS"</span><span style="-webkit-font-kerning: none; color: rgb(255, 135, 0); -webkit-text-stroke-color: rgb(255, 135, 0);" class="">)</span></div><div style="margin: 0px; line-height: normal; font-family: Courier; color: rgb(255, 135, 0); -webkit-text-stroke-width: initial; -webkit-text-stroke-color: rgb(255, 135, 0); background-color: rgb(18, 18, 18);" class=""><span style="-webkit-font-kerning: none; color: rgb(188, 188, 188); background-color: rgb(48, 48, 48); -webkit-text-stroke-color: rgb(188, 188, 188);" class=""> 7 </span><span style="-webkit-font-kerning: none; color: rgb(208, 208, 208); -webkit-text-stroke-color: rgb(208, 208, 208);" class="">    set_property</span><span style="font-kerning: none" class="">(TARGET </span><span style="-webkit-font-kerning: none; color: rgb(95, 215, 255); -webkit-text-stroke-color: rgb(95, 215, 255);" class="">${target_name}</span><span style="font-kerning: none" class=""> APPEND_STRING PROPERTY</span></div><div style="margin: 0px; line-height: normal; font-family: Courier; color: rgb(175, 175, 135); -webkit-text-stroke-width: initial; -webkit-text-stroke-color: rgb(175, 175, 135); background-color: rgb(18, 18, 18);" class=""><span style="-webkit-font-kerning: none; color: rgb(188, 188, 188); background-color: rgb(48, 48, 48); -webkit-text-stroke-color: rgb(188, 188, 188);" class=""> 8 </span><span style="-webkit-font-kerning: none; color: rgb(255, 135, 0); -webkit-text-stroke-color: rgb(255, 135, 0);" class="">                 LINK_FLAGS </span><span style="font-kerning: none" class="">" -Wl,-z -Wl,discard-unused=sections"</span><span style="-webkit-font-kerning: none; color: rgb(255, 135, 0); -webkit-text-stroke-color: rgb(255, 135, 0);" class="">)</span></div><div style="margin: 0px; line-height: normal; font-family: Courier; color: rgb(255, 135, 0); -webkit-text-stroke-width: initial; -webkit-text-stroke-color: rgb(255, 135, 0); background-color: rgb(18, 18, 18);" class=""><span style="-webkit-font-kerning: none; color: rgb(188, 188, 188); background-color: rgb(48, 48, 48); -webkit-text-stroke-color: rgb(188, 188, 188);" class=""> 9 </span><span style="-webkit-font-kerning: none; color: rgb(208, 208, 208); -webkit-text-stroke-color: rgb(208, 208, 208);" class="">  </span><span style="-webkit-font-kerning: none; color: rgb(215, 0, 95); -webkit-text-stroke-color: rgb(215, 0, 95);" class=""><b class="">elseif</b></span><span style="font-kerning: none" class="">(</span><span style="-webkit-font-kerning: none; color: rgb(215, 0, 95); -webkit-text-stroke-color: rgb(215, 0, 95);" class="">NOT</span><span style="font-kerning: none" class=""> </span><span style="-webkit-font-kerning: none; color: rgb(208, 208, 208); -webkit-text-stroke-color: rgb(208, 208, 208);" class="">WIN32</span><span style="font-kerning: none" class=""> </span><span style="-webkit-font-kerning: none; color: rgb(215, 0, 95); -webkit-text-stroke-color: rgb(215, 0, 95);" class="">AND</span><span style="font-kerning: none" class=""> </span><span style="-webkit-font-kerning: none; color: rgb(215, 0, 95); -webkit-text-stroke-color: rgb(215, 0, 95);" class="">NOT</span><span style="font-kerning: none" class=""> LLVM_LINKER_IS_GOLD)</span></div><div style="margin: 0px; line-height: normal; font-family: Courier; color: rgb(95, 95, 95); -webkit-text-stroke-width: initial; -webkit-text-stroke-color: rgb(95, 95, 95); background-color: rgb(18, 18, 18);" class=""><span style="-webkit-font-kerning: none; color: rgb(188, 188, 188); background-color: rgb(48, 48, 48); -webkit-text-stroke-color: rgb(188, 188, 188);" class="">10 </span><span style="-webkit-font-kerning: none; color: rgb(208, 208, 208); -webkit-text-stroke-color: rgb(208, 208, 208);" class="">    </span><span style="font-kerning: none" class=""># Object files are compiled with -ffunction-data-sections.</span></div><div style="margin: 0px; line-height: normal; font-family: Courier; color: rgb(95, 95, 95); -webkit-text-stroke-width: initial; -webkit-text-stroke-color: rgb(95, 95, 95); background-color: rgb(18, 18, 18);" class=""><span style="-webkit-font-kerning: none; color: rgb(188, 188, 188); background-color: rgb(48, 48, 48); -webkit-text-stroke-color: rgb(188, 188, 188);" class="">11 </span><span style="-webkit-font-kerning: none; color: rgb(208, 208, 208); -webkit-text-stroke-color: rgb(208, 208, 208);" class="">    </span><span style="font-kerning: none" class=""># Versions of bfd ld < 2.23.1 have a bug in --gc-sections that breaks</span></div><div style="margin: 0px; line-height: normal; font-family: Courier; color: rgb(95, 95, 95); -webkit-text-stroke-width: initial; -webkit-text-stroke-color: rgb(95, 95, 95); background-color: rgb(18, 18, 18);" class=""><span style="-webkit-font-kerning: none; color: rgb(188, 188, 188); background-color: rgb(48, 48, 48); -webkit-text-stroke-color: rgb(188, 188, 188);" class="">12 </span><span style="-webkit-font-kerning: none; color: rgb(208, 208, 208); -webkit-text-stroke-color: rgb(208, 208, 208);" class="">    </span><span style="font-kerning: none" class=""># tools that use plugins. Always pass --gc-sections once we require</span></div><div style="margin: 0px; line-height: normal; font-family: Courier; color: rgb(95, 95, 95); -webkit-text-stroke-width: initial; -webkit-text-stroke-color: rgb(95, 95, 95); background-color: rgb(18, 18, 18);" class=""><span style="-webkit-font-kerning: none; color: rgb(188, 188, 188); background-color: rgb(48, 48, 48); -webkit-text-stroke-color: rgb(188, 188, 188);" class="">13 </span><span style="-webkit-font-kerning: none; color: rgb(208, 208, 208); -webkit-text-stroke-color: rgb(208, 208, 208);" class="">    </span><span style="font-kerning: none" class=""># a newer linker.</span></div><div style="margin: 0px; line-height: normal; font-family: Courier; color: rgb(255, 135, 0); -webkit-text-stroke-width: initial; -webkit-text-stroke-color: rgb(255, 135, 0); background-color: rgb(18, 18, 18);" class=""><span style="-webkit-font-kerning: none; color: rgb(188, 188, 188); background-color: rgb(48, 48, 48); -webkit-text-stroke-color: rgb(188, 188, 188);" class="">14 </span><span style="-webkit-font-kerning: none; color: rgb(208, 208, 208); -webkit-text-stroke-color: rgb(208, 208, 208);" class="">    set_property</span><span style="font-kerning: none" class="">(TARGET </span><span style="-webkit-font-kerning: none; color: rgb(95, 215, 255); -webkit-text-stroke-color: rgb(95, 215, 255);" class="">${target_name}</span><span style="font-kerning: none" class=""> APPEND_STRING PROPERTY</span></div><div style="margin: 0px; line-height: normal; font-family: Courier; color: rgb(255, 135, 0); -webkit-text-stroke-width: initial; -webkit-text-stroke-color: rgb(255, 135, 0); background-color: rgb(18, 18, 18);" class=""><span style="-webkit-font-kerning: none; color: rgb(188, 188, 188); background-color: rgb(48, 48, 48); -webkit-text-stroke-color: rgb(188, 188, 188);" class="">15 </span><span style="font-kerning: none" class="">                 LINK_FLAGS </span><span style="-webkit-font-kerning: none; color: rgb(175, 175, 135); -webkit-text-stroke-color: rgb(175, 175, 135);" class="">" -Wl,--gc-sections"</span><span style="font-kerning: none" class="">)</span></div><div style="margin: 0px; line-height: normal; font-family: Courier; color: rgb(215, 0, 95); -webkit-text-stroke-width: initial; -webkit-text-stroke-color: rgb(215, 0, 95); background-color: rgb(18, 18, 18);" class=""><span style="-webkit-font-kerning: none; color: rgb(188, 188, 188); background-color: rgb(48, 48, 48); -webkit-text-stroke-color: rgb(188, 188, 188);" class="">16 </span><span style="-webkit-font-kerning: none; color: rgb(208, 208, 208); -webkit-text-stroke-color: rgb(208, 208, 208);" class="">  </span><span style="font-kerning: none" class=""><b class="">endif</b></span><span style="-webkit-font-kerning: none; color: rgb(255, 135, 0); -webkit-text-stroke-color: rgb(255, 135, 0);" class="">()</span></div><div style="margin: 0px; line-height: normal; font-family: Courier; color: rgb(215, 0, 95); -webkit-text-stroke-width: initial; -webkit-text-stroke-color: rgb(215, 0, 95); background-color: rgb(18, 18, 18);" class=""><span style="-webkit-font-kerning: none; color: rgb(188, 188, 188); background-color: rgb(48, 48, 48); -webkit-text-stroke-color: rgb(188, 188, 188);" class="">17 </span><span style="font-kerning: none" class=""><b class="">endif</b></span><span style="-webkit-font-kerning: none; color: rgb(255, 135, 0); -webkit-text-stroke-color: rgb(255, 135, 0);" class="">()</span></div><div class=""><span style="-webkit-font-kerning: none; color: rgb(255, 135, 0); -webkit-text-stroke-color: rgb(255, 135, 0);" class=""><br class=""></span></div></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">--kcc <br class="">  <div class=""><br class=""></div></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Aug 24, 2017 at 2:49 PM, Justin Bogner <span dir="ltr" class=""><<a href="mailto:mail@justinbogner.com" target="_blank" class="">mail@justinbogner.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">George Karpenkov <<a href="mailto:ekarpenkov@apple.com" class="">ekarpenkov@apple.com</a>> writes:<br class="">
> OK so with Kuba’s help I’ve found the error: with optimization, dead<br class="">
> stripping of produced libraries is enabled,<br class="">
> which removes coverage instrumentation.<br class="">
><br class="">
> However, this has nothing to do with the move to compiler-rt, so I’m<br class="">
> quite skeptical on whether it has worked<br class="">
> beforehand.<br class="">
><br class="">
> A trivial fix is to do:<br class="">
><br class="">
> diff --git a/cmake/modules/<wbr class="">HandleLLVMOptions.cmake b/cmake/modules/<wbr class="">HandleLLVMOptions.cmake<br class="">
> index 04596a6ff63..5465d8d95ba 100644<br class="">
> --- a/cmake/modules/<wbr class="">HandleLLVMOptions.cmake<br class="">
> +++ b/cmake/modules/<wbr class="">HandleLLVMOptions.cmake<br class="">
> @@ -665,6 +665,9 @@ if(LLVM_USE_SANITIZER)<br class="">
>    endif()<br class="">
>    if (LLVM_USE_SANITIZE_COVERAGE)<br class="">
>      append("-fsanitize=fuzzer-no-<wbr class="">link" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)<br class="">
> +<br class="">
> +    # Dead stripping messes up coverage instrumentation.<br class="">
> +    set(LLVM_NO_DEAD_STRIP ON)<br class="">
>    endif()<br class="">
>  endif()<br class="">
><br class="">
> Any arguments against that?<br class="">
<br class="">
</span>We shouldn't do this. We really only want to prevent dead stripping of<br class="">
the counters themselves - disabling it completely isn't very nice.<br class="">
<span class=""><br class="">
> Apparently, a better way is to follow ASAN instrumentation pass,<br class="">
> which uses some magic to protect against dead-stripping.<br class="">
<br class="">
</span>I thought this was already being done - how else did it work before?<br class="">
<div class="HOEnZb"><div class="h5"><br class="">
>> On Aug 24, 2017, at 11:29 AM, Justin Bogner <<a href="mailto:mail@justinbogner.com" class="">mail@justinbogner.com</a>> wrote:<br class="">
>><br class="">
>> (kcc, george: sorry for the re-send, the first was from a non-list email<br class="">
>> address)<br class="">
>><br class="">
>> My configuration for building the fuzzers in the LLVM tree doesn't seem to<br class="">
>> work any more (possibly as of moving libFuzzer to compiler-rt, but there<br class="">
>> have been a few other changes in the last week or so that may be related).<br class="">
>><br class="">
>> I'm building with a fresh top-of-tree clang and setting<br class="">
>> -DLLVM_USE_SANITIZER=Address and -DLLVM_USE_SANITIZE_COVERAGE=<wbr class="">On, which<br class="">
>> was working before:<br class="">
>><br class="">
>>  % cmake -GNinja \<br class="">
>>          -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=On \<br class="">
>>          -DLLVM_ENABLE_WERROR=On \<br class="">
>>          -DLLVM_USE_SANITIZER=Address -DLLVM_USE_SANITIZE_COVERAGE=<wbr class="">On \<br class="">
>>          -DCMAKE_C_COMPILER=$HOME/llvm-<wbr class="">lkgc/bin/clang \<br class="">
>>          $HOME/code/llvm-src<br class="">
>><br class="">
>> But when I run any of the fuzzers, it looks like the sanitizer coverage<br class="">
>> hasn't been set up correctly:<br class="">
>><br class="">
>>  % ./bin/llvm-as-fuzzer                                                                                   2017-08-24 11:14:33<br class="">
>>  INFO: Seed: 4089166883<br class="">
>>  INFO: Loaded 1 modules   (50607 guards): 50607 [0x10e14ef80, 0x10e18063c),<br class="">
>>  INFO: Loaded 1 PC tables (0 PCs): 0 [0x10e2870a8,0x10e2870a8),<br class="">
>>  ERROR: The size of coverage PC tables does not match the number of instrumented PCs. This might be a bug in the compiler, please contact the libFuzzer developers.<br class="">
>><br class="">
>> From the build logs, it looks like we're now building objects with these<br class="">
>> sanitizer flags:<br class="">
>><br class="">
>>  -fsanitize=address<br class="">
>>  -fsanitize-address-use-after-<wbr class="">scope<br class="">
>>  -fsanitize=fuzzer-no-link<br class="">
>><br class="">
>> We're then linking the fuzzer binaries with these:<br class="">
>><br class="">
>>  -fsanitize=address<br class="">
>>  -fsanitize-address-use-after-<wbr class="">scope<br class="">
>>  -fsanitize=fuzzer-no-link<br class="">
>>  -fsanitize=fuzzer<br class="">
>><br class="">
>> Any idea what's wrong or where to start looking?<br class="">
</div></div></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>