Skip to content

Commit

Permalink
[llvm-profgen] More tweaks to warnings (#68608)
Browse files Browse the repository at this point in the history
Tweaking warnings more to avoid flooding user log.
  • Loading branch information
htyu committed Oct 23, 2023
1 parent a244183 commit 7a3db65
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
46 changes: 31 additions & 15 deletions llvm/tools/llvm-profgen/ProfiledBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,6 @@ bool ProfiledBinary::dissassembleSymbol(std::size_t SI, ArrayRef<uint8_t> Bytes,
if (ShowDisassembly)
outs() << '<' << SymbolName << ">:\n";

auto WarnInvalidInsts = [](uint64_t Start, uint64_t End) {
WithColor::warning() << "Invalid instructions at "
<< format("%8" PRIx64, Start) << " - "
<< format("%8" PRIx64, End) << "\n";
};

uint64_t Address = StartAddress;
// Size of a consecutive invalid instruction range starting from Address -1
// backwards.
Expand Down Expand Up @@ -578,7 +572,8 @@ bool ProfiledBinary::dissassembleSymbol(std::size_t SI, ArrayRef<uint8_t> Bytes,
}

if (InvalidInstLength) {
WarnInvalidInsts(Address - InvalidInstLength, Address - 1);
AddrsWithInvalidInstruction.insert(
{Address - InvalidInstLength, Address - 1});
InvalidInstLength = 0;
}
} else {
Expand All @@ -589,7 +584,8 @@ bool ProfiledBinary::dissassembleSymbol(std::size_t SI, ArrayRef<uint8_t> Bytes,
}

if (InvalidInstLength)
WarnInvalidInsts(Address - InvalidInstLength, Address - 1);
AddrsWithInvalidInstruction.insert(
{Address - InvalidInstLength, Address - 1});

if (ShowDisassembly)
outs() << "\n";
Expand Down Expand Up @@ -708,6 +704,19 @@ void ProfiledBinary::disassemble(const ELFObjectFileBase *Obj) {
}
}

if (!AddrsWithInvalidInstruction.empty()) {
if (ShowDetailedWarning) {
for (auto &Addr : AddrsWithInvalidInstruction) {
WithColor::warning()
<< "Invalid instructions at " << format("%8" PRIx64, Addr.first)
<< " - " << format("%8" PRIx64, Addr.second) << "\n";
}
}
WithColor::warning() << "Found " << AddrsWithInvalidInstruction.size()
<< " invalid instructions\n";
AddrsWithInvalidInstruction.clear();
}

// Dissassemble rodata section to check if FS discriminator symbol exists.
checkUseFSDiscriminator(Obj, AllSymbols);
}
Expand Down Expand Up @@ -792,10 +801,12 @@ void ProfiledBinary::loadSymbolsFromDWARFUnit(DWARFUnit &CompilationUnit) {
FRange.StartAddress = StartAddress;
FRange.EndAddress = EndAddress;
} else {
WithColor::warning()
<< "Duplicated symbol start address at "
<< format("%8" PRIx64, StartAddress) << " "
<< R.first->second.getFuncName() << " and " << Name << "\n";
AddrsWithMultipleSymbols.insert(StartAddress);
if (ShowDetailedWarning)
WithColor::warning()
<< "Duplicated symbol start address at "
<< format("%8" PRIx64, StartAddress) << " "
<< R.first->second.getFuncName() << " and " << Name << "\n";
}
}
}
Expand Down Expand Up @@ -839,14 +850,18 @@ void ProfiledBinary::loadSymbolsFromDWARF(ObjectFile &Obj) {
if (BinaryFunctions.empty())
WithColor::warning() << "Loading of DWARF info completed, but no binary "
"functions have been retrieved.\n";


// Populate the hash binary function map for MD5 function name lookup. This
// is done after BinaryFunctions are finalized.
for (auto &BinaryFunction : BinaryFunctions) {
HashBinaryFunctions[MD5Hash(StringRef(BinaryFunction.first))] =
&BinaryFunction.second;
}

if (!AddrsWithMultipleSymbols.empty()) {
WithColor::warning() << "Found " << AddrsWithMultipleSymbols.size()
<< " start addresses with multiple symbols\n";
AddrsWithMultipleSymbols.clear();
}
}

void ProfiledBinary::populateSymbolListFromDWARF(
Expand Down Expand Up @@ -881,7 +896,8 @@ SampleContextFrameVector ProfiledBinary::symbolize(const InstructionPointer &IP,
SampleContextFrameVector CallStack;
for (int32_t I = InlineStack.getNumberOfFrames() - 1; I >= 0; I--) {
const auto &CallerFrame = InlineStack.getFrame(I);
if (CallerFrame.FunctionName.empty() || (CallerFrame.FunctionName == "<invalid>"))
if (CallerFrame.FunctionName.empty() ||
(CallerFrame.FunctionName == "<invalid>"))
break;

StringRef FunctionName(CallerFrame.FunctionName);
Expand Down
6 changes: 5 additions & 1 deletion llvm/tools/llvm-profgen/ProfiledBinary.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ class ProfiledBinary {
// GUID to Elf symbol start address map
DenseMap<uint64_t, uint64_t> SymbolStartAddrs;

// These maps are for temporary use of warning diagnosis.
DenseSet<int64_t> AddrsWithMultipleSymbols;
DenseSet<std::pair<uint64_t, uint64_t>> AddrsWithInvalidInstruction;

// Start address to Elf symbol GUID map
std::unordered_multimap<uint64_t, uint64_t> StartAddrToSymMap;

Expand Down Expand Up @@ -529,7 +533,7 @@ class ProfiledBinary {

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

MissingFrameInferrer* getMissingContextInferrer() {
MissingFrameInferrer *getMissingContextInferrer() {
return MissingContextInferrer.get();
}

Expand Down

0 comments on commit 7a3db65

Please sign in to comment.