diff options
author | Jonathan Metzman <metzman@chromium.org> | 2019-01-14 21:02:02 +0000 |
---|---|---|
committer | Jonathan Metzman <metzman@chromium.org> | 2019-01-14 21:02:02 +0000 |
commit | e159a0dd1a04a10fab2663dc5bc80a51b09e3636 (patch) | |
tree | 936306a961b459ca56291302168388fccdd6146d /llvm/lib | |
parent | 6e39af016fd8bbcf06adc5ef2d9b93de30648ff3 (diff) | |
download | bcm5719-llvm-e159a0dd1a04a10fab2663dc5bc80a51b09e3636.tar.gz bcm5719-llvm-e159a0dd1a04a10fab2663dc5bc80a51b09e3636.zip |
[SanitizerCoverage][NFC] Use appendToUsed instead of include
Summary:
Use appendToUsed instead of include to ensure that
SanitizerCoverage's constructors are not stripped.
Also, use isOSBinFormatCOFF() to determine if target
binary format is COFF.
Reviewers: pcc
Reviewed By: pcc
Subscribers: hiraditya
Differential Revision: https://reviews.llvm.org/D56369
llvm-svn: 351118
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp index 7f683ad089f..729197fcefd 100644 --- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -264,7 +264,7 @@ SanitizerCoverageModule::CreateSecStartEnd(Module &M, const char *Section, SecEnd->setVisibility(GlobalValue::HiddenVisibility); IRBuilder<> IRB(M.getContext()); Value *SecEndPtr = IRB.CreatePointerCast(SecEnd, Ty); - if (TargetTriple.getObjectFormat() != Triple::COFF) + if (!TargetTriple.isOSBinFormatCOFF()) return std::make_pair(IRB.CreatePointerCast(SecStart, Ty), SecEndPtr); // Account for the fact that on windows-msvc __start_* symbols actually @@ -293,24 +293,15 @@ Function *SanitizerCoverageModule::CreateInitCallsForSections( appendToGlobalCtors(M, CtorFunc, SanCtorAndDtorPriority); } - if (TargetTriple.getObjectFormat() == Triple::COFF) { + if (TargetTriple.isOSBinFormatCOFF()) { // In COFF files, if the contructors are set as COMDAT (they are because // COFF supports COMDAT) and the linker flag /OPT:REF (strip unreferenced // functions and data) is used, the constructors get stripped. To prevent - // this, give the constructors weak ODR linkage and tell the linker to - // always include the sancov constructor. This way the linker can - // deduplicate the constructors but always leave one copy. + // this, give the constructors weak ODR linkage and ensure the linker knows + // to include the sancov constructor. This way the linker can deduplicate + // the constructors but always leave one copy. CtorFunc->setLinkage(GlobalValue::WeakODRLinkage); - SmallString<20> PartialIncDirective("/include:"); - // Get constructor's mangled name in order to support i386. - SmallString<40> MangledName; - Mangler().getNameWithPrefix(MangledName, CtorFunc, true); - Twine IncDirective = PartialIncDirective + MangledName; - Metadata *Args[1] = {MDString::get(*C, IncDirective.str())}; - MDNode *MetadataNode = MDNode::get(*C, Args); - NamedMDNode *NamedMetadata = - M.getOrInsertNamedMetadata("llvm.linker.options"); - NamedMetadata->addOperand(MetadataNode); + appendToUsed(M, CtorFunc); } return CtorFunc; } @@ -833,7 +824,7 @@ void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F, BasicBlock &BB, std::string SanitizerCoverageModule::getSectionName(const std::string &Section) const { - if (TargetTriple.getObjectFormat() == Triple::COFF) { + if (TargetTriple.isOSBinFormatCOFF()) { if (Section == SanCovCountersSectionName) return ".SCOV$CM"; if (Section == SanCovPCsSectionName) |