Skip to content

Commit 7a3db65

Browse files
authored
[llvm-profgen] More tweaks to warnings (#68608)
Tweaking warnings more to avoid flooding user log.
1 parent a244183 commit 7a3db65

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

llvm/tools/llvm-profgen/ProfiledBinary.cpp

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,6 @@ bool ProfiledBinary::dissassembleSymbol(std::size_t SI, ArrayRef<uint8_t> Bytes,
480480
if (ShowDisassembly)
481481
outs() << '<' << SymbolName << ">:\n";
482482

483-
auto WarnInvalidInsts = [](uint64_t Start, uint64_t End) {
484-
WithColor::warning() << "Invalid instructions at "
485-
<< format("%8" PRIx64, Start) << " - "
486-
<< format("%8" PRIx64, End) << "\n";
487-
};
488-
489483
uint64_t Address = StartAddress;
490484
// Size of a consecutive invalid instruction range starting from Address -1
491485
// backwards.
@@ -578,7 +572,8 @@ bool ProfiledBinary::dissassembleSymbol(std::size_t SI, ArrayRef<uint8_t> Bytes,
578572
}
579573

580574
if (InvalidInstLength) {
581-
WarnInvalidInsts(Address - InvalidInstLength, Address - 1);
575+
AddrsWithInvalidInstruction.insert(
576+
{Address - InvalidInstLength, Address - 1});
582577
InvalidInstLength = 0;
583578
}
584579
} else {
@@ -589,7 +584,8 @@ bool ProfiledBinary::dissassembleSymbol(std::size_t SI, ArrayRef<uint8_t> Bytes,
589584
}
590585

591586
if (InvalidInstLength)
592-
WarnInvalidInsts(Address - InvalidInstLength, Address - 1);
587+
AddrsWithInvalidInstruction.insert(
588+
{Address - InvalidInstLength, Address - 1});
593589

594590
if (ShowDisassembly)
595591
outs() << "\n";
@@ -708,6 +704,19 @@ void ProfiledBinary::disassemble(const ELFObjectFileBase *Obj) {
708704
}
709705
}
710706

707+
if (!AddrsWithInvalidInstruction.empty()) {
708+
if (ShowDetailedWarning) {
709+
for (auto &Addr : AddrsWithInvalidInstruction) {
710+
WithColor::warning()
711+
<< "Invalid instructions at " << format("%8" PRIx64, Addr.first)
712+
<< " - " << format("%8" PRIx64, Addr.second) << "\n";
713+
}
714+
}
715+
WithColor::warning() << "Found " << AddrsWithInvalidInstruction.size()
716+
<< " invalid instructions\n";
717+
AddrsWithInvalidInstruction.clear();
718+
}
719+
711720
// Dissassemble rodata section to check if FS discriminator symbol exists.
712721
checkUseFSDiscriminator(Obj, AllSymbols);
713722
}
@@ -792,10 +801,12 @@ void ProfiledBinary::loadSymbolsFromDWARFUnit(DWARFUnit &CompilationUnit) {
792801
FRange.StartAddress = StartAddress;
793802
FRange.EndAddress = EndAddress;
794803
} else {
795-
WithColor::warning()
796-
<< "Duplicated symbol start address at "
797-
<< format("%8" PRIx64, StartAddress) << " "
798-
<< R.first->second.getFuncName() << " and " << Name << "\n";
804+
AddrsWithMultipleSymbols.insert(StartAddress);
805+
if (ShowDetailedWarning)
806+
WithColor::warning()
807+
<< "Duplicated symbol start address at "
808+
<< format("%8" PRIx64, StartAddress) << " "
809+
<< R.first->second.getFuncName() << " and " << Name << "\n";
799810
}
800811
}
801812
}
@@ -839,14 +850,18 @@ void ProfiledBinary::loadSymbolsFromDWARF(ObjectFile &Obj) {
839850
if (BinaryFunctions.empty())
840851
WithColor::warning() << "Loading of DWARF info completed, but no binary "
841852
"functions have been retrieved.\n";
842-
843-
844853
// Populate the hash binary function map for MD5 function name lookup. This
845854
// is done after BinaryFunctions are finalized.
846855
for (auto &BinaryFunction : BinaryFunctions) {
847856
HashBinaryFunctions[MD5Hash(StringRef(BinaryFunction.first))] =
848857
&BinaryFunction.second;
849858
}
859+
860+
if (!AddrsWithMultipleSymbols.empty()) {
861+
WithColor::warning() << "Found " << AddrsWithMultipleSymbols.size()
862+
<< " start addresses with multiple symbols\n";
863+
AddrsWithMultipleSymbols.clear();
864+
}
850865
}
851866

852867
void ProfiledBinary::populateSymbolListFromDWARF(
@@ -881,7 +896,8 @@ SampleContextFrameVector ProfiledBinary::symbolize(const InstructionPointer &IP,
881896
SampleContextFrameVector CallStack;
882897
for (int32_t I = InlineStack.getNumberOfFrames() - 1; I >= 0; I--) {
883898
const auto &CallerFrame = InlineStack.getFrame(I);
884-
if (CallerFrame.FunctionName.empty() || (CallerFrame.FunctionName == "<invalid>"))
899+
if (CallerFrame.FunctionName.empty() ||
900+
(CallerFrame.FunctionName == "<invalid>"))
885901
break;
886902

887903
StringRef FunctionName(CallerFrame.FunctionName);

llvm/tools/llvm-profgen/ProfiledBinary.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ class ProfiledBinary {
230230
// GUID to Elf symbol start address map
231231
DenseMap<uint64_t, uint64_t> SymbolStartAddrs;
232232

233+
// These maps are for temporary use of warning diagnosis.
234+
DenseSet<int64_t> AddrsWithMultipleSymbols;
235+
DenseSet<std::pair<uint64_t, uint64_t>> AddrsWithInvalidInstruction;
236+
233237
// Start address to Elf symbol GUID map
234238
std::unordered_multimap<uint64_t, uint64_t> StartAddrToSymMap;
235239

@@ -529,7 +533,7 @@ class ProfiledBinary {
529533

530534
void flushSymbolizer() { Symbolizer.reset(); }
531535

532-
MissingFrameInferrer* getMissingContextInferrer() {
536+
MissingFrameInferrer *getMissingContextInferrer() {
533537
return MissingContextInferrer.get();
534538
}
535539

0 commit comments

Comments
 (0)