[llvm] r263050 - [llvm-readobj] Enable GNU style section group print
Hemant Kulkarni via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 9 11:16:13 PST 2016
Author: khemant
Date: Wed Mar 9 13:16:13 2016
New Revision: 263050
URL: http://llvm.org/viewvc/llvm-project?rev=263050&view=rev
Log:
[llvm-readobj] Enable GNU style section group print
Differential Revision: http://reviews.llvm.org/D17822
Modified:
llvm/trunk/test/tools/llvm-readobj/elf-groups.test
llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
Modified: llvm/trunk/test/tools/llvm-readobj/elf-groups.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/elf-groups.test?rev=263050&r1=263049&r2=263050&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/elf-groups.test (original)
+++ llvm/trunk/test/tools/llvm-readobj/elf-groups.test Wed Mar 9 13:16:13 2016
@@ -15,6 +15,8 @@
RUN: llvm-readobj -g %p/Inputs/elf-groups.x86_64 \
RUN: | FileCheck %s
+RUN: llvm-readobj -g -elf-output-style=GNU %p/Inputs/elf-groups.x86_64 \
+RUN: | FileCheck --check-prefix="GNU" %s
CHECK: Groups {
CHECK-NEXT: Group {
CHECK-NEXT: Name: .group (92)
@@ -37,3 +39,14 @@ CHECK-NEXT: .rela.text._Z3fooIi
CHECK-NEXT: ]
CHECK-NEXT: }
+GNU:COMDAT group section [ 1] `.group' [_Z3fooIcEvT_] contains 2 sections:
+GNU-NEXT: [Index] Name
+GNU-NEXT: [ 10] .text._Z3fooIcEvT_
+GNU-NEXT: [ 11] .rela.text._Z3fooIcEvT_
+GNU:COMDAT group section [ 2] `.group' [_Z3fooIiEvT_] contains 2 sections:
+GNU-NEXT: [Index] Name
+GNU-NEXT: [ 12] .text._Z3fooIiEvT_
+GNU-NEXT: [ 13] .rela.text._Z3fooIiEvT_
+GNU:COMDAT group section [ 3] `.group' [_ZNKSt9type_info4nameEv] contains 1 sections:
+GNU-NEXT: [Index] Name
+GNU-NEXT: [ 14] .text._ZNKSt9type_info4nameEv
Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=263050&r1=263049&r2=263050&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Wed Mar 9 13:16:13 2016
@@ -44,6 +44,21 @@ using namespace ELF;
#define ENUM_ENT_1(enum) \
{ #enum, #enum, ELF::enum }
+#define TYPEDEF_ELF_TYPES(ELFT) \
+ typedef ELFFile<ELFT> ELFO; \
+ typedef typename ELFO::Elf_Shdr Elf_Shdr; \
+ typedef typename ELFO::Elf_Sym Elf_Sym; \
+ typedef typename ELFO::Elf_Dyn Elf_Dyn; \
+ typedef typename ELFO::Elf_Dyn_Range Elf_Dyn_Range; \
+ typedef typename ELFO::Elf_Rel Elf_Rel; \
+ typedef typename ELFO::Elf_Rela Elf_Rela; \
+ typedef typename ELFO::Elf_Rela_Range Elf_Rela_Range; \
+ typedef typename ELFO::Elf_Phdr Elf_Phdr; \
+ typedef typename ELFO::Elf_Half Elf_Half; \
+ typedef typename ELFO::Elf_Ehdr Elf_Ehdr; \
+ typedef typename ELFO::Elf_Word Elf_Word; \
+ typedef typename ELFO::uintX_t uintX_t;
+
namespace {
template <class ELFT> class DumpStyle;
@@ -222,15 +237,17 @@ template <typename ELFT> class DumpStyle
public:
virtual void printFileHeaders(const ELFFile<ELFT> *Obj) = 0;
virtual ~DumpStyle() { }
+ virtual void printGroupSections(const ELFFile<ELFT> *Obj) = 0;
};
template <typename ELFT> class GNUStyle : public DumpStyle<ELFT> {
formatted_raw_ostream OS;
public:
- typedef typename ELFFile<ELFT>::Elf_Ehdr Elf_Ehdr;
+ TYPEDEF_ELF_TYPES(ELFT)
GNUStyle(StreamWriter &W) : OS(W.getOStream()) {}
void printFileHeaders(const ELFFile<ELFT> *Obj) override;
+ void printGroupSections(const ELFFile<ELFT> *Obj) override;
private:
template <typename T, typename TEnum>
@@ -244,10 +261,10 @@ private:
template <typename ELFT> class LLVMStyle : public DumpStyle<ELFT> {
public:
- typedef typename ELFFile<ELFT>::Elf_Ehdr Elf_Ehdr;
+ TYPEDEF_ELF_TYPES(ELFT)
LLVMStyle(StreamWriter &W) : W(W) {}
-
void printFileHeaders(const ELFFile<ELFT> *Obj) override;
+ void printGroupSections(const ELFFile<ELFT> *Obj) override;
private:
StreamWriter &W;
@@ -2251,37 +2268,7 @@ template <class ELFT> void ELFDumper<ELF
}
template <class ELFT> void ELFDumper<ELFT>::printGroupSections() {
- DictScope Lists(W, "Groups");
- uint32_t SectionIndex = 0;
- bool HasGroups = false;
- for (const Elf_Shdr &Sec : Obj->sections()) {
- if (Sec.sh_type == ELF::SHT_GROUP) {
- HasGroups = true;
- const Elf_Shdr *Symtab = unwrapOrError(Obj->getSection(Sec.sh_link));
- StringRef StrTable = unwrapOrError(Obj->getStringTableForSymtab(*Symtab));
- const Elf_Sym *Sym = Obj->template getEntry<Elf_Sym>(Symtab, Sec.sh_info);
- auto Data = unwrapOrError(
- Obj->template getSectionContentsAsArray<Elf_Word>(&Sec));
- DictScope D(W, "Group");
- StringRef Name = unwrapOrError(Obj->getSectionName(&Sec));
- W.printNumber("Name", Name, Sec.sh_name);
- W.printNumber("Index", SectionIndex);
- W.printHex("Type", getGroupType(Data[0]), Data[0]);
- W.startLine() << "Signature: " << StrTable.data() + Sym->st_name << "\n";
- {
- ListScope L(W, "Section(s) in group");
- size_t Member = 1;
- while (Member < Data.size()) {
- auto Sec = unwrapOrError(Obj->getSection(Data[Member]));
- const StringRef Name = unwrapOrError(Obj->getSectionName(Sec));
- W.startLine() << Name << " (" << Data[Member++] << ")\n";
- }
- }
- }
- ++SectionIndex;
- }
- if (!HasGroups)
- W.startLine() << "There are no group sections in the file.\n";
+ ELFDumperStyle->printGroupSections(Obj);
}
static inline void printFields(formatted_raw_ostream &OS, StringRef Str1,
@@ -2346,6 +2333,37 @@ void GNUStyle<ELFT>::printFileHeaders(co
printFields(OS, "Section header string table index:", Str);
}
+template <class ELFT> void GNUStyle<ELFT>::printGroupSections(const ELFO *Obj) {
+ uint32_t SectionIndex = 0;
+ bool HasGroups = false;
+ for (const Elf_Shdr &Sec : Obj->sections()) {
+ if (Sec.sh_type == ELF::SHT_GROUP) {
+ HasGroups = true;
+ const Elf_Shdr *Symtab = unwrapOrError(Obj->getSection(Sec.sh_link));
+ StringRef StrTable = unwrapOrError(Obj->getStringTableForSymtab(*Symtab));
+ const Elf_Sym *Signature =
+ Obj->template getEntry<Elf_Sym>(Symtab, Sec.sh_info);
+ ArrayRef<Elf_Word> Data = unwrapOrError(
+ Obj->template getSectionContentsAsArray<Elf_Word>(&Sec));
+ StringRef Name = unwrapOrError(Obj->getSectionName(&Sec));
+ OS << "\n" << getGroupType(Data[0]) << " group section ["
+ << format_decimal(SectionIndex, 5) << "] `" << Name << "' ["
+ << StrTable.data() + Signature->st_name << "] contains "
+ << (Data.size() - 1) << " sections:\n"
+ << " [Index] Name\n";
+ for (auto &Ndx : Data.slice(1)) {
+ auto Sec = unwrapOrError(Obj->getSection(Ndx));
+ const StringRef Name = unwrapOrError(Obj->getSectionName(Sec));
+ OS << " [" << format_decimal(Ndx, 5) << "] " << Name
+ << "\n";
+ }
+ }
+ ++SectionIndex;
+ }
+ if (!HasGroups)
+ OS << "There are no section groups in this file.\n";
+}
+
template <class ELFT>
void LLVMStyle<ELFT>::printFileHeaders(const ELFFile<ELFT> *Obj) {
const Elf_Ehdr *e = Obj->getHeader();
@@ -2390,3 +2408,38 @@ void LLVMStyle<ELFT>::printFileHeaders(c
W.printNumber("StringTableSectionIndex", e->e_shstrndx);
}
}
+
+template <class ELFT>
+void LLVMStyle<ELFT>::printGroupSections(const ELFO *Obj) {
+ DictScope Lists(W, "Groups");
+ uint32_t SectionIndex = 0;
+ bool HasGroups = false;
+ for (const Elf_Shdr &Sec : Obj->sections()) {
+ if (Sec.sh_type == ELF::SHT_GROUP) {
+ HasGroups = true;
+ const Elf_Shdr *Symtab = unwrapOrError(Obj->getSection(Sec.sh_link));
+ StringRef StrTable = unwrapOrError(Obj->getStringTableForSymtab(*Symtab));
+ const Elf_Sym *Sym = Obj->template getEntry<Elf_Sym>(Symtab, Sec.sh_info);
+ auto Data = unwrapOrError(
+ Obj->template getSectionContentsAsArray<Elf_Word>(&Sec));
+ DictScope D(W, "Group");
+ StringRef Name = unwrapOrError(Obj->getSectionName(&Sec));
+ W.printNumber("Name", Name, Sec.sh_name);
+ W.printNumber("Index", SectionIndex);
+ W.printHex("Type", getGroupType(Data[0]), Data[0]);
+ W.startLine() << "Signature: " << StrTable.data() + Sym->st_name << "\n";
+ {
+ ListScope L(W, "Section(s) in group");
+ size_t Member = 1;
+ while (Member < Data.size()) {
+ auto Sec = unwrapOrError(Obj->getSection(Data[Member]));
+ const StringRef Name = unwrapOrError(Obj->getSectionName(Sec));
+ W.startLine() << Name << " (" << Data[Member++] << ")\n";
+ }
+ }
+ }
+ ++SectionIndex;
+ }
+ if (!HasGroups)
+ W.startLine() << "There are no group sections in the file.\n";
+}
More information about the llvm-commits
mailing list