<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 24, 2017 at 3:20 PM, Justin Bogner <span dir="ltr"><<a href="mailto:mail@justinbogner.com" target="_blank">mail@justinbogner.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I think the simplest fix is something like this:<br>
<br>
diff --git a/lib/Transforms/<wbr>Instrumentation/<wbr>SanitizerCoverage.cpp b/lib/Transforms/<wbr>Instrumentation/<wbr>SanitizerCoverage.cpp<br>
index c6f0d17f8fe..e81957ab80a 100644<br>
--- a/lib/Transforms/<wbr>Instrumentation/<wbr>SanitizerCoverage.cpp<br>
+++ b/lib/Transforms/<wbr>Instrumentation/<wbr>SanitizerCoverage.cpp<br>
@@ -256,6 +256,7 @@ SanitizerCoverageModule::<wbr>CreateSecStartEnd(Module &M, const char *Section,<br>
       new GlobalVariable(M, Ty, false, GlobalVariable::<wbr>ExternalLinkage,<br>
                          nullptr, getSectionEnd(Section));<br>
   SecEnd->setVisibility(<wbr>GlobalValue::HiddenVisibility)<wbr>;<br>
+  appendToUsed(M, {SecStart, SecEnd});<br>
<br>
   return std::make_pair(SecStart, SecEnd);<br>
 }<br>
<br>
I'm trying it out now.<br></blockquote><div><br></div><div>LGTM (if this works), thanks! </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class=""><br>
Kostya Serebryany <<a href="mailto:kcc@google.com">kcc@google.com</a>> writes:<br>
> With -Wl,-gc-sections I get this:<br>
> SimpleTest.cpp:(.text.sancov.<wbr>module_ctor[sancov.module_<wbr>ctor]+0x1b):<br>
> undefined reference to `__start___sancov_pcs'<br>
> SimpleTest.cpp:(.text.sancov.<wbr>module_ctor[sancov.module_<wbr>ctor]+0x20):<br>
> undefined reference to `__stop___sancov_pcs'<br>
><br>
><br>
><br>
> On Thu, Aug 24, 2017 at 3:07 PM, George Karpenkov <<a href="mailto:ekarpenkov@apple.com">ekarpenkov@apple.com</a>><br>
> wrote:<br>
><br>
>><br>
>> On Aug 24, 2017, at 2:55 PM, Kostya Serebryany <<a href="mailto:kcc@google.com">kcc@google.com</a>> wrote:<br>
>><br>
>> Interesting.<br>
>> This is a relatively new addition (fsanitize-coverage=pc-tables, which is<br>
>> now a part of -fsanitize=fuzzer).<br>
>> The tests worked (did they? On Mac?) so I thought everything is ok.<br>
>><br>
>><br>
>> For tests we never compile the tested target with -O3 (and that wouldn’t<br>
>> be sufficient),<br>
>> and for testing fuzzers I was always building them in debug<br>
>><br>
>> Yea, we need to make sure the pc-tables are not stripped (this is a<br>
>> separate section with globals).<br>
>> (I still haven't documented pc-tables, will do soon)<br>
>><br>
>><br>
>> Do you know what's the analog of Wl,-dead_strip on Linux?<br>
>><br>
>><br>
>> Apparently -Wl,—gc-sections.<br>
>> For some reason LLVM does not do it for gold, even though it seems to<br>
>> support this flag as well.<br>
>> (that could be another reason why you don’t see the failure on Linux)<br>
>><br>
</span>>>  1 *if*(NOT LLVM_NO_DEAD_STRIP)<br>
>>  2   *if*(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")<br>
<span class="">>>  3     # ld64's implementation of -dead_strip breaks tools that use<br>
>> plugins.<br>
>>  4     set_property(TARGET ${target_name} APPEND_STRING PROPERTY<br>
>>  5                  LINK_FLAGS " -Wl,-dead_strip")<br>
</span>>>  6   *elseif*(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")<br>
<span class="">>>  7     set_property(TARGET ${target_name} APPEND_STRING PROPERTY<br>
>>  8                  LINK_FLAGS " -Wl,-z -Wl,discard-unused=sections")<br>
</span>>>  9   *elseif*(NOT WIN32 AND NOT LLVM_LINKER_IS_GOLD)<br>
<span class="">>> 10     # Object files are compiled with -ffunction-data-sections.<br>
>> 11     # Versions of bfd ld < 2.23.1 have a bug in --gc-sections that<br>
>> breaks<br>
>> 12     # tools that use plugins. Always pass --gc-sections once we require<br>
>> 13     # a newer linker.<br>
>> 14     set_property(TARGET ${target_name} APPEND_STRING PROPERTY<br>
>> 15                  LINK_FLAGS " -Wl,--gc-sections")<br>
</span>>> 16   *endif*()<br>
>> 17 *endif*()<br>
<div class="HOEnZb"><div class="h5">>><br>
>><br>
>><br>
>> --kcc<br>
>><br>
>><br>
>><br>
>> On Thu, Aug 24, 2017 at 2:49 PM, Justin Bogner <<a href="mailto:mail@justinbogner.com">mail@justinbogner.com</a>><br>
>> wrote:<br>
>><br>
>>> George Karpenkov <<a href="mailto:ekarpenkov@apple.com">ekarpenkov@apple.com</a>> writes:<br>
>>> > OK so with Kuba’s help I’ve found the error: with optimization, dead<br>
>>> > stripping of produced libraries is enabled,<br>
>>> > which removes coverage instrumentation.<br>
>>> ><br>
>>> > However, this has nothing to do with the move to compiler-rt, so I’m<br>
>>> > quite skeptical on whether it has worked<br>
>>> > beforehand.<br>
>>> ><br>
>>> > A trivial fix is to do:<br>
>>> ><br>
>>> > diff --git a/cmake/modules/<wbr>HandleLLVMOptions.cmake<br>
>>> b/cmake/modules/<wbr>HandleLLVMOptions.cmake<br>
>>> > index 04596a6ff63..5465d8d95ba 100644<br>
>>> > --- a/cmake/modules/<wbr>HandleLLVMOptions.cmake<br>
>>> > +++ b/cmake/modules/<wbr>HandleLLVMOptions.cmake<br>
>>> > @@ -665,6 +665,9 @@ if(LLVM_USE_SANITIZER)<br>
>>> >    endif()<br>
>>> >    if (LLVM_USE_SANITIZE_COVERAGE)<br>
>>> >      append("-fsanitize=fuzzer-no-<wbr>link" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)<br>
>>> > +<br>
>>> > +    # Dead stripping messes up coverage instrumentation.<br>
>>> > +    set(LLVM_NO_DEAD_STRIP ON)<br>
>>> >    endif()<br>
>>> >  endif()<br>
>>> ><br>
>>> > Any arguments against that?<br>
>>><br>
>>> We shouldn't do this. We really only want to prevent dead stripping of<br>
>>> the counters themselves - disabling it completely isn't very nice.<br>
>>><br>
>>> > Apparently, a better way is to follow ASAN instrumentation pass,<br>
>>> > which uses some magic to protect against dead-stripping.<br>
>>><br>
>>> I thought this was already being done - how else did it work before?<br>
>>><br>
>>> >> On Aug 24, 2017, at 11:29 AM, Justin Bogner <<a href="mailto:mail@justinbogner.com">mail@justinbogner.com</a>><br>
>>> wrote:<br>
>>> >><br>
>>> >> (kcc, george: sorry for the re-send, the first was from a non-list<br>
>>> email<br>
>>> >> address)<br>
>>> >><br>
>>> >> My configuration for building the fuzzers in the LLVM tree doesn't<br>
>>> seem to<br>
>>> >> work any more (possibly as of moving libFuzzer to compiler-rt, but<br>
>>> there<br>
>>> >> have been a few other changes in the last week or so that may be<br>
>>> related).<br>
>>> >><br>
>>> >> I'm building with a fresh top-of-tree clang and setting<br>
>>> >> -DLLVM_USE_SANITIZER=Address and -DLLVM_USE_SANITIZE_COVERAGE=<wbr>On,<br>
>>> which<br>
>>> >> was working before:<br>
>>> >><br>
>>> >>  % cmake -GNinja \<br>
>>> >>          -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=On \<br>
>>> >>          -DLLVM_ENABLE_WERROR=On \<br>
>>> >>          -DLLVM_USE_SANITIZER=Address -DLLVM_USE_SANITIZE_COVERAGE=<wbr>On<br>
>>> \<br>
>>> >>          -DCMAKE_C_COMPILER=$HOME/llvm-<wbr>lkgc/bin/clang \<br>
>>> >>          $HOME/code/llvm-src<br>
>>> >><br>
>>> >> But when I run any of the fuzzers, it looks like the sanitizer coverage<br>
>>> >> hasn't been set up correctly:<br>
>>> >><br>
>>> >>  % ./bin/llvm-as-fuzzer<br>
>>>                                    2017-08-24 11:14:33<br>
>>> >>  INFO: Seed: 4089166883<br>
>>> >>  INFO: Loaded 1 modules   (50607 guards): 50607 [0x10e14ef80,<br>
>>> 0x10e18063c),<br>
>>> >>  INFO: Loaded 1 PC tables (0 PCs): 0 [0x10e2870a8,0x10e2870a8),<br>
>>> >>  ERROR: The size of coverage PC tables does not match the number of<br>
>>> instrumented PCs. This might be a bug in the compiler, please contact the<br>
>>> libFuzzer developers.<br>
>>> >><br>
>>> >> From the build logs, it looks like we're now building objects with<br>
>>> these<br>
>>> >> sanitizer flags:<br>
>>> >><br>
>>> >>  -fsanitize=address<br>
>>> >>  -fsanitize-address-use-after-<wbr>scope<br>
>>> >>  -fsanitize=fuzzer-no-link<br>
>>> >><br>
>>> >> We're then linking the fuzzer binaries with these:<br>
>>> >><br>
>>> >>  -fsanitize=address<br>
>>> >>  -fsanitize-address-use-after-<wbr>scope<br>
>>> >>  -fsanitize=fuzzer-no-link<br>
>>> >>  -fsanitize=fuzzer<br>
>>> >><br>
>>> >> Any idea what's wrong or where to start looking?<br>
>>><br>
>><br>
>><br>
>><br>
</div></div></blockquote></div><br></div></div>