Skip to content

Commit 9f28587

Browse files
[llvm-cov][WebAssembly] Align coverage mapping section to 8 bytes
Wasm format does not have a good way to insert padding bytes to align the start of a section contents because the size of each section header depends on the size of the section contents (leb128 encoding). This design makes it difficult to align section contents to a specific alignment to load them by post-processing tools like llvm-cov. This patch copies the coverage mapping section to a new buffer that is aligned to 8 bytes if the original section is not aligned. This is not an ideal solution but it works for now.
1 parent d16b107 commit 9f28587

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,16 @@ loadBinaryFormat(std::unique_ptr<Binary> Bin, StringRef Arch,
11361136
return CoverageMappingOrErr.takeError();
11371137
StringRef CoverageMapping = CoverageMappingOrErr.get();
11381138

1139+
// If the coverage mapping section is not aligned to 8 bytes, copy it to a
1140+
// new buffer that is. Wasm format typically has unaligned section contents
1141+
// because it doesn't have a good way to insert padding bytes.
1142+
std::unique_ptr<MemoryBuffer> CoverageMappingBufferOwner;
1143+
if (!isAddrAligned(Align(8), CoverageMapping.data())) {
1144+
CoverageMappingBufferOwner =
1145+
MemoryBuffer::getMemBufferCopy(CoverageMapping);
1146+
CoverageMapping = CoverageMappingBufferOwner->getBuffer();
1147+
}
1148+
11391149
// Look for the coverage records section (Version4 only).
11401150
auto CoverageRecordsSections = lookupSections(*OF, IPSK_covfun);
11411151

0 commit comments

Comments
 (0)