[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.
This commit is contained in:
Fangrui Song 2021-03-22 23:05:36 -07:00
parent 9fec382601
commit 3c81822ec5
3 changed files with 15 additions and 6 deletions

View File

@ -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())

View File

@ -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

View File

@ -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