Skip to content

Commit 5600e83

Browse files
committed
Cleanup loggings and comments
1 parent 75dc996 commit 5600e83

File tree

5 files changed

+45
-52
lines changed

5 files changed

+45
-52
lines changed

llvm/test/tools/llvm-profgen/missing-dwarf.test

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
; Test --load-function-from-symbol=0
88
; RUN: llvm-profgen --format=text --unsymbolized-profile=%t.prof --binary=%S/Inputs/missing-dwarf.exe --output=%t1 --fill-zero-for-all-funcs --show-detailed-warning --use-offset=0 --load-function-from-symbol=0 2>&1 | FileCheck %s --check-prefix=CHECK-NO-LOAD-SYMTAB
99

10-
; CHECK-NO-LOAD-SYMTAB: warning: 100.00%(1/1) of function range samples do not belong to any function
11-
; CHECK-NO-LOAD-SYMTAB-NEXT: warning: 100.00%(1/1) of LBR source samples do not belong to any function
12-
; CHECK-NO-LOAD-SYMTAB-NEXT: warning: 100.00%(1/1) of LBR target samples do not belong to any function
10+
; CHECK-NO-LOAD-SYMTAB: warning: Loading of DWARF info completed, but no binary functions have been retrieved.
1311

1412
; Test --load-function-from-symbol=1
1513
; RUN: llvm-profgen --format=text --unsymbolized-profile=%t.prof --binary=%S/Inputs/missing-dwarf.exe --output=%t2 --fill-zero-for-all-funcs --show-detailed-warning --use-offset=0 --load-function-from-symbol=1

llvm/tools/llvm-profgen/PerfReader.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,13 +1274,17 @@ void PerfScriptReader::warnInvalidRange() {
12741274

12751275
const char *EndNotBoundaryMsg = "Range is not on instruction boundary, "
12761276
"likely due to profile and binary mismatch.";
1277+
const char *DanglingRangeMsg = "Range does not belong to any functions, "
1278+
"likely from PLT, .init or .fini section.";
12771279
const char *RangeCrossFuncMsg =
12781280
"Fall through range should not cross function boundaries, likely due to "
12791281
"profile and binary mismatch.";
12801282
const char *BogusRangeMsg = "Range start is after or too far from range end.";
12811283

12821284
uint64_t TotalRangeNum = 0;
12831285
uint64_t InstNotBoundary = 0;
1286+
uint64_t UnmatchedRange = 0;
1287+
uint64_t RecoveredRange = 0;
12841288
uint64_t RangeCrossFunc = 0;
12851289
uint64_t BogusRange = 0;
12861290

@@ -1300,8 +1304,14 @@ void PerfScriptReader::warnInvalidRange() {
13001304
}
13011305

13021306
auto *FRange = Binary->findFuncRange(StartAddress);
1303-
if (!FRange)
1307+
if (!FRange) {
1308+
UnmatchedRange += I.second;
1309+
WarnInvalidRange(StartAddress, EndAddress, DanglingRangeMsg);
13041310
continue;
1311+
}
1312+
1313+
if (FRange->Func->FromSymtab)
1314+
RecoveredRange += I.second;
13051315

13061316
if (EndAddress >= FRange->EndAddress) {
13071317
RangeCrossFunc += I.second;
@@ -1319,6 +1329,12 @@ void PerfScriptReader::warnInvalidRange() {
13191329
emitWarningSummary(
13201330
InstNotBoundary, TotalRangeNum,
13211331
"of samples are from ranges that are not on instruction boundary.");
1332+
emitWarningSummary(
1333+
UnmatchedRange, TotalRangeNum,
1334+
"of samples are from ranges that do not belong to any functions.");
1335+
emitWarningSummary(
1336+
RecoveredRange, TotalRangeNum,
1337+
"of samples are from ranges that belong to functions recovered from symbol table.");
13221338
emitWarningSummary(
13231339
RangeCrossFunc, TotalRangeNum,
13241340
"of samples are from ranges that do cross function boundaries.");

llvm/tools/llvm-profgen/ProfileGenerator.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -449,62 +449,29 @@ bool ProfileGeneratorBase::collectFunctionsFromRawProfile(
449449
// Go through all the stacks, ranges and branches in sample counters, use
450450
// the start of the range to look up the function it belongs and record the
451451
// function.
452-
uint64_t ErrStkAddr = 0, ErrFuncRange = 0, ErrSrc = 0, ErrTgt = 0;
453-
uint64_t TotalStkAddr = 0, TotalFuncRange = 0, TotalSrc = 0, TotalTgt = 0;
454452
for (const auto &CI : *SampleCounters) {
455453
if (const auto *CtxKey = dyn_cast<AddrBasedCtxKey>(CI.first.getPtr())) {
456454
for (auto StackAddr : CtxKey->Context) {
457-
uint64_t Inc = Binary->addressIsCode(StackAddr) ? 1 : 0;
458-
TotalStkAddr += Inc;
459455
if (FuncRange *FRange = Binary->findFuncRange(StackAddr))
460456
ProfiledFunctions.insert(FRange->Func);
461-
else
462-
ErrStkAddr += Inc;
463457
}
464458
}
465459

466460
for (auto Item : CI.second.RangeCounter) {
467461
uint64_t StartAddress = Item.first.first;
468-
uint64_t Inc = Binary->addressIsCode(StartAddress) ? Item.second : 0;
469-
TotalFuncRange += Inc;
470462
if (FuncRange *FRange = Binary->findFuncRange(StartAddress))
471463
ProfiledFunctions.insert(FRange->Func);
472-
else
473-
ErrFuncRange += Inc;
474464
}
475465

476466
for (auto Item : CI.second.BranchCounter) {
477467
uint64_t SourceAddress = Item.first.first;
478468
uint64_t TargetAddress = Item.first.second;
479-
uint64_t SrcInc = Binary->addressIsCode(SourceAddress) ? Item.second : 0;
480-
uint64_t TgtInc = Binary->addressIsCode(TargetAddress) ? Item.second : 0;
481-
TotalSrc += SrcInc;
482469
if (FuncRange *FRange = Binary->findFuncRange(SourceAddress))
483470
ProfiledFunctions.insert(FRange->Func);
484-
else
485-
ErrSrc += SrcInc;
486-
TotalTgt += TgtInc;
487471
if (FuncRange *FRange = Binary->findFuncRange(TargetAddress))
488472
ProfiledFunctions.insert(FRange->Func);
489-
else
490-
ErrTgt += TgtInc;
491473
}
492474
}
493-
494-
if (ErrStkAddr)
495-
emitWarningSummary(
496-
ErrStkAddr, TotalStkAddr,
497-
"of stack address samples do not belong to any function");
498-
if (ErrFuncRange)
499-
emitWarningSummary(
500-
ErrFuncRange, TotalFuncRange,
501-
"of function range samples do not belong to any function");
502-
if (ErrSrc)
503-
emitWarningSummary(ErrSrc, TotalSrc,
504-
"of LBR source samples do not belong to any function");
505-
if (ErrTgt)
506-
emitWarningSummary(ErrTgt, TotalTgt,
507-
"of LBR target samples do not belong to any function");
508475
return true;
509476
}
510477

llvm/tools/llvm-profgen/ProfiledBinary.cpp

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -831,13 +831,21 @@ void ProfiledBinary::populateSymbolAddressList(const ObjectFile *Obj) {
831831
}
832832

833833
void ProfiledBinary::populateSymbolsFromBinary(const ObjectFile *Obj) {
834-
// Load binary functions from symbol table when Debug info is incomplete
835-
const SmallVector<StringRef> Suffixes(
836-
{".destroy", ".resume", ".llvm.", ".cold", ".warm"});
834+
// Load binary functions from symbol table when Debug info is incomplete.
835+
// Strip the internal suffixes which are not reflected in the DWARF info.
836+
const SmallVector<StringRef, 6> Suffixes(
837+
{
838+
// Internal suffixes from CoroSplit pass
839+
".cleanup", ".destroy", ".resume",
840+
// Internal suffixes from Bolt
841+
".cold", ".warm",
842+
// Compiler internal
843+
".llvm.",
844+
});
837845
StringRef FileName = Obj->getFileName();
838846
for (const SymbolRef &Symbol : Obj->symbols()) {
839847
const SymbolRef::Type Type = unwrapOrError(Symbol.getType(), FileName);
840-
const uint64_t Addr = unwrapOrError(Symbol.getAddress(), FileName);
848+
const uint64_t StartAddr = unwrapOrError(Symbol.getAddress(), FileName);
841849
const StringRef Name = unwrapOrError(Symbol.getName(), FileName);
842850
uint64_t Size = 0;
843851
if (isa<ELFObjectFileBase>(Symbol.getObject())) {
@@ -855,25 +863,26 @@ void ProfiledBinary::populateSymbolsFromBinary(const ObjectFile *Obj) {
855863
auto &Func = Ret.first->second;
856864
if (Ret.second) {
857865
Func.FuncName = Ret.first->first;
866+
Func.FromSymtab = true;
858867
HashBinaryFunctions[MD5Hash(StringRef(SymName))] = &Func;
859868
}
860869

861-
if (auto Range = findFuncRange(Addr)) {
862-
if (Ret.second && ShowDetailedWarning)
870+
if (auto Range = findFuncRange(StartAddr)) {
871+
if (Ret.second && Range->getFuncName() != SymName && ShowDetailedWarning)
863872
WithColor::warning()
864-
<< "Symbol " << Name << " start address "
865-
<< format("%8" PRIx64, Addr) << " already exists in DWARF at "
866-
<< format("%8" PRIx64, Range->StartAddress) << " in function "
867-
<< Range->getFuncName() << "\n";
873+
<< "Conflicting symbol " << Name << " already exists in DWARF as "
874+
<< Range->getFuncName() << " at address " << format("%8" PRIx64, StartAddr)
875+
<< ". The DWARF indicates a range from " << format("%8" PRIx64, Range->StartAddress) << " to "
876+
<< format("%8" PRIx64, Range->EndAddress) << "\n";
868877
} else {
869878
// Store/Update Function Range from SymTab
870-
Func.Ranges.emplace_back(Addr, Addr + Size);
879+
Func.Ranges.emplace_back(StartAddr, StartAddr + Size);
871880

872-
auto R = StartAddrToFuncRangeMap.emplace(Addr, FuncRange());
881+
auto R = StartAddrToFuncRangeMap.emplace(StartAddr, FuncRange());
873882
FuncRange &FRange = R.first->second;
874883
FRange.Func = &Func;
875-
FRange.StartAddress = Addr;
876-
FRange.EndAddress = Addr + Size;
884+
FRange.StartAddress = StartAddr;
885+
FRange.EndAddress = StartAddr + Size;
877886
}
878887
}
879888
}
@@ -902,8 +911,10 @@ void ProfiledBinary::loadSymbolsFromDWARFUnit(DWARFUnit &CompilationUnit) {
902911
// BinaryFunction indexed by the name.
903912
auto Ret = BinaryFunctions.emplace(Name, BinaryFunction());
904913
auto &Func = Ret.first->second;
905-
if (Ret.second)
914+
if (Ret.second) {
906915
Func.FuncName = Ret.first->first;
916+
Func.FromSymtab = false;
917+
}
907918

908919
for (const auto &Range : Ranges) {
909920
uint64_t StartAddress = Range.LowPC;

llvm/tools/llvm-profgen/ProfiledBinary.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ struct BinaryFunction {
7676
StringRef FuncName;
7777
// End of range is an exclusive bound.
7878
RangesTy Ranges;
79+
bool FromSymtab;
7980

8081
uint64_t getFuncSize() {
8182
uint64_t Sum = 0;

0 commit comments

Comments
 (0)