llvm.org GIT mirror llvm / e57aee0
[llvm-readobj] Enable GNU style section group print Differential Revision: http://reviews.llvm.org/D17822 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@263050 91177308-0d34-0410-b5e6-96231b3b80d8 Hemant Kulkarni 3 years ago
2 changed file(s) with 100 addition(s) and 34 deletion(s). Raw diff Collapse all Expand all
1414
1515 RUN: llvm-readobj -g %p/Inputs/elf-groups.x86_64 \
1616 RUN: | FileCheck %s
17 RUN: llvm-readobj -g -elf-output-style=GNU %p/Inputs/elf-groups.x86_64 \
18 RUN: | FileCheck --check-prefix="GNU" %s
1719 CHECK: Groups {
1820 CHECK-NEXT: Group {
1921 CHECK-NEXT: Name: .group (92)
3638 CHECK-NEXT: ]
3739 CHECK-NEXT: }
3840
41 GNU:COMDAT group section [ 1] `.group' [_Z3fooIcEvT_] contains 2 sections:
42 GNU-NEXT: [Index] Name
43 GNU-NEXT: [ 10] .text._Z3fooIcEvT_
44 GNU-NEXT: [ 11] .rela.text._Z3fooIcEvT_
45 GNU:COMDAT group section [ 2] `.group' [_Z3fooIiEvT_] contains 2 sections:
46 GNU-NEXT: [Index] Name
47 GNU-NEXT: [ 12] .text._Z3fooIiEvT_
48 GNU-NEXT: [ 13] .rela.text._Z3fooIiEvT_
49 GNU:COMDAT group section [ 3] `.group' [_ZNKSt9type_info4nameEv] contains 1 sections:
50 GNU-NEXT: [Index] Name
51 GNU-NEXT: [ 14] .text._ZNKSt9type_info4nameEv
4242
4343 #define ENUM_ENT_1(enum) \
4444 { #enum, #enum, ELF::enum }
45
46 #define TYPEDEF_ELF_TYPES(ELFT) \
47 typedef ELFFile ELFO; \
48 typedef typename ELFO::Elf_Shdr Elf_Shdr; \
49 typedef typename ELFO::Elf_Sym Elf_Sym; \
50 typedef typename ELFO::Elf_Dyn Elf_Dyn; \
51 typedef typename ELFO::Elf_Dyn_Range Elf_Dyn_Range; \
52 typedef typename ELFO::Elf_Rel Elf_Rel; \
53 typedef typename ELFO::Elf_Rela Elf_Rela; \
54 typedef typename ELFO::Elf_Rela_Range Elf_Rela_Range; \
55 typedef typename ELFO::Elf_Phdr Elf_Phdr; \
56 typedef typename ELFO::Elf_Half Elf_Half; \
57 typedef typename ELFO::Elf_Ehdr Elf_Ehdr; \
58 typedef typename ELFO::Elf_Word Elf_Word; \
59 typedef typename ELFO::uintX_t uintX_t;
4560
4661 namespace {
4762
221236 public:
222237 virtual void printFileHeaders(const ELFFile *Obj) = 0;
223238 virtual ~DumpStyle() { }
239 virtual void printGroupSections(const ELFFile *Obj) = 0;
224240 };
225241
226242 template class GNUStyle : public DumpStyle {
227243 formatted_raw_ostream OS;
228244
229245 public:
230 typedef typename ELFFile::Elf_Ehdr Elf_Ehdr;
246 TYPEDEF_ELF_TYPES(ELFT)
231247 GNUStyle(StreamWriter &W) : OS(W.getOStream()) {}
232248 void printFileHeaders(const ELFFile *Obj) override;
249 void printGroupSections(const ELFFile *Obj) override;
233250
234251 private:
235252 template
243260
244261 template class LLVMStyle : public DumpStyle {
245262 public:
246 typedef typename ELFFile::Elf_Ehdr Elf_Ehdr;
263 TYPEDEF_ELF_TYPES(ELFT)
247264 LLVMStyle(StreamWriter &W) : W(W) {}
248
249265 void printFileHeaders(const ELFFile *Obj) override;
266 void printGroupSections(const ELFFile *Obj) override;
250267
251268 private:
252269 StreamWriter &W;
22502267 }
22512268
22522269 template void ELFDumper::printGroupSections() {
2253 DictScope Lists(W, "Groups");
2254 uint32_t SectionIndex = 0;
2255 bool HasGroups = false;
2256 for (const Elf_Shdr &Sec : Obj->sections()) {
2257 if (Sec.sh_type == ELF::SHT_GROUP) {
2258 HasGroups = true;
2259 const Elf_Shdr *Symtab = unwrapOrError(Obj->getSection(Sec.sh_link));
2260 StringRef StrTable = unwrapOrError(Obj->getStringTableForSymtab(*Symtab));
2261 const Elf_Sym *Sym = Obj->template getEntry(Symtab, Sec.sh_info);
2262 auto Data = unwrapOrError(
2263 Obj->template getSectionContentsAsArray(&Sec));
2264 DictScope D(W, "Group");
2265 StringRef Name = unwrapOrError(Obj->getSectionName(&Sec));
2266 W.printNumber("Name", Name, Sec.sh_name);
2267 W.printNumber("Index", SectionIndex);
2268 W.printHex("Type", getGroupType(Data[0]), Data[0]);
2269 W.startLine() << "Signature: " << StrTable.data() + Sym->st_name << "\n";
2270 {
2271 ListScope L(W, "Section(s) in group");
2272 size_t Member = 1;
2273 while (Member < Data.size()) {
2274 auto Sec = unwrapOrError(Obj->getSection(Data[Member]));
2275 const StringRef Name = unwrapOrError(Obj->getSectionName(Sec));
2276 W.startLine() << Name << " (" << Data[Member++] << ")\n";
2277 }
2278 }
2279 }
2280 ++SectionIndex;
2281 }
2282 if (!HasGroups)
2283 W.startLine() << "There are no group sections in the file.\n";
2270 ELFDumperStyle->printGroupSections(Obj);
22842271 }
22852272
22862273 static inline void printFields(formatted_raw_ostream &OS, StringRef Str1,
23452332 printFields(OS, "Section header string table index:", Str);
23462333 }
23472334
2335 template void GNUStyle::printGroupSections(const ELFO *Obj) {
2336 uint32_t SectionIndex = 0;
2337 bool HasGroups = false;
2338 for (const Elf_Shdr &Sec : Obj->sections()) {
2339 if (Sec.sh_type == ELF::SHT_GROUP) {
2340 HasGroups = true;
2341 const Elf_Shdr *Symtab = unwrapOrError(Obj->getSection(Sec.sh_link));
2342 StringRef StrTable = unwrapOrError(Obj->getStringTableForSymtab(*Symtab));
2343 const Elf_Sym *Signature =
2344 Obj->template getEntry(Symtab, Sec.sh_info);
2345 ArrayRef Data = unwrapOrError(
2346 Obj->template getSectionContentsAsArray(&Sec));
2347 StringRef Name = unwrapOrError(Obj->getSectionName(&Sec));
2348 OS << "\n" << getGroupType(Data[0]) << " group section ["
2349 << format_decimal(SectionIndex, 5) << "] `" << Name << "' ["
2350 << StrTable.data() + Signature->st_name << "] contains "
2351 << (Data.size() - 1) << " sections:\n"
2352 << " [Index] Name\n";
2353 for (auto &Ndx : Data.slice(1)) {
2354 auto Sec = unwrapOrError(Obj->getSection(Ndx));
2355 const StringRef Name = unwrapOrError(Obj->getSectionName(Sec));
2356 OS << " [" << format_decimal(Ndx, 5) << "] " << Name
2357 << "\n";
2358 }
2359 }
2360 ++SectionIndex;
2361 }
2362 if (!HasGroups)
2363 OS << "There are no section groups in this file.\n";
2364 }
2365
23482366 template
23492367 void LLVMStyle::printFileHeaders(const ELFFile *Obj) {
23502368 const Elf_Ehdr *e = Obj->getHeader();
23892407 W.printNumber("StringTableSectionIndex", e->e_shstrndx);
23902408 }
23912409 }
2410
2411 template
2412 void LLVMStyle::printGroupSections(const ELFO *Obj) {
2413 DictScope Lists(W, "Groups");
2414 uint32_t SectionIndex = 0;
2415 bool HasGroups = false;
2416 for (const Elf_Shdr &Sec : Obj->sections()) {
2417 if (Sec.sh_type == ELF::SHT_GROUP) {
2418 HasGroups = true;
2419 const Elf_Shdr *Symtab = unwrapOrError(Obj->getSection(Sec.sh_link));
2420 StringRef StrTable = unwrapOrError(Obj->getStringTableForSymtab(*Symtab));
2421 const Elf_Sym *Sym = Obj->template getEntry(Symtab, Sec.sh_info);
2422 auto Data = unwrapOrError(
2423 Obj->template getSectionContentsAsArray(&Sec));
2424 DictScope D(W, "Group");
2425 StringRef Name = unwrapOrError(Obj->getSectionName(&Sec));
2426 W.printNumber("Name", Name, Sec.sh_name);
2427 W.printNumber("Index", SectionIndex);
2428 W.printHex("Type", getGroupType(Data[0]), Data[0]);
2429 W.startLine() << "Signature: " << StrTable.data() + Sym->st_name << "\n";
2430 {
2431 ListScope L(W, "Section(s) in group");
2432 size_t Member = 1;
2433 while (Member < Data.size()) {
2434 auto Sec = unwrapOrError(Obj->getSection(Data[Member]));
2435 const StringRef Name = unwrapOrError(Obj->getSectionName(Sec));
2436 W.startLine() << Name << " (" << Data[Member++] << ")\n";
2437 }
2438 }
2439 }
2440 ++SectionIndex;
2441 }
2442 if (!HasGroups)
2443 W.startLine() << "There are no group sections in the file.\n";
2444 }