Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 0a64b6d

Browse files
committed
InstrProf: Fix reading of consecutive 32 bit coverage maps
When we generate coverage data, we explicitly set each coverage map's alignment to 8 (See InstrProfiling::lowerCoverageData), but when we read the coverage data, we assume consecutive maps are exactly adjacent. When we're dealing with 32 bit, maps can end on a 4 byte boundary, causing us to think the padding is part of the next record. Fix this by adjusting the buffer to an appropriately aligned address between records. This is pretty awkward to test, as it requires a binary with multiple coverage maps to hit, so we'd need to check in multiple source files and a binary blob as inputs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239129 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 85529a5 commit 0a64b6d

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

include/llvm/Support/MathExtras.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ inline uint64_t MinAlign(uint64_t A, uint64_t B) {
562562
///
563563
/// Alignment should be a power of two. This method rounds up, so
564564
/// alignAddr(7, 4) == 8 and alignAddr(8, 4) == 8.
565-
inline uintptr_t alignAddr(void *Addr, size_t Alignment) {
565+
inline uintptr_t alignAddr(const void *Addr, size_t Alignment) {
566566
assert(Alignment && isPowerOf2_64((uint64_t)Alignment) &&
567567
"Alignment is not a power of two!");
568568

@@ -573,7 +573,7 @@ inline uintptr_t alignAddr(void *Addr, size_t Alignment) {
573573

574574
/// \brief Returns the necessary adjustment for aligning \c Ptr to \c Alignment
575575
/// bytes, rounding up.
576-
inline size_t alignmentAdjustment(void *Ptr, size_t Alignment) {
576+
inline size_t alignmentAdjustment(const void *Ptr, size_t Alignment) {
577577
return alignAddr(Ptr, Alignment) - (uintptr_t)Ptr;
578578
}
579579

lib/ProfileData/CoverageMappingReader.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/Support/Debug.h"
2020
#include "llvm/Support/Endian.h"
2121
#include "llvm/Support/LEB128.h"
22+
#include "llvm/Support/MathExtras.h"
2223
#include "llvm/Support/raw_ostream.h"
2324

2425
using namespace llvm;
@@ -358,8 +359,12 @@ std::error_code readCoverageMappingData(
358359
const char *CovBuf = Buf;
359360
Buf += CoverageSize;
360361
const char *CovEnd = Buf;
362+
361363
if (Buf > End)
362364
return coveragemap_error::malformed;
365+
// Each coverage map has an alignment of 8, so we need to adjust alignment
366+
// before reading the next map.
367+
Buf += alignmentAdjustment(Buf, 8);
363368

364369
while (FunBuf < FunEnd) {
365370
// Read the function information

0 commit comments

Comments
 (0)