1 //===-- ELFDump.cpp - ELF-specific dumper -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief This file implements the ELF-specific dumper for llvm-objdump.
13 //===----------------------------------------------------------------------===//
15 #include "llvm-objdump.h"
16 #include "llvm/Object/ELF.h"
17 #include "llvm/Support/Format.h"
18 #include "llvm/Support/MathExtras.h"
19 #include "llvm/Support/raw_ostream.h"
22 using namespace llvm::object;
25 void printProgramHeaders(
26 const ELFObjectFile<ELFT> *o) {
27 typedef ELFObjectFile<ELFT> ELFO;
28 outs() << "Program Header:\n";
29 for (typename ELFO::Elf_Phdr_Iter pi = o->begin_program_headers(),
30 pe = o->end_program_headers();
36 case ELF::PT_GNU_STACK:
39 case ELF::PT_GNU_EH_FRAME:
40 outs() << "EH_FRAME ";
46 outs() << " DYNAMIC ";
55 outs() << " UNKNOWN ";
58 const char *Fmt = ELFT::Is64Bits ? "0x%016" PRIx64 " " : "0x%08" PRIx64 " ";
61 << format(Fmt, (uint64_t)pi->p_offset)
63 << format(Fmt, (uint64_t)pi->p_vaddr)
65 << format(Fmt, (uint64_t)pi->p_paddr)
66 << format("align 2**%u\n", countTrailingZeros<uint64_t>(pi->p_align))
68 << format(Fmt, (uint64_t)pi->p_filesz)
70 << format(Fmt, (uint64_t)pi->p_memsz)
72 << ((pi->p_flags & ELF::PF_R) ? "r" : "-")
73 << ((pi->p_flags & ELF::PF_W) ? "w" : "-")
74 << ((pi->p_flags & ELF::PF_X) ? "x" : "-")
80 void llvm::printELFFileHeader(const object::ObjectFile *Obj) {
81 // Little-endian 32-bit
82 if (const ELF32LEObjectFile *ELFObj = dyn_cast<ELF32LEObjectFile>(Obj))
83 printProgramHeaders(ELFObj);
86 if (const ELF32BEObjectFile *ELFObj = dyn_cast<ELF32BEObjectFile>(Obj))
87 printProgramHeaders(ELFObj);
89 // Little-endian 64-bit
90 if (const ELF64LEObjectFile *ELFObj = dyn_cast<ELF64LEObjectFile>(Obj))
91 printProgramHeaders(ELFObj);
94 if (const ELF64BEObjectFile *ELFObj = dyn_cast<ELF64BEObjectFile>(Obj))
95 printProgramHeaders(ELFObj);