forked from OSchip/llvm-project
[llvm-readelf] - Split GNUStyle<ELFT>::printHashHistogram. NFC.
As was mentioned in review comments for D80204, `printHashHistogram` has 2 lambdas that are probably too large and deserves splitting into member functions. This patch does it. Differential revision: https://reviews.llvm.org/D80546
This commit is contained in:
parent
1e9462a201
commit
d804b334ed
llvm/tools/llvm-readobj
|
@ -230,7 +230,7 @@ public:
|
|||
|
||||
void printStackMap() const override;
|
||||
|
||||
void printHashHistogram() override;
|
||||
void printHashHistograms() override;
|
||||
|
||||
void printCGProfile() override;
|
||||
void printAddrsig() override;
|
||||
|
@ -742,7 +742,7 @@ public:
|
|||
const Elf_Shdr *Sec) = 0;
|
||||
virtual void printVersionDependencySection(const ELFFile<ELFT> *Obj,
|
||||
const Elf_Shdr *Sec) = 0;
|
||||
virtual void printHashHistogram(const ELFFile<ELFT> *Obj) = 0;
|
||||
virtual void printHashHistograms(const ELFFile<ELFT> *Obj) = 0;
|
||||
virtual void printCGProfile(const ELFFile<ELFT> *Obj) = 0;
|
||||
virtual void printAddrsig(const ELFFile<ELFT> *Obj) = 0;
|
||||
virtual void printNotes(const ELFFile<ELFT> *Obj) = 0;
|
||||
|
@ -811,7 +811,7 @@ public:
|
|||
const Elf_Shdr *Sec) override;
|
||||
void printVersionDependencySection(const ELFFile<ELFT> *Obj,
|
||||
const Elf_Shdr *Sec) override;
|
||||
void printHashHistogram(const ELFFile<ELFT> *Obj) override;
|
||||
void printHashHistograms(const ELFFile<ELFT> *Obj) override;
|
||||
void printCGProfile(const ELFFile<ELFT> *Obj) override;
|
||||
void printAddrsig(const ELFFile<ELFT> *Obj) override;
|
||||
void printNotes(const ELFFile<ELFT> *Obj) override;
|
||||
|
@ -823,6 +823,9 @@ public:
|
|||
void printMipsABIFlags(const ELFObjectFile<ELFT> *Obj) override;
|
||||
|
||||
private:
|
||||
void printHashHistogram(const Elf_Hash &HashTable);
|
||||
void printGnuHashHistogram(const Elf_GnuHash &GnuHashTable);
|
||||
|
||||
struct Field {
|
||||
std::string Str;
|
||||
unsigned Column;
|
||||
|
@ -932,7 +935,7 @@ public:
|
|||
const Elf_Shdr *Sec) override;
|
||||
void printVersionDependencySection(const ELFFile<ELFT> *Obj,
|
||||
const Elf_Shdr *Sec) override;
|
||||
void printHashHistogram(const ELFFile<ELFT> *Obj) override;
|
||||
void printHashHistograms(const ELFFile<ELFT> *Obj) override;
|
||||
void printCGProfile(const ELFFile<ELFT> *Obj) override;
|
||||
void printAddrsig(const ELFFile<ELFT> *Obj) override;
|
||||
void printNotes(const ELFFile<ELFT> *Obj) override;
|
||||
|
@ -2287,8 +2290,8 @@ template <class ELFT> void ELFDumper<ELFT>::printHashSymbols() {
|
|||
ELFDumperStyle->printHashSymbols(ObjF->getELFFile());
|
||||
}
|
||||
|
||||
template <class ELFT> void ELFDumper<ELFT>::printHashHistogram() {
|
||||
ELFDumperStyle->printHashHistogram(ObjF->getELFFile());
|
||||
template <class ELFT> void ELFDumper<ELFT>::printHashHistograms() {
|
||||
ELFDumperStyle->printHashHistograms(ObjF->getELFFile());
|
||||
}
|
||||
|
||||
template <class ELFT> void ELFDumper<ELFT>::printCGProfile() {
|
||||
|
@ -4556,13 +4559,8 @@ void GNUStyle<ELFT>::printVersionDependencySection(const ELFFile<ELFT> *Obj,
|
|||
OS << '\n';
|
||||
}
|
||||
|
||||
// Hash histogram shows statistics of how efficient the hash was for the
|
||||
// dynamic symbol table. The table shows number of hash buckets for different
|
||||
// lengths of chains as absolute number and percentage of the total buckets.
|
||||
// Additionally cumulative coverage of symbols for each set of buckets.
|
||||
template <class ELFT>
|
||||
void GNUStyle<ELFT>::printHashHistogram(const ELFFile<ELFT> *Obj) {
|
||||
auto PrintHashHist = [&](const Elf_Hash &HashTable) {
|
||||
void GNUStyle<ELFT>::printHashHistogram(const Elf_Hash &HashTable) {
|
||||
size_t NBucket = HashTable.nbucket;
|
||||
size_t NChain = HashTable.nchain;
|
||||
ArrayRef<Elf_Word> Buckets = HashTable.buckets();
|
||||
|
@ -4584,8 +4582,8 @@ void GNUStyle<ELFT>::printHashHistogram(const ELFFile<ELFT> *Obj) {
|
|||
if (C == ELF::STN_UNDEF)
|
||||
break;
|
||||
if (Visited[C]) {
|
||||
reportWarning(
|
||||
createError(".hash section is invalid: bucket " + Twine(C) +
|
||||
reportWarning(createError(".hash section is invalid: bucket " +
|
||||
Twine(C) +
|
||||
": a cycle was detected in the linked chain"),
|
||||
this->FileName);
|
||||
break;
|
||||
|
@ -4615,9 +4613,10 @@ void GNUStyle<ELFT>::printHashHistogram(const ELFFile<ELFT> *Obj) {
|
|||
(Count[I] * 100.0) / NBucket,
|
||||
(CumulativeNonZero * 100.0) / TotalSyms);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
auto PrintGnuHashHist = [&](const Elf_GnuHash &GnuHashTable) {
|
||||
template <class ELFT>
|
||||
void GNUStyle<ELFT>::printGnuHashHistogram(const Elf_GnuHash &GnuHashTable) {
|
||||
size_t NBucket = GnuHashTable.nbuckets;
|
||||
ArrayRef<Elf_Word> Buckets = GnuHashTable.buckets();
|
||||
unsigned NumSyms = this->dumper()->dynamic_symbols().size();
|
||||
|
@ -4633,7 +4632,6 @@ void GNUStyle<ELFT>::printHashHistogram(const ELFFile<ELFT> *Obj) {
|
|||
return;
|
||||
|
||||
std::vector<size_t> ChainLen(NBucket, 0);
|
||||
|
||||
for (size_t B = 0; B < NBucket; B++) {
|
||||
if (!Buckets[B])
|
||||
continue;
|
||||
|
@ -4664,16 +4662,22 @@ void GNUStyle<ELFT>::printHashHistogram(const ELFFile<ELFT> *Obj) {
|
|||
(Count[I] * 100.0) / NBucket,
|
||||
(CumulativeNonZero * 100.0) / TotalSyms);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Hash histogram shows statistics of how efficient the hash was for the
|
||||
// dynamic symbol table. The table shows the number of hash buckets for
|
||||
// different lengths of chains as an absolute number and percentage of the total
|
||||
// buckets, and the cumulative coverage of symbols for each set of buckets.
|
||||
template <class ELFT>
|
||||
void GNUStyle<ELFT>::printHashHistograms(const ELFFile<ELFT> *Obj) {
|
||||
// Print histogram for the .hash section.
|
||||
if (const Elf_Hash *HashTable = this->dumper()->getHashTable())
|
||||
if (checkHashTable(Obj, HashTable, this->FileName))
|
||||
PrintHashHist(*HashTable);
|
||||
printHashHistogram(*HashTable);
|
||||
|
||||
// Print histogram for the .gnu.hash section.
|
||||
if (const Elf_GnuHash *GnuHashTable = this->dumper()->getGnuHashTable())
|
||||
PrintGnuHashHist(*GnuHashTable);
|
||||
printGnuHashHistogram(*GnuHashTable);
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
|
@ -6417,7 +6421,7 @@ void LLVMStyle<ELFT>::printVersionDependencySection(const ELFFile<ELFT> *Obj,
|
|||
}
|
||||
|
||||
template <class ELFT>
|
||||
void LLVMStyle<ELFT>::printHashHistogram(const ELFFile<ELFT> *Obj) {
|
||||
void LLVMStyle<ELFT>::printHashHistograms(const ELFFile<ELFT> *Obj) {
|
||||
W.startLine() << "Hash Histogram not implemented!\n";
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ public:
|
|||
virtual void printLoadName() {}
|
||||
virtual void printVersionInfo() {}
|
||||
virtual void printGroupSections() {}
|
||||
virtual void printHashHistogram() {}
|
||||
virtual void printHashHistograms() {}
|
||||
virtual void printCGProfile() {}
|
||||
virtual void printAddrsig() {}
|
||||
virtual void printNotes() {}
|
||||
|
|
|
@ -502,7 +502,7 @@ static void dumpObject(const ObjectFile *Obj, ScopedPrinter &Writer,
|
|||
if (opts::SectionGroups)
|
||||
Dumper->printGroupSections();
|
||||
if (opts::HashHistogram)
|
||||
Dumper->printHashHistogram();
|
||||
Dumper->printHashHistograms();
|
||||
if (opts::CGProfile)
|
||||
Dumper->printCGProfile();
|
||||
if (opts::Addrsig)
|
||||
|
|
Loading…
Reference in New Issue