forked from OSchip/llvm-project
[BOLT] Fix merge-fdata and heatmap in BAT
Summary: merge-fdata for legacy format was simply appending all input strings to output, but the real format supports some header strings that can't be simply concatanated to output. Check for the header string used by BAT before merging fdata to avoid creating an output file with invalid lines (header in the middle of the fdata file). For heatmap, avoid reading BAT tables, since they won't be used. (cherry picked from FBD17943131)
This commit is contained in:
parent
d87f95065a
commit
698a4684ac
|
@ -1849,12 +1849,15 @@ void RewriteInstance::readSpecialSections() {
|
|||
|
||||
if (auto BATSec =
|
||||
BC->getUniqueSectionByName(BoltAddressTranslation::SECTION_NAME)) {
|
||||
// Do not read BAT when plotting a heatmap
|
||||
if (!opts::HeatmapMode) {
|
||||
if (std::error_code EC = BAT->parse(BATSec->getContents())) {
|
||||
errs() << "BOLT-ERROR: failed to parse BOLT address translation "
|
||||
"table.\n";
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (opts::PrintSections) {
|
||||
outs() << "BOLT-INFO: Sections from original binary:\n";
|
||||
|
|
|
@ -245,6 +245,8 @@ bool isYAML(const StringRef Filename) {
|
|||
|
||||
void mergeLegacyProfiles(const cl::list<std::string> &Filenames) {
|
||||
errs() << "Using legacy profile format.\n";
|
||||
bool BoltedCollection{false};
|
||||
bool First{true};
|
||||
for (auto &Filename : Filenames) {
|
||||
if (isYAML(Filename))
|
||||
report_error(Filename, "cannot mix YAML and legacy formats");
|
||||
|
@ -252,7 +254,28 @@ void mergeLegacyProfiles(const cl::list<std::string> &Filenames) {
|
|||
if (std::error_code EC = MB.getError())
|
||||
report_error(Filename, EC);
|
||||
errs() << "Merging data from " << Filename << "...\n";
|
||||
outs() << MB.get()->getBuffer();
|
||||
|
||||
auto Buf = MB.get()->getBuffer();
|
||||
// Check if the string "boltedcollection" is in the first line
|
||||
if (Buf.startswith("boltedcollection\n")) {
|
||||
if (!First && !BoltedCollection) {
|
||||
report_error(
|
||||
Filename,
|
||||
"cannot mix profile collected in BOLT and non-BOLT deployments");
|
||||
}
|
||||
BoltedCollection = true;
|
||||
if (!First)
|
||||
Buf = Buf.drop_front(17);
|
||||
} else {
|
||||
if (BoltedCollection) {
|
||||
report_error(
|
||||
Filename,
|
||||
"cannot mix profile collected in BOLT and non-BOLT deployments");
|
||||
}
|
||||
}
|
||||
|
||||
outs() << Buf;
|
||||
First = false;
|
||||
}
|
||||
errs() << "Profile from " << Filenames.size() << " files merged.\n";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue