[llvm] r341082 - [libFuzzer] Port to Windows

Jonathan Metzman via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 11 18:42:35 PDT 2018


I think I can make them one function as they do the same thing (add 8 bytes
to the section start pointer).
Is that what you have in mind?

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).

On Thu, Oct 11, 2018 at 6:23 PM, Kostya Serebryany <kcc at google.com> wrote:

> This patch seem to have two nearly-identical sections starting from a
> comment "Account for the fact that on windows-msvc"
> Is it possible to account for any such fact just once?
>
> On Thu, Aug 30, 2018 at 8:55 AM Matt Morehouse via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>> Author: morehouse
>> Date: Thu Aug 30 08:54:44 2018
>> New Revision: 341082
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=341082&view=rev
>> Log:
>> [libFuzzer] Port to Windows
>>
>> Summary:
>> Port libFuzzer to windows-msvc.
>> 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.
>> It does not fix all issues, such as those with -fsanitize-coverage=stack-depth,
>> which is not usable on Windows as of this patch.
>> 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.
>>
>> Patch By: metzman
>>
>> Reviewers: morehouse, rnk
>>
>> Reviewed By: morehouse, rnk
>>
>> Subscribers: #sanitizers, delcypher, morehouse, kcc, eraman
>>
>> Differential Revision: https://reviews.llvm.org/D51022
>>
>> Added:
>>     llvm/trunk/test/Instrumentation/SanitizerCoverage/coff-pc-
>> table-inline-8bit-counters.ll
>> Modified:
>>     llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
>>
>> Modified: llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/
>> Transforms/Instrumentation/SanitizerCoverage.cpp?rev=
>> 341082&r1=341081&r2=341082&view=diff
>> ============================================================
>> ==================
>> --- llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
>> (original)
>> +++ llvm/trunk/lib/Transforms/Instrumentation/SanitizerCoverage.cpp Thu
>> Aug 30 08:54:44 2018
>> @@ -273,9 +273,20 @@ Function *SanitizerCoverageModule::Creat
>>    auto SecStart = SecStartEnd.first;
>>    auto SecEnd = SecStartEnd.second;
>>    Function *CtorFunc;
>> +  Value *SecStartPtr = nullptr;
>> +  // Account for the fact that on windows-msvc __start_* symbols actually
>> +  // point to a uint64_t before the start of the array.
>> +  if (TargetTriple.getObjectFormat() == Triple::COFF) {
>> +    auto SecStartI8Ptr = IRB.CreatePointerCast(SecStart, Int8PtrTy);
>> +    auto GEP = IRB.CreateGEP(SecStartI8Ptr,
>> +                             ConstantInt::get(IntptrTy,
>> sizeof(uint64_t)));
>> +    SecStartPtr = IRB.CreatePointerCast(GEP, Ty);
>> +  } else {
>> +    SecStartPtr = IRB.CreatePointerCast(SecStart, Ty);
>> +  }
>>    std::tie(CtorFunc, std::ignore) = createSanitizerCtorAndInitFunctions(
>>        M, SanCovModuleCtorName, InitFunctionName, {Ty, Ty},
>> -      {IRB.CreatePointerCast(SecStart, Ty),
>> IRB.CreatePointerCast(SecEnd, Ty)});
>> +      {SecStartPtr, IRB.CreatePointerCast(SecEnd, Ty)});
>>
>>    if (TargetTriple.supportsCOMDAT()) {
>>      // Use comdat to dedup CtorFunc.
>> @@ -397,9 +408,20 @@ bool SanitizerCoverageModule::runOnModul
>>      Function *InitFunction = declareSanitizerInitFunction(
>>          M, SanCovPCsInitName, {IntptrPtrTy, IntptrPtrTy});
>>      IRBuilder<> IRBCtor(Ctor->getEntryBlock().getTerminator());
>> -    IRBCtor.CreateCall(InitFunction,
>> -                       {IRB.CreatePointerCast(SecStartEnd.first,
>> IntptrPtrTy),
>> -                        IRB.CreatePointerCast(SecStartEnd.second,
>> IntptrPtrTy)});
>> +    Value *SecStartPtr = nullptr;
>> +    // Account for the fact that on windows-msvc __start_pc_table
>> actually
>> +    // points to a uint64_t before the start of the PC table.
>> +    if (TargetTriple.getObjectFormat() == Triple::COFF) {
>> +      auto SecStartI8Ptr = IRB.CreatePointerCast(SecStartEnd.first,
>> Int8PtrTy);
>> +      auto GEP = IRB.CreateGEP(SecStartI8Ptr,
>> +                               ConstantInt::get(IntptrTy,
>> sizeof(uint64_t)));
>> +      SecStartPtr = IRB.CreatePointerCast(GEP, IntptrPtrTy);
>> +    } else {
>> +      SecStartPtr = IRB.CreatePointerCast(SecStartEnd.first,
>> IntptrPtrTy);
>> +    }
>> +    IRBCtor.CreateCall(
>> +        InitFunction,
>> +        {SecStartPtr, IRB.CreatePointerCast(SecStartEnd.second,
>> IntptrPtrTy)});
>>    }
>>    // We don't reference these arrays directly in any of our runtime
>> functions,
>>    // so we need to prevent them from being dead stripped.
>> @@ -809,8 +831,13 @@ void SanitizerCoverageModule::InjectCove
>>
>>  std::string
>>  SanitizerCoverageModule::getSectionName(const std::string &Section)
>> const {
>> -  if (TargetTriple.getObjectFormat() == Triple::COFF)
>> -    return ".SCOV$M";
>> +  if (TargetTriple.getObjectFormat() == Triple::COFF) {
>> +    if (Section == SanCovCountersSectionName)
>> +      return ".SCOV$CM";
>> +    if (Section == SanCovPCsSectionName)
>> +      return ".SCOVP$M";
>> +    return ".SCOV$GM"; // For SanCovGuardsSectionName.
>> +  }
>>    if (TargetTriple.isOSBinFormatMachO())
>>      return "__DATA,__" + Section;
>>    return "__" + Section;
>>
>> Added: llvm/trunk/test/Instrumentation/SanitizerCoverage/coff-pc-
>> table-inline-8bit-counters.ll
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/
>> SanitizerCoverage/coff-pc-table-inline-8bit-counters.ll?
>> rev=341082&view=auto
>> ============================================================
>> ==================
>> --- llvm/trunk/test/Instrumentation/SanitizerCoverage/coff-pc-table-inline-8bit-counters.ll
>> (added)
>> +++ llvm/trunk/test/Instrumentation/SanitizerCoverage/coff-pc-table-inline-8bit-counters.ll
>> Thu Aug 30 08:54:44 2018
>> @@ -0,0 +1,12 @@
>> +; Checks that the PC and 8-bit Counter Arrays are placed in their own
>> sections in COFF binaries.
>> +; RUN: opt < %s -sancov -sanitizer-coverage-level=1
>> -sanitizer-coverage-inline-8bit-counters=1
>> -sanitizer-coverage-pc-table=1 -S | FileCheck %s
>> +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
>> +target triple = "x86_64-pc-windows-msvc19.14.26433"
>> +
>> +define void @foo() {
>> +entry:
>> +  ret void
>> +}
>> +
>> +; CHECK-DAG: section ".SCOV{{\$}}CM",
>> +; CHECK-DAG: section ".SCOVP{{\$}}M",
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181011/7c6d8136/attachment.html>


More information about the llvm-commits mailing list