summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ProfileData/CoverageMappingReader.cpp
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2015-06-05 01:23:42 +0000
committerJustin Bogner <mail@justinbogner.com>2015-06-05 01:23:42 +0000
commitd49d8eec1266740d2c902e699b5fb31d4f11cd97 (patch)
tree7031bf61ca914fccb21c2d6a5e27c3fc7ccbf567 /llvm/lib/ProfileData/CoverageMappingReader.cpp
parent6e04f98bc3eea437c3bdf738e3e247dd04181f5d (diff)
downloadbcm5719-llvm-d49d8eec1266740d2c902e699b5fb31d4f11cd97.tar.gz
bcm5719-llvm-d49d8eec1266740d2c902e699b5fb31d4f11cd97.zip
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. llvm-svn: 239129
Diffstat (limited to 'llvm/lib/ProfileData/CoverageMappingReader.cpp')
-rw-r--r--llvm/lib/ProfileData/CoverageMappingReader.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/lib/ProfileData/CoverageMappingReader.cpp b/llvm/lib/ProfileData/CoverageMappingReader.cpp
index cf6cd58f953..ec531c3753e 100644
--- a/llvm/lib/ProfileData/CoverageMappingReader.cpp
+++ b/llvm/lib/ProfileData/CoverageMappingReader.cpp
@@ -19,6 +19,7 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/LEB128.h"
+#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
@@ -358,8 +359,12 @@ std::error_code readCoverageMappingData(
const char *CovBuf = Buf;
Buf += CoverageSize;
const char *CovEnd = Buf;
+
if (Buf > End)
return coveragemap_error::malformed;
+ // Each coverage map has an alignment of 8, so we need to adjust alignment
+ // before reading the next map.
+ Buf += alignmentAdjustment(Buf, 8);
while (FunBuf < FunEnd) {
// Read the function information
OpenPOWER on IntegriCloud