[llvm] 3c81822 - [SanitizerCoverage] Use External on Windows

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 22 23:05:42 PDT 2021


Author: Fangrui Song
Date: 2021-03-22T23:05:36-07:00
New Revision: 3c81822ec5d2375d243ef2d43468807aa96383ec

URL: https://github.com/llvm/llvm-project/commit/3c81822ec5d2375d243ef2d43468807aa96383ec
DIFF: https://github.com/llvm/llvm-project/commit/3c81822ec5d2375d243ef2d43468807aa96383ec.diff

LOG: [SanitizerCoverage] Use External on Windows

This should fix https://reviews.llvm.org/D98903#2643589 though
it is not clear to me why ExternalWeak does not work.

Added: 
    

Modified: 
    llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
    llvm/test/Instrumentation/SanitizerCoverage/coff-pc-table-inline-8bit-counters.ll
    llvm/test/Instrumentation/SanitizerCoverage/coff-pc-table-inline-bool-flag.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
index 16ba84fdd00b7..166dd108f81bf 100644
--- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -330,13 +330,18 @@ ModuleSanitizerCoverage::CreateSecStartEnd(Module &M, const char *Section,
                                            Type *Ty) {
   // Use ExternalWeak so that if all sections are discarded due to section
   // garbage collection, the linker will not report undefined symbol errors.
-  GlobalVariable *SecStart = new GlobalVariable(
-      M, Ty->getPointerElementType(), false,
-      GlobalVariable::ExternalWeakLinkage, nullptr, getSectionStart(Section));
+  // Windows defines the start/stop symbols in compiler-rt so no need for
+  // ExternalWeak.
+  GlobalValue::LinkageTypes Linkage = TargetTriple.isOSBinFormatCOFF()
+                                          ? GlobalVariable::ExternalLinkage
+                                          : GlobalVariable::ExternalWeakLinkage;
+  GlobalVariable *SecStart =
+      new GlobalVariable(M, Ty->getPointerElementType(), false, Linkage,
+                         nullptr, getSectionStart(Section));
   SecStart->setVisibility(GlobalValue::HiddenVisibility);
-  GlobalVariable *SecEnd = new GlobalVariable(
-      M, Ty->getPointerElementType(), false,
-      GlobalVariable::ExternalWeakLinkage, nullptr, getSectionEnd(Section));
+  GlobalVariable *SecEnd =
+      new GlobalVariable(M, Ty->getPointerElementType(), false, Linkage,
+                         nullptr, getSectionEnd(Section));
   SecEnd->setVisibility(GlobalValue::HiddenVisibility);
   IRBuilder<> IRB(M.getContext());
   if (!TargetTriple.isOSBinFormatCOFF())

diff  --git a/llvm/test/Instrumentation/SanitizerCoverage/coff-pc-table-inline-8bit-counters.ll b/llvm/test/Instrumentation/SanitizerCoverage/coff-pc-table-inline-8bit-counters.ll
index 0134c7ea92c14..445a96d1e8c3c 100644
--- a/llvm/test/Instrumentation/SanitizerCoverage/coff-pc-table-inline-8bit-counters.ll
+++ b/llvm/test/Instrumentation/SanitizerCoverage/coff-pc-table-inline-8bit-counters.ll
@@ -11,3 +11,5 @@ entry:
 
 ; CHECK-DAG: section ".SCOV{{\$}}CM",
 ; CHECK-DAG: section ".SCOVP{{\$}}M",
+; CHECK:     @__start___sancov_cntrs = external hidden global i8
+; CHECK:     @__stop___sancov_cntrs = external hidden global i8

diff  --git a/llvm/test/Instrumentation/SanitizerCoverage/coff-pc-table-inline-bool-flag.ll b/llvm/test/Instrumentation/SanitizerCoverage/coff-pc-table-inline-bool-flag.ll
index d91714ba8fcf6..2f046f9587b80 100644
--- a/llvm/test/Instrumentation/SanitizerCoverage/coff-pc-table-inline-bool-flag.ll
+++ b/llvm/test/Instrumentation/SanitizerCoverage/coff-pc-table-inline-bool-flag.ll
@@ -11,3 +11,5 @@ entry:
 
 ; CHECK-DAG: section ".SCOV{{\$}}BM",
 ; CHECK-DAG: section ".SCOVP{{\$}}M",
+; CHECK:     @__start___sancov_bools = external hidden global i1
+; CHECK:     @__stop___sancov_bools = external hidden global i1


        


More information about the llvm-commits mailing list