Skip to content

Commit fbe266c

Browse files
Merge branch 'main' into dev/NormalizeMemref
2 parents b03d3fe + 2a005bf commit fbe266c

File tree

2,245 files changed

+162573
-64454
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,245 files changed

+162573
-64454
lines changed

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,15 @@ struct SegmentInfo {
7171
uint64_t FileOffset; /// Offset in the file.
7272
uint64_t FileSize; /// Size in file.
7373
uint64_t Alignment; /// Alignment of the segment.
74+
bool IsExecutable; /// Is the executable bit set on the Segment?
7475

7576
void print(raw_ostream &OS) const {
76-
OS << "SegmentInfo { Address: 0x"
77-
<< Twine::utohexstr(Address) << ", Size: 0x"
78-
<< Twine::utohexstr(Size) << ", FileOffset: 0x"
77+
OS << "SegmentInfo { Address: 0x" << Twine::utohexstr(Address)
78+
<< ", Size: 0x" << Twine::utohexstr(Size) << ", FileOffset: 0x"
7979
<< Twine::utohexstr(FileOffset) << ", FileSize: 0x"
8080
<< Twine::utohexstr(FileSize) << ", Alignment: 0x"
81-
<< Twine::utohexstr(Alignment) << "}";
81+
<< Twine::utohexstr(Alignment) << ", " << (IsExecutable ? "x" : " ")
82+
<< "}";
8283
};
8384
};
8485

bolt/include/bolt/Core/BinaryData.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ inline raw_ostream &operator<<(raw_ostream &OS,
226226
Sep = ",\n ";
227227
TotalCount += AccessInfo.Count;
228228
}
229-
SS.flush();
230229

231230
OS << TotalCount << " total counts : " << TempString;
232231
return OS;

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ inline raw_ostream &operator<<(raw_ostream &OS,
117117
TotalCount += CSP.Count;
118118
TotalMispreds += CSP.Mispreds;
119119
}
120-
SS.flush();
121120

122121
OS << TotalCount << " (" << TotalMispreds << " misses) :" << TempString;
123122
return OS;

bolt/include/bolt/Rewrite/RewriteInstance.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -510,12 +510,11 @@ class RewriteInstance {
510510
};
511511

512512
/// Different types of X86-64 PLT sections.
513-
const PLTSectionInfo X86_64_PLTSections[4] = {
514-
{ ".plt", 16 },
515-
{ ".plt.got", 8 },
516-
{ ".plt.sec", 8 },
517-
{ nullptr, 0 }
518-
};
513+
const PLTSectionInfo X86_64_PLTSections[5] = {{".plt", 16},
514+
{".plt.got", 8},
515+
{".plt.sec", 8},
516+
{".iplt", 16},
517+
{nullptr, 0}};
519518

520519
/// AArch64 PLT sections.
521520
const PLTSectionInfo AArch64_PLTSections[4] = {

bolt/lib/Core/BinaryContext.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,6 +2021,9 @@ BinaryContext::getBaseAddressForMapping(uint64_t MMapAddress,
20212021
// Find a segment with a matching file offset.
20222022
for (auto &KV : SegmentMapInfo) {
20232023
const SegmentInfo &SegInfo = KV.second;
2024+
// Only consider executable segments.
2025+
if (!SegInfo.IsExecutable)
2026+
continue;
20242027
// FileOffset is got from perf event,
20252028
// and it is equal to alignDown(SegInfo.FileOffset, pagesize).
20262029
// If the pagesize is not equal to SegInfo.Alignment.

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ bool shouldPrint(const BinaryFunction &Function) {
165165
}
166166
}
167167

168+
std::optional<StringRef> Origin = Function.getOriginSectionName();
169+
if (Origin && llvm::any_of(opts::PrintOnly, [&](const std::string &Name) {
170+
return Name == *Origin;
171+
}))
172+
return true;
173+
168174
return false;
169175
}
170176

bolt/lib/Passes/RetpolineInsertion.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ std::string createRetpolineFunctionTag(BinaryContext &BC,
181181
if (BrInfo.isReg()) {
182182
BC.InstPrinter->printRegName(TagOS, BrInfo.BranchReg);
183183
TagOS << "_";
184-
TagOS.flush();
185184
return Tag;
186185
}
187186

@@ -212,7 +211,6 @@ std::string createRetpolineFunctionTag(BinaryContext &BC,
212211
BC.InstPrinter->printRegName(TagOS, MemRef.SegRegNum);
213212
}
214213

215-
TagOS.flush();
216214
return Tag;
217215
}
218216

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2043,7 +2043,8 @@ std::error_code DataAggregator::parseMMapEvents() {
20432043
// size of the mapping, but we know it should not exceed the segment
20442044
// alignment value. Hence we are performing an approximate check.
20452045
return SegInfo.Address >= MMapInfo.MMapAddress &&
2046-
SegInfo.Address - MMapInfo.MMapAddress < SegInfo.Alignment;
2046+
SegInfo.Address - MMapInfo.MMapAddress < SegInfo.Alignment &&
2047+
SegInfo.IsExecutable;
20472048
});
20482049
if (!MatchFound) {
20492050
errs() << "PERF2BOLT-WARNING: ignoring mapping of " << NameToUse

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,9 @@ Error RewriteInstance::discoverStorage() {
526526
NextAvailableOffset = std::max(NextAvailableOffset,
527527
Phdr.p_offset + Phdr.p_filesz);
528528

529-
BC->SegmentMapInfo[Phdr.p_vaddr] = SegmentInfo{Phdr.p_vaddr,
530-
Phdr.p_memsz,
531-
Phdr.p_offset,
532-
Phdr.p_filesz,
533-
Phdr.p_align};
529+
BC->SegmentMapInfo[Phdr.p_vaddr] = SegmentInfo{
530+
Phdr.p_vaddr, Phdr.p_memsz, Phdr.p_offset,
531+
Phdr.p_filesz, Phdr.p_align, ((Phdr.p_flags & ELF::PF_X) != 0)};
534532
if (BC->TheTriple->getArch() == llvm::Triple::x86_64 &&
535533
Phdr.p_vaddr >= BinaryContext::KernelStartX86_64)
536534
BC->IsLinuxKernel = true;
@@ -1533,7 +1531,7 @@ void RewriteInstance::createPLTBinaryFunction(uint64_t TargetAddress,
15331531

15341532
MCSymbol *Symbol = Rel->Symbol;
15351533
if (!Symbol) {
1536-
if (!BC->isAArch64() || !Rel->Addend || !Rel->isIRelative())
1534+
if (BC->isRISCV() || !Rel->Addend || !Rel->isIRelative())
15371535
return;
15381536

15391537
// IFUNC trampoline without symbol
@@ -4247,7 +4245,6 @@ void RewriteInstance::addBoltInfoSection() {
42474245
<< "command line:";
42484246
for (int I = 0; I < Argc; ++I)
42494247
DescOS << " " << Argv[I];
4250-
DescOS.flush();
42514248

42524249
// Encode as GNU GOLD VERSION so it is easily printable by 'readelf -n'
42534250
const std::string BoltInfo =
@@ -4270,7 +4267,6 @@ void RewriteInstance::encodeBATSection() {
42704267
raw_string_ostream DescOS(DescStr);
42714268

42724269
BAT->write(*BC, DescOS);
4273-
DescOS.flush();
42744270

42754271
const std::string BoltInfo =
42764272
BinarySection::encodeELFNote("BOLT", DescStr, BinarySection::NT_BOLT_BAT);

bolt/lib/RuntimeLibs/InstrumentationRuntimeLibrary.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ std::string InstrumentationRuntimeLibrary::buildTables(BinaryContext &BC) {
314314
}
315315
// Our string table lives immediately after descriptions vector
316316
OS << Summary->StringTable;
317-
OS.flush();
318317

319318
return TablesStr;
320319
}

0 commit comments

Comments
 (0)