[lld] [Coverage][WebAssembly] Remove InstrProf sections if object not live (PR #172023)

via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 12 19:05:43 PST 2025


https://github.com/Spxg updated https://github.com/llvm/llvm-project/pull/172023

>From dc84939ccf9b71a1516ffce53ec690ab22d7b5a5 Mon Sep 17 00:00:00 2001
From: Spxg <unsafe at outlook.es>
Date: Sat, 13 Dec 2025 10:39:01 +0800
Subject: [PATCH] [Coverage][WebAssembly] Remove InstrProf sections if object
 not live

If the object is not live, remove `__llvm_covfun` and `__llvm_covmap`
sections since `__llvm_prf_*` segments have already been removed.
---
 lld/wasm/Writer.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index 9a5b56fc52e2f..94d613b44d135 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -26,6 +26,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/BinaryFormat/Wasm.h"
+#include "llvm/ProfileData/InstrProf.h"
 #include "llvm/Support/FileOutputBuffer.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Parallel.h"
@@ -153,6 +154,13 @@ void Writer::calculateCustomSections() {
       // Strip debug section in that option was specified.
       if (stripDebug && name.starts_with(".debug_"))
         continue;
+      // If the object is not live, remove `__llvm_covfun` and `__llvm_covmap`
+      // sections since `__llvm_prf_*` segments have already been removed.
+      if (!file->isLive() &&
+          (name == getInstrProfSectionName(IPSK_covfun, Triple::Wasm) ||
+           name == getInstrProfSectionName(IPSK_covmap, Triple::Wasm))) {
+        continue;
+      }
       // Otherwise include custom sections by default and concatenate their
       // contents.
       customSectionMapping[name].push_back(section);



More information about the llvm-commits mailing list