[PATCH] D98903: [SanitizerCoverage] Make __start_/__stop_ symbols extern_weak
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 18 16:46:12 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9558456b5370: [SanitizerCoverage] Make __start_/__stop_ symbols extern_weak (authored by MaskRay).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D98903/new/
https://reviews.llvm.org/D98903
Files:
llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
llvm/test/Instrumentation/SanitizerCoverage/inline-8bit-counters.ll
llvm/test/Instrumentation/SanitizerCoverage/inline-bool-flag.ll
llvm/test/Instrumentation/SanitizerCoverage/pc-table.ll
Index: llvm/test/Instrumentation/SanitizerCoverage/pc-table.ll
===================================================================
--- llvm/test/Instrumentation/SanitizerCoverage/pc-table.ll
+++ llvm/test/Instrumentation/SanitizerCoverage/pc-table.ll
@@ -22,6 +22,8 @@
}
; CHECK: private constant [6 x i64*] [{{.*}}@foo{{.*}}blockaddress{{.*}}blockaddress{{.*}}], section "__sancov_pcs", comdat($foo), align 8
+; CHECK: @__start___sancov_pcs = extern_weak hidden global i64
+; CHECK-NEXT: @__stop___sancov_pcs = extern_weak hidden global i64
; CHECK: define internal void @sancov.module_ctor
; CHECK: call void @__sanitizer_cov
; CHECK: call void @__sanitizer_cov_pcs_init
Index: llvm/test/Instrumentation/SanitizerCoverage/inline-bool-flag.ll
===================================================================
--- llvm/test/Instrumentation/SanitizerCoverage/inline-bool-flag.ll
+++ llvm/test/Instrumentation/SanitizerCoverage/inline-bool-flag.ll
@@ -4,6 +4,8 @@
; CHECK: $foo = comdat noduplicates
; CHECK: @__sancov_gen_ = private global [1 x i1] zeroinitializer, section "__sancov_bools", comdat($foo), align 1{{$}}
+; CHECK: @__start___sancov_bools = extern_weak hidden global i1
+; CHECK-NEXT: @__stop___sancov_bools = extern_weak hidden global i1
; CHECK-NOT: @llvm.used =
; CHECK: @llvm.compiler.used = appending global [1 x i8*] [i8* bitcast ([1 x i1]* @__sancov_gen_ to i8*)], section "llvm.metadata"
Index: llvm/test/Instrumentation/SanitizerCoverage/inline-8bit-counters.ll
===================================================================
--- llvm/test/Instrumentation/SanitizerCoverage/inline-8bit-counters.ll
+++ llvm/test/Instrumentation/SanitizerCoverage/inline-8bit-counters.ll
@@ -2,11 +2,14 @@
; RUN: opt < %s -sancov -sanitizer-coverage-level=1 -sanitizer-coverage-inline-8bit-counters=1 -S -enable-new-pm=0 | FileCheck %s
; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=1 -sanitizer-coverage-inline-8bit-counters=1 -S | FileCheck %s
+; CHECK: @__sancov_gen_ = private global [1 x i8] zeroinitializer, section "__sancov_cntrs", comdat($foo), align 1
+; CHECK: @__start___sancov_cntrs = extern_weak hidden global i8
+; CHECK-NEXT: @__stop___sancov_cntrs = extern_weak hidden global i8
+
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-unknown-linux-gnu"
define void @foo() {
entry:
-; CHECK: section "__sancov_cntrs", comdat($foo), align 1
; CHECK: %0 = load i8, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @__sancov_gen_, i64 0, i64 0), align 1, !nosanitize
; CHECK: %1 = add i8 %0, 1
; CHECK: store i8 %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @__sancov_gen_, i64 0, i64 0), align 1, !nosanitize
Index: llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -328,13 +328,15 @@
std::pair<Value *, Value *>
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::ExternalLinkage,
- nullptr, getSectionStart(Section));
+ M, Ty->getPointerElementType(), false,
+ GlobalVariable::ExternalWeakLinkage, nullptr, getSectionStart(Section));
SecStart->setVisibility(GlobalValue::HiddenVisibility);
GlobalVariable *SecEnd = new GlobalVariable(
- M, Ty->getPointerElementType(), false, GlobalVariable::ExternalLinkage,
- nullptr, getSectionEnd(Section));
+ M, Ty->getPointerElementType(), false,
+ GlobalVariable::ExternalWeakLinkage, nullptr, getSectionEnd(Section));
SecEnd->setVisibility(GlobalValue::HiddenVisibility);
IRBuilder<> IRB(M.getContext());
if (!TargetTriple.isOSBinFormatCOFF())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98903.331722.patch
Type: text/x-patch
Size: 4244 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210318/89fb0a43/attachment.bin>
More information about the llvm-commits
mailing list