[llvm] [Coverage] Mark coverage sections as metadata sections on COFF. (PR #76834)
Zequan Wu via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 3 09:05:13 PST 2024
https://github.com/ZequanWu created https://github.com/llvm/llvm-project/pull/76834
Mark `.lcovmap$M`, `.lcovfun$M`, `.lcovd` and `.lcovn` as metadata sections on COFF so they are not loaded into memory.
>From 10d80bc106441829d7865b201a0b6d9c3a1dc6c1 Mon Sep 17 00:00:00 2001
From: Zequan Wu <zequanwu at google.com>
Date: Wed, 3 Jan 2024 12:01:50 -0500
Subject: [PATCH] [Coverage] Mark coverage sections as metadata sections on
COFF.
---
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 11 ++++++++++-
llvm/test/CodeGen/X86/cov-sections.ll | 15 +++++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/CodeGen/X86/cov-sections.ll
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 6e69dc66429d31..a69b71451736fa 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -1669,9 +1669,18 @@ static int getSelectionForCOFF(const GlobalValue *GV) {
MCSection *TargetLoweringObjectFileCOFF::getExplicitSectionGlobal(
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
+ StringRef Name = GO->getSection();
+ if (Name == getInstrProfSectionName(IPSK_covmap, Triple::COFF,
+ /*AddSegmentInfo=*/false) ||
+ Name == getInstrProfSectionName(IPSK_covfun, Triple::COFF,
+ /*AddSegmentInfo=*/false) ||
+ Name == getInstrProfSectionName(IPSK_covdata, Triple::COFF,
+ /*AddSegmentInfo=*/false) ||
+ Name == getInstrProfSectionName(IPSK_covname, Triple::COFF,
+ /*AddSegmentInfo=*/false))
+ Kind = SectionKind::getMetadata();
int Selection = 0;
unsigned Characteristics = getCOFFSectionFlags(Kind, TM);
- StringRef Name = GO->getSection();
StringRef COMDATSymName = "";
if (GO->hasComdat()) {
Selection = getSelectionForCOFF(GO);
diff --git a/llvm/test/CodeGen/X86/cov-sections.ll b/llvm/test/CodeGen/X86/cov-sections.ll
new file mode 100644
index 00000000000000..6c4f3f079f38e3
--- /dev/null
+++ b/llvm/test/CodeGen/X86/cov-sections.ll
@@ -0,0 +1,15 @@
+; RUN: llc < %s -mtriple=x86_64-pc-windows-msvc -filetype=obj -o - | llvm-readobj -S - | FileCheck %s
+
+ at covmap = private global i32 0, section ".lcovmap$M"
+ at covfun = private global i32 0, section ".lcovfun$M"
+ at covname = private global i32 0, section ".lcovd"
+ at covdata= private global i32 0, section ".lcovn"
+
+; CHECK: Name: .lcovmap$M
+; CHECK: IMAGE_SCN_MEM_DISCARDABLE (0x2000000)
+; CHECK: Name: .lcovfun$M
+; CHECK: IMAGE_SCN_MEM_DISCARDABLE (0x2000000)
+; CHECK: Name: .lcovd
+; CHECK: IMAGE_SCN_MEM_DISCARDABLE (0x2000000)
+; CHECK: Name: .lcovn
+; CHECK: IMAGE_SCN_MEM_DISCARDABLE (0x2000000)
More information about the llvm-commits
mailing list