2013-01-06 03:56:49 +00:00
|
|
|
//===-- ELFDump.cpp - ELF-specific dumper -----------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// \brief This file implements the ELF-specific dumper for llvm-objdump.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm-objdump.h"
|
|
|
|
#include "llvm/Object/ELF.h"
|
|
|
|
#include "llvm/Support/Format.h"
|
|
|
|
#include "llvm/Support/MathExtras.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::object;
|
|
|
|
|
2013-01-15 07:44:25 +00:00
|
|
|
template<class ELFT>
|
2013-01-06 03:56:49 +00:00
|
|
|
void printProgramHeaders(
|
2013-01-15 07:44:25 +00:00
|
|
|
const ELFObjectFile<ELFT> *o) {
|
|
|
|
typedef ELFObjectFile<ELFT> ELFO;
|
2013-01-06 03:56:49 +00:00
|
|
|
outs() << "Program Header:\n";
|
|
|
|
for (typename ELFO::Elf_Phdr_Iter pi = o->begin_program_headers(),
|
|
|
|
pe = o->end_program_headers();
|
|
|
|
pi != pe; ++pi) {
|
|
|
|
switch (pi->p_type) {
|
|
|
|
case ELF::PT_LOAD:
|
|
|
|
outs() << " LOAD ";
|
|
|
|
break;
|
|
|
|
case ELF::PT_GNU_STACK:
|
|
|
|
outs() << " STACK ";
|
|
|
|
break;
|
|
|
|
case ELF::PT_GNU_EH_FRAME:
|
|
|
|
outs() << "EH_FRAME ";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
outs() << " UNKNOWN ";
|
|
|
|
}
|
|
|
|
|
2013-01-15 07:44:25 +00:00
|
|
|
const char *Fmt = ELFT::Is64Bits ? "0x%016" PRIx64 " " : "0x%08" PRIx64 " ";
|
2013-01-06 05:23:59 +00:00
|
|
|
|
2013-01-06 03:56:49 +00:00
|
|
|
outs() << "off "
|
2013-01-06 05:23:59 +00:00
|
|
|
<< format(Fmt, (uint64_t)pi->p_offset)
|
2013-01-06 03:56:49 +00:00
|
|
|
<< "vaddr "
|
2013-01-06 05:23:59 +00:00
|
|
|
<< format(Fmt, (uint64_t)pi->p_vaddr)
|
2013-01-06 03:56:49 +00:00
|
|
|
<< "paddr "
|
2013-01-06 05:23:59 +00:00
|
|
|
<< format(Fmt, (uint64_t)pi->p_paddr)
|
|
|
|
<< format("align 2**%u\n", CountTrailingZeros_64(pi->p_align))
|
2013-01-06 03:56:49 +00:00
|
|
|
<< " filesz "
|
2013-01-06 05:23:59 +00:00
|
|
|
<< format(Fmt, (uint64_t)pi->p_filesz)
|
2013-01-06 03:56:49 +00:00
|
|
|
<< "memsz "
|
2013-01-06 05:23:59 +00:00
|
|
|
<< format(Fmt, (uint64_t)pi->p_memsz)
|
2013-01-06 03:56:49 +00:00
|
|
|
<< "flags "
|
|
|
|
<< ((pi->p_flags & ELF::PF_R) ? "r" : "-")
|
|
|
|
<< ((pi->p_flags & ELF::PF_W) ? "w" : "-")
|
|
|
|
<< ((pi->p_flags & ELF::PF_X) ? "x" : "-")
|
|
|
|
<< "\n";
|
|
|
|
}
|
|
|
|
outs() << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void llvm::printELFFileHeader(const object::ObjectFile *Obj) {
|
|
|
|
// Little-endian 32-bit
|
2013-01-15 07:44:25 +00:00
|
|
|
if (const ELFObjectFile<ELFType<support::little, 4, false> > *ELFObj =
|
|
|
|
dyn_cast<ELFObjectFile<ELFType<support::little, 4, false> > >(Obj))
|
2013-01-06 03:56:49 +00:00
|
|
|
printProgramHeaders(ELFObj);
|
|
|
|
|
|
|
|
// Big-endian 32-bit
|
2013-01-15 07:44:25 +00:00
|
|
|
if (const ELFObjectFile<ELFType<support::big, 4, false> > *ELFObj =
|
|
|
|
dyn_cast<ELFObjectFile<ELFType<support::big, 4, false> > >(Obj))
|
2013-01-06 03:56:49 +00:00
|
|
|
printProgramHeaders(ELFObj);
|
|
|
|
|
|
|
|
// Little-endian 64-bit
|
2013-01-15 07:44:25 +00:00
|
|
|
if (const ELFObjectFile<ELFType<support::little, 8, true> > *ELFObj =
|
|
|
|
dyn_cast<ELFObjectFile<ELFType<support::little, 8, true> > >(Obj))
|
2013-01-06 03:56:49 +00:00
|
|
|
printProgramHeaders(ELFObj);
|
|
|
|
|
|
|
|
// Big-endian 64-bit
|
2013-01-15 07:44:25 +00:00
|
|
|
if (const ELFObjectFile<ELFType<support::big, 8, true> > *ELFObj =
|
|
|
|
dyn_cast<ELFObjectFile<ELFType<support::big, 8, true> > >(Obj))
|
2013-01-06 03:56:49 +00:00
|
|
|
printProgramHeaders(ELFObj);
|
|
|
|
}
|