diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp index 9a5b56fc52e2f..c229917a1ecb5 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,12 @@ void Writer::calculateCustomSections() { // Strip debug section in that option was specified. if (stripDebug && name.starts_with(".debug_")) continue; + // If the object is not live, discard `__llvm_covfun` and `__llvm_covmap` + // sections since `__llvm_prf_*` segments have already been discarded. + 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);