[llvm] r362082 - [llvm-readobj/llvm-readelf] - Implement GNU style dumper of the SHT_GNU_verdef section.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Thu May 30 03:36:52 PDT 2019
Author: grimar
Date: Thu May 30 03:36:52 2019
New Revision: 362082
URL: http://llvm.org/viewvc/llvm-project?rev=362082&view=rev
Log:
[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
Modified:
llvm/trunk/test/tools/llvm-readobj/elf-versioninfo.test
llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
Modified: llvm/trunk/test/tools/llvm-readobj/elf-versioninfo.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/elf-versioninfo.test?rev=362082&r1=362081&r2=362082&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/elf-versioninfo.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/elf-versioninfo.test Thu May 30 03:36:52 2019
@@ -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)
Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=362082&r1=362081&r2=362082&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Thu May 30 03:36:52 2019
@@ -3491,18 +3491,7 @@ void GNUStyle<ELFT>::printVersionSymbolS
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";
@@ -3524,6 +3513,48 @@ static std::string verNeedFlagToString(u
}
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) {
if (!Sec)
@@ -3558,7 +3589,7 @@ void GNUStyle<ELFT>::printVersionDepende
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;
}
More information about the llvm-commits
mailing list