[llvm-readobj/llvm-readelf] - Implement GNU style dumper of the SHT_GNU_verdef section.

It was not implemented yet, we had only LLVM style dumper implemented.
Section description is here: https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/symversion.html

Differential revision: https://reviews.llvm.org/D62520

llvm-svn: 362082
This commit is contained in:
George Rimar 2019-05-30 10:36:52 +00:00
parent 32aac1727a
commit c372f41c18
2 changed files with 53 additions and 16 deletions

View File

@ -30,7 +30,7 @@ Sections:
Flags: 0
VersionNdx: 2
Hash: 175630257
Names:
Names:
- VERSION1
- Version: 1
Flags: 0
@ -64,7 +64,7 @@ Sections:
Hash: 1937
Flags: 0
Other: 6
DynamicSymbols:
DynamicSymbols:
- Name: sym1
Binding: STB_GLOBAL
- Name: sym2
@ -174,7 +174,13 @@ DynamicSymbols:
# GNU-NEXT: 000: 0 (*local*) 2 (VERSION1) 3 (VERSION2) 4 (v1)
# GNU-NEXT: 004: 5 (v2) 6 (v3)
# GNU-EMPTY:
# GNU-NEXT: Dumper for .gnu.version_d is not implemented
# GNU-NEXT: Version definition section '.gnu.version_d' contains 3 entries:
# GNU-NEXT: Addr: 0000000000000000 Offset: 0x00028c Link: 8 (.dynstr)
# GNU-NEXT: 0x0000: Rev: 1 Flags: none Index: 2 Cnt: 1 Name: VERSION1
# GNU-NEXT: 0x001c: Rev: 1 Flags: none Index: 3 Cnt: 2 Name: VERSION2
# GNU-NEXT: 0x0038: Parent 1: VERSION1
# GNU-NEXT: 0x001c: Rev: 1 Flags: none Index: 3 Cnt: 2 Name: VERSION2
# GNU-NEXT: 0x0038: Parent 1: VERSION1
# GNU-EMPTY:
# GNU-NEXT: Version needs section '.gnu.version_r' contains 2 entries:
# GNU-NEXT: Addr: 0000000000000000 Offset: 0x0002cc Link: 8 (.dynstr)

View File

@ -3491,18 +3491,7 @@ void GNUStyle<ELFT>::printVersionSymbolSection(const ELFFile<ELFT> *Obj,
OS << '\n';
}
template <class ELFT>
void GNUStyle<ELFT>::printVersionDefinitionSection(const ELFFile<ELFT> *Obj,
const Elf_Shdr *Sec) {
if (!Sec)
return;
StringRef SecName = unwrapOrError(Obj->getSectionName(Sec));
OS << "Dumper for " << SecName << " is not implemented\n";
OS << '\n';
}
static std::string verNeedFlagToString(unsigned Flags) {
static std::string versionFlagToString(unsigned Flags) {
if (Flags == 0)
return "none";
@ -3523,6 +3512,48 @@ static std::string verNeedFlagToString(unsigned Flags) {
return Ret;
}
template <class ELFT>
void GNUStyle<ELFT>::printVersionDefinitionSection(const ELFFile<ELFT> *Obj,
const Elf_Shdr *Sec) {
if (!Sec)
return;
unsigned VerDefsNum = Sec->sh_info;
printGNUVersionSectionProlog(OS, "Version definition", VerDefsNum, Obj, Sec);
const Elf_Shdr *StrTabSec = unwrapOrError(Obj->getSection(Sec->sh_link));
StringRef StringTable(
reinterpret_cast<const char *>(Obj->base() + StrTabSec->sh_offset),
StrTabSec->sh_size);
const uint8_t *VerdefBuf = unwrapOrError(Obj->getSectionContents(Sec)).data();
const uint8_t *Begin = VerdefBuf;
while (VerDefsNum--) {
const Elf_Verdef *Verdef = reinterpret_cast<const Elf_Verdef *>(VerdefBuf);
OS << format(" 0x%04x: Rev: %u Flags: %s Index: %u Cnt: %u",
VerdefBuf - Begin, (unsigned)Verdef->vd_version,
versionFlagToString(Verdef->vd_flags).c_str(),
(unsigned)Verdef->vd_ndx, (unsigned)Verdef->vd_cnt);
const uint8_t *VerdauxBuf = VerdefBuf + Verdef->vd_aux;
const Elf_Verdaux *Verdaux =
reinterpret_cast<const Elf_Verdaux *>(VerdauxBuf);
OS << format(" Name: %s\n",
StringTable.drop_front(Verdaux->vda_name).data());
for (unsigned I = 1; I < Verdef->vd_cnt; ++I) {
VerdauxBuf += Verdaux->vda_next;
Verdaux = reinterpret_cast<const Elf_Verdaux *>(VerdauxBuf);
OS << format(" 0x%04x: Parent %u: %s\n", VerdauxBuf - Begin, I,
StringTable.drop_front(Verdaux->vda_name).data());
}
VerdefBuf += Verdef->vd_next;
}
OS << '\n';
}
template <class ELFT>
void GNUStyle<ELFT>::printVersionDependencySection(const ELFFile<ELFT> *Obj,
const Elf_Shdr *Sec) {
@ -3558,7 +3589,7 @@ void GNUStyle<ELFT>::printVersionDependencySection(const ELFFile<ELFT> *Obj,
OS << format(" 0x%04x: Name: %s Flags: %s Version: %u\n",
reinterpret_cast<const uint8_t *>(Vernaux) - SecData.begin(),
StringTable.drop_front(Vernaux->vna_name).data(),
verNeedFlagToString(Vernaux->vna_flags).c_str(),
versionFlagToString(Vernaux->vna_flags).c_str(),
(unsigned)Vernaux->vna_other);
VernauxBuf += Vernaux->vna_next;
}