diff options
author | Matt Morehouse <mascasa@google.com> | 2018-08-28 18:34:32 +0000 |
---|---|---|
committer | Matt Morehouse <mascasa@google.com> | 2018-08-28 18:34:32 +0000 |
commit | c6fff3b6f5b937b97a427e5e52ece058ce71b55b (patch) | |
tree | dd1da3133d27cd42b0900e0e5e4144776cc1d00b /llvm/lib/Transforms | |
parent | de6c421cc81f935b74f771638d674c745118ef8b (diff) | |
download | bcm5719-llvm-c6fff3b6f5b937b97a427e5e52ece058ce71b55b.tar.gz bcm5719-llvm-c6fff3b6f5b937b97a427e5e52ece058ce71b55b.zip |
[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: morehouse, kcc, eraman
Differential Revision: https://reviews.llvm.org/D51022
llvm-svn: 340860
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp index c0b219d1d1b..6a3ae2d9d33 100644 --- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -273,9 +273,15 @@ Function *SanitizerCoverageModule::CreateInitCallsForSections( auto SecStart = SecStartEnd.first; auto SecEnd = SecStartEnd.second; Function *CtorFunc; + auto SecStartPtr = IRB.CreatePointerCast(SecStart, Ty); + // 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) + SecStartPtr = IRB.CreateAdd(SecStartPtr, + ConstantInt::get(IntptrTy, sizeof(uint64_t))); 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 +403,15 @@ bool SanitizerCoverageModule::runOnModule(Module &M) { 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)}); + auto SecStartPtr = IRB.CreatePointerCast(SecStartEnd.first, IntptrPtrTy); + // 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) + SecStartPtr = IRB.CreateAdd(SecStartPtr, + ConstantInt::get(IntptrTy, sizeof(uint64_t))); + 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 +821,13 @@ void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F, BasicBlock &BB, 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; |