<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - make -fsanitize-coverage=pc-table friendly with -ffunction-sections -Wl,-gc-sections"
   href="https://bugs.llvm.org/show_bug.cgi?id=34636">34636</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>make -fsanitize-coverage=pc-table friendly with -ffunction-sections -Wl,-gc-sections
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>mascasa@google.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>kcc@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>ekarpenkov@apple.com, eugeni.stepanov@gmail.com, llvm-bugs@justinbogner.com, llvm-bugs@lists.llvm.org, peter@pcc.me.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>[discussed previously at
<a href="http://lists.llvm.org/pipermail/llvm-dev/2017-September/117315.html">http://lists.llvm.org/pipermail/llvm-dev/2017-September/117315.html</a>]


On linux we have two problems with -fsanitize=fuzzer and -ffunction-sections
-Wl,-gc-sections

Test for these: projects/compiler-rt/test/fuzzer/GcSectionsTest.cpp

First problem: 

% clang -std=c++11 -ffunction-sections -Wl,-gc-sections -fsanitize=fuzzer 
GcSectionsTest.cpp 
/tmp/GcSectionsTest-065286.o: In function `sancov.module_ctor':
GcSectionsTest.cpp:(.text.sancov.module_ctor[sancov.module_ctor]+0x22):
undefined reference to `__start___sancov_pcs'
GcSectionsTest.cpp:(.text.sancov.module_ctor[sancov.module_ctor]+0x2c):
undefined reference to `__stop___sancov_pcs'

Here, the table produced by -fsanitize-coverage=pc-table __sancov_pcs gets
dropped by the bfd linker (on Ubuntu 14.04). 

With a better linker (-fuse-ld=gold or -fuse-ld=lld) this doesn't happen,
but we still *may* need to find a workaround suitable for old ld. Or maybe not. 


Second:

% clang -std=c++11 -ffunction-sections -Wl,-gc-sections -fsanitize=fuzzer 
GcSectionsTest.cpp -fuse-ld=lld && nm a.out | grep Unused 
000000000023f590 t UnusedFunctionShouldBeRemovedByLinker


here, gc-sections is essentially disabled because -fsanitize-coverage=pc-table
makes all functions used. 

eugenis@ suggests that all we need here is to use
<a href="https://llvm.org/docs/LangRef.html#associated-metadata">https://llvm.org/docs/LangRef.html#associated-metadata</a> to mark the pc-table as
associated with it's function. 

This is important, we need gc-sections to work. 
But once we fix it, we'll need a test (in test/fuzzer/gc-sections.test)
but the test won't work with bfd linker, see above.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>