From 76e70f340c09ba759ad96d8dfe416b64f24bc287 Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Wed, 3 Apr 2013 18:31:38 +0000 Subject: Implements low-level object file format specific output for COFF and ELF with support for: - File headers - Section headers + data - Relocations - Symbols - Unwind data (only COFF/Win64) The output format follows a few rules: - Values are almost always output one per line (as elf-dump/coff-dump already do). - Many values are translated to something readable (like enum names), with the raw value in parentheses. - Hex numbers are output in uppercase, prefixed with "0x". - Flags are sorted alphabetically. - Lists and groups are always delimited. Example output: ---------- snip ---------- Sections [ Section { Index: 1 Name: .text (5) Type: SHT_PROGBITS (0x1) Flags [ (0x6) SHF_ALLOC (0x2) SHF_EXECINSTR (0x4) ] Address: 0x0 Offset: 0x40 Size: 33 Link: 0 Info: 0 AddressAlignment: 16 EntrySize: 0 Relocations [ 0x6 R_386_32 .rodata.str1.1 0x0 0xB R_386_PC32 puts 0x0 0x12 R_386_32 .rodata.str1.1 0x0 0x17 R_386_PC32 puts 0x0 ] SectionData ( 0000: 83EC04C7 04240000 0000E8FC FFFFFFC7 |.....$..........| 0010: 04240600 0000E8FC FFFFFF31 C083C404 |.$.........1....| 0020: C3 |.| ) } ] ---------- snip ---------- Relocations and symbols can be output standalone or together with the section header as displayed in the example. This feature set supports all tests in test/MC/COFF and test/MC/ELF (and I suspect all additional tests using elf-dump), making elf-dump and coff-dump deprecated. Patch by Nico Rieck! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178679 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-readobj/ELF.cpp | 196 --------------------------------------------- 1 file changed, 196 deletions(-) delete mode 100644 tools/llvm-readobj/ELF.cpp (limited to 'tools/llvm-readobj/ELF.cpp') diff --git a/tools/llvm-readobj/ELF.cpp b/tools/llvm-readobj/ELF.cpp deleted file mode 100644 index 07f15b3a6d..0000000000 --- a/tools/llvm-readobj/ELF.cpp +++ /dev/null @@ -1,196 +0,0 @@ -//===- llvm-readobj/ELF.cpp - ELF Specific Dumper -------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "llvm-readobj.h" - -#include "llvm/Object/ELF.h" -#include "llvm/Support/Casting.h" -#include "llvm/Support/Format.h" - -namespace llvm { -using namespace object; -using namespace ELF; - -const char *getTypeString(uint64_t Type) { - switch (Type) { - case DT_BIND_NOW: - return "(BIND_NOW)"; - case DT_DEBUG: - return "(DEBUG)"; - case DT_FINI: - return "(FINI)"; - case DT_FINI_ARRAY: - return "(FINI_ARRAY)"; - case DT_FINI_ARRAYSZ: - return "(FINI_ARRAYSZ)"; - case DT_FLAGS: - return "(FLAGS)"; - case DT_HASH: - return "(HASH)"; - case DT_INIT: - return "(INIT)"; - case DT_INIT_ARRAY: - return "(INIT_ARRAY)"; - case DT_INIT_ARRAYSZ: - return "(INIT_ARRAYSZ)"; - case DT_PREINIT_ARRAY: - return "(PREINIT_ARRAY)"; - case DT_PREINIT_ARRAYSZ: - return "(PREINIT_ARRAYSZ)"; - case DT_JMPREL: - return "(JMPREL)"; - case DT_NEEDED: - return "(NEEDED)"; - case DT_NULL: - return "(NULL)"; - case DT_PLTGOT: - return "(PLTGOT)"; - case DT_PLTREL: - return "(PLTREL)"; - case DT_PLTRELSZ: - return "(PLTRELSZ)"; - case DT_REL: - return "(REL)"; - case DT_RELA: - return "(RELA)"; - case DT_RELENT: - return "(RELENT)"; - case DT_RELSZ: - return "(RELSZ)"; - case DT_RELAENT: - return "(RELAENT)"; - case DT_RELASZ: - return "(RELASZ)"; - case DT_RPATH: - return "(RPATH)"; - case DT_RUNPATH: - return "(RUNPATH)"; - case DT_SONAME: - return "(SONAME)"; - case DT_STRSZ: - return "(STRSZ)"; - case DT_STRTAB: - return "(STRTAB)"; - case DT_SYMBOLIC: - return "(SYMBOLIC)"; - case DT_SYMENT: - return "(SYMENT)"; - case DT_SYMTAB: - return "(SYMTAB)"; - case DT_TEXTREL: - return "(TEXTREL)"; - default: - return "unknown"; - } -} - -template -void printValue(const ELFObjectFile *O, uint64_t Type, uint64_t Value, - bool Is64, raw_ostream &OS) { - switch (Type) { - case DT_PLTREL: - if (Value == DT_REL) { - OS << "REL"; - break; - } else if (Value == DT_RELA) { - OS << "RELA"; - break; - } - // Fallthrough. - case DT_PLTGOT: - case DT_HASH: - case DT_STRTAB: - case DT_SYMTAB: - case DT_RELA: - case DT_INIT: - case DT_FINI: - case DT_REL: - case DT_JMPREL: - case DT_INIT_ARRAY: - case DT_FINI_ARRAY: - case DT_PREINIT_ARRAY: - case DT_DEBUG: - case DT_NULL: - OS << format("0x%" PRIx64, Value); - break; - case DT_PLTRELSZ: - case DT_RELASZ: - case DT_RELAENT: - case DT_STRSZ: - case DT_SYMENT: - case DT_RELSZ: - case DT_RELENT: - case DT_INIT_ARRAYSZ: - case DT_FINI_ARRAYSZ: - case DT_PREINIT_ARRAYSZ: - OS << Value << " (bytes)"; - break; - case DT_NEEDED: - OS << "Shared library: [" - << O->getString(O->getDynamicStringTableSectionHeader(), Value) << "]"; - break; - case DT_SONAME: - OS << "Library soname: [" - << O->getString(O->getDynamicStringTableSectionHeader(), Value) << "]"; - break; - } -} - -template -ErrorOr dumpDynamicTable(const ELFObjectFile *O, raw_ostream &OS) { - typedef ELFObjectFile ELFO; - typedef typename ELFO::Elf_Dyn_iterator EDI; - EDI Start = O->begin_dynamic_table(), - End = O->end_dynamic_table(true); - - if (Start == End) - return error_code::success(); - - ptrdiff_t Total = std::distance(Start, End); - OS << "Dynamic section contains " << Total << " entries\n"; - - bool Is64 = O->getBytesInAddress() == 8; - - OS << " Tag" << (Is64 ? " " : " ") << "Type" - << " " << "Name/Value\n"; - for (; Start != End; ++Start) { - OS << " " - << format(Is64 ? "0x%016" PRIx64 : "0x%08" PRIx64, Start->getTag()) - << " " << format("%-21s", getTypeString(Start->getTag())); - printValue(O, Start->getTag(), Start->getVal(), Is64, OS); - OS << "\n"; - } - - OS << " Total: " << Total << "\n\n"; - return error_code::success(); -} - -ErrorOr dumpELFDynamicTable(ObjectFile *O, raw_ostream &OS) { - // Little-endian 32-bit - if (const ELFObjectFile > *ELFObj = - dyn_cast > >(O)) - return dumpDynamicTable(ELFObj, OS); - - // Big-endian 32-bit - if (const ELFObjectFile > *ELFObj = - dyn_cast > >(O)) - return dumpDynamicTable(ELFObj, OS); - - // Little-endian 64-bit - if (const ELFObjectFile > *ELFObj = - dyn_cast > >(O)) - return dumpDynamicTable(ELFObj, OS); - - // Big-endian 64-bit - if (const ELFObjectFile > *ELFObj = - dyn_cast > >(O)) - return dumpDynamicTable(ELFObj, OS); - return error_code(object_error::invalid_file_type); -} -} // end namespace llvm -- cgit v1.2.3-70-g09d2