[PATCH] D62520: [llvm-readobj/llvm-readelf] - Implement GNU style dumper of the SHT_GNU_verdef section.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 28 06:17:56 PDT 2019
grimar created this revision.
grimar added reviewers: jhenderson, rupprecht, jakehehrlich.
grimar added a parent revision: D62516: [llvm-readobj/llvm-readelf] - Implement GNU style dumper of the SHT_GNU_verneed section..
It was not implemented yet, we had only LLVM style dumper implemented.
Section description is here: http://refspecs.linux-foundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/symversion.html
This patch is rebased on top of D62516 <https://reviews.llvm.org/D62516> (which implements GNU-style SHT_GNU_verneed dumping).
https://reviews.llvm.org/D62520
Files:
test/tools/llvm-readobj/elf-versioninfo.test
tools/llvm-readobj/ELFDumper.cpp
Index: tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- tools/llvm-readobj/ELFDumper.cpp
+++ tools/llvm-readobj/ELFDumper.cpp
@@ -3489,17 +3489,7 @@
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";
-}
-
-static std::string verNeedFlagToString(unsigned Flags) {
+static std::string versionFlagToString(unsigned Flags) {
if (Flags == 0)
return "none";
@@ -3520,6 +3510,47 @@
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;
+ }
+}
+
template <class ELFT>
void GNUStyle<ELFT>::printVersionDependencySection(const ELFFile<ELFT> *Obj,
const Elf_Shdr *Sec) {
@@ -3555,7 +3586,7 @@
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;
}
Index: test/tools/llvm-readobj/elf-versioninfo.test
===================================================================
--- test/tools/llvm-readobj/elf-versioninfo.test
+++ test/tools/llvm-readobj/elf-versioninfo.test
@@ -82,7 +82,12 @@
GNU-VERDEF-NEXT: 000: 0 (*local*) 1 (*global*) 1 (*global*) 3 (VERSION2)
GNU-VERDEF-NEXT: 004: 1 (*global*) 2 (VERSION1) 2 (VERSION1) 3 (VERSION2)
-GNU-VERDEF: Dumper for .gnu.version_d is not implemented
+GNU-VERDEF: Version definition section '.gnu.version_d' contains 3 entries:
+GNU-VERDEF-NEXT: Addr: 000000000000025c Offset: 0x00025c Link: 2 (.dynstr)
+GNU-VERDEF-NEXT: 0x0000: Rev: 1 Flags: BASE Index: 1 Cnt: 1 Name: blah
+GNU-VERDEF-NEXT: 0x001c: Rev: 1 Flags: none Index: 2 Cnt: 1 Name: VERSION1
+GNU-VERDEF-NEXT: 0x0038: Rev: 1 Flags: none Index: 3 Cnt: 2 Name: VERSION2
+GNU-VERDEF-NEXT: 0x0054: Parent 1: VERSION1
RUN: llvm-readobj -V %p/Inputs/verneed.elf-x86-64 | FileCheck %s --check-prefix=LLVM-VERNEED
RUN: llvm-readelf -V %p/Inputs/verneed.elf-x86-64 | FileCheck %s --check-prefix=GNU-VERNEED
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62520.201647.patch
Type: text/x-patch
Size: 4198 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190528/f7c54a12/attachment.bin>
More information about the llvm-commits
mailing list