<div dir="ltr"><div dir="ltr">I think I can make them one function as they do the same thing (add 8 bytes to the section start pointer). </div><div dir="ltr">Is that what you have in mind?</div><div dir="ltr"><br><div>I don't think I can actually account for this just once because there are two places where constructors are created, in CreateInitCallsForSections (for the guard array and the 8-bit counter array) and in runOnModule (for PCTable).</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 11, 2018 at 6:23 PM, Kostya Serebryany <span dir="ltr"><<a href="mailto:kcc@google.com" target="_blank">kcc@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 dir="ltr">This patch seem to have two nearly-identical sections starting from a comment "<span>Account</span> <span>for</span> <span>the</span> <span>fact</span> <span>that</span> <span>on</span> <span><wbr>windows</span>-<span>msvc</span>"<div>Is it possible to account for any such fact just once? </div></div><div class="HOEnZb"><div class="h5"><br><div class="gmail_quote"><div dir="ltr">On Thu, Aug 30, 2018 at 8:55 AM Matt Morehouse via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: morehouse<br>
Date: Thu Aug 30 08:54:44 2018<br>
New Revision: 341082<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=341082&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=341082&view=rev</a><br>
Log:<br>
[libFuzzer] Port to Windows<br>
<br>
Summary:<br>
Port libFuzzer to windows-msvc.<br>
This patch allows libFuzzer targets to be built and run on Windows, using -fsanitize=fuzzer and/or fsanitize=fuzzer-no-link. It allows these forms of coverage instrumentation to work on Windows as well.<br>
It does not fix all issues, such as those with -fsanitize-coverage=stack-<wbr>depth, which is not usable on Windows as of this patch.<br>
It also does not fix any libFuzzer integration tests. Nearly all of them fail to compile, fixing them will come in a later patch, so libFuzzer tests are disabled on Windows until them.<br>
<br>
Patch By: metzman<br>
<br>
Reviewers: morehouse, rnk<br>
<br>
Reviewed By: morehouse, rnk<br>
<br>
Subscribers: #sanitizers, delcypher, morehouse, kcc, eraman<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D51022" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D51022</a><br>
<br>
Added:<br>
    llvm/trunk/test/<wbr>Instrumentation/<wbr>SanitizerCoverage/coff-pc-<wbr>table-inline-8bit-counters.ll<br>
Modified:<br>
    llvm/trunk/lib/Transforms/<wbr>Instrumentation/<wbr>SanitizerCoverage.cpp<br>
<br>
Modified: llvm/trunk/lib/Transforms/<wbr>Instrumentation/<wbr>SanitizerCoverage.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp?rev=341082&r1=341081&r2=341082&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>Transforms/Instrumentation/<wbr>SanitizerCoverage.cpp?rev=<wbr>341082&r1=341081&r2=341082&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/Transforms/<wbr>Instrumentation/<wbr>SanitizerCoverage.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/<wbr>Instrumentation/<wbr>SanitizerCoverage.cpp Thu Aug 30 08:54:44 2018<br>
@@ -273,9 +273,20 @@ Function *SanitizerCoverageModule::<wbr>Creat<br>
   auto SecStart = SecStartEnd.first;<br>
   auto SecEnd = SecStartEnd.second;<br>
   Function *CtorFunc;<br>
+  Value *SecStartPtr = nullptr;<br>
+  // Account for the fact that on windows-msvc __start_* symbols actually<br>
+  // point to a uint64_t before the start of the array.<br>
+  if (TargetTriple.getObjectFormat(<wbr>) == Triple::COFF) {<br>
+    auto SecStartI8Ptr = IRB.CreatePointerCast(<wbr>SecStart, Int8PtrTy);<br>
+    auto GEP = IRB.CreateGEP(SecStartI8Ptr,<br>
+                             ConstantInt::get(IntptrTy, sizeof(uint64_t)));<br>
+    SecStartPtr = IRB.CreatePointerCast(GEP, Ty);<br>
+  } else {<br>
+    SecStartPtr = IRB.CreatePointerCast(<wbr>SecStart, Ty);<br>
+  }<br>
   std::tie(CtorFunc, std::ignore) = createSanitizerCtorAndInitFunc<wbr>tions(<br>
       M, SanCovModuleCtorName, InitFunctionName, {Ty, Ty},<br>
-      {IRB.CreatePointerCast(<wbr>SecStart, Ty), IRB.CreatePointerCast(SecEnd, Ty)});<br>
+      {SecStartPtr, IRB.CreatePointerCast(SecEnd, Ty)});<br>
<br>
   if (TargetTriple.supportsCOMDAT()<wbr>) {<br>
     // Use comdat to dedup CtorFunc.<br>
@@ -397,9 +408,20 @@ bool SanitizerCoverageModule::<wbr>runOnModul<br>
     Function *InitFunction = declareSanitizerInitFunction(<br>
         M, SanCovPCsInitName, {IntptrPtrTy, IntptrPtrTy});<br>
     IRBuilder<> IRBCtor(Ctor->getEntryBlock().<wbr>getTerminator());<br>
-    IRBCtor.CreateCall(<wbr>InitFunction,<br>
-                       {IRB.CreatePointerCast(<wbr>SecStartEnd.first, IntptrPtrTy),<br>
-                        IRB.CreatePointerCast(<wbr>SecStartEnd.second, IntptrPtrTy)});<br>
+    Value *SecStartPtr = nullptr;<br>
+    // Account for the fact that on windows-msvc __start_pc_table actually<br>
+    // points to a uint64_t before the start of the PC table.<br>
+    if (TargetTriple.getObjectFormat(<wbr>) == Triple::COFF) {<br>
+      auto SecStartI8Ptr = IRB.CreatePointerCast(<wbr>SecStartEnd.first, Int8PtrTy);<br>
+      auto GEP = IRB.CreateGEP(SecStartI8Ptr,<br>
+                               ConstantInt::get(IntptrTy, sizeof(uint64_t)));<br>
+      SecStartPtr = IRB.CreatePointerCast(GEP, IntptrPtrTy);<br>
+    } else {<br>
+      SecStartPtr = IRB.CreatePointerCast(<wbr>SecStartEnd.first, IntptrPtrTy);<br>
+    }<br>
+    IRBCtor.CreateCall(<br>
+        InitFunction,<br>
+        {SecStartPtr, IRB.CreatePointerCast(<wbr>SecStartEnd.second, IntptrPtrTy)});<br>
   }<br>
   // We don't reference these arrays directly in any of our runtime functions,<br>
   // so we need to prevent them from being dead stripped.<br>
@@ -809,8 +831,13 @@ void SanitizerCoverageModule::<wbr>InjectCove<br>
<br>
 std::string<br>
 SanitizerCoverageModule::<wbr>getSectionName(const std::string &Section) const {<br>
-  if (TargetTriple.getObjectFormat(<wbr>) == Triple::COFF)<br>
-    return ".SCOV$M";<br>
+  if (TargetTriple.getObjectFormat(<wbr>) == Triple::COFF) {<br>
+    if (Section == SanCovCountersSectionName)<br>
+      return ".SCOV$CM";<br>
+    if (Section == SanCovPCsSectionName)<br>
+      return ".SCOVP$M";<br>
+    return ".SCOV$GM"; // For SanCovGuardsSectionName.<br>
+  }<br>
   if (TargetTriple.<wbr>isOSBinFormatMachO())<br>
     return "__DATA,__" + Section;<br>
   return "__" + Section;<br>
<br>
Added: llvm/trunk/test/<wbr>Instrumentation/<wbr>SanitizerCoverage/coff-pc-<wbr>table-inline-8bit-counters.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/SanitizerCoverage/coff-pc-table-inline-8bit-counters.ll?rev=341082&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/test/<wbr>Instrumentation/<wbr>SanitizerCoverage/coff-pc-<wbr>table-inline-8bit-counters.ll?<wbr>rev=341082&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/test/<wbr>Instrumentation/<wbr>SanitizerCoverage/coff-pc-<wbr>table-inline-8bit-counters.ll (added)<br>
+++ llvm/trunk/test/<wbr>Instrumentation/<wbr>SanitizerCoverage/coff-pc-<wbr>table-inline-8bit-counters.ll Thu Aug 30 08:54:44 2018<br>
@@ -0,0 +1,12 @@<br>
+; Checks that the PC and 8-bit Counter Arrays are placed in their own sections in COFF binaries.<br>
+; RUN: opt < %s -sancov -sanitizer-coverage-level=1 -sanitizer-coverage-inline-<wbr>8bit-counters=1 -sanitizer-coverage-pc-table=1 -S | FileCheck %s<br>
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:<wbr>32:64-S128"<br>
+target triple = "x86_64-pc-windows-msvc19.14.<wbr>26433"<br>
+<br>
+define void @foo() {<br>
+entry:<br>
+  ret void<br>
+}<br>
+<br>
+; CHECK-DAG: section ".SCOV{{\$}}CM",<br>
+; CHECK-DAG: section ".SCOVP{{\$}}M",<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div>
</div></div></blockquote></div><br></div>