2013-01-06 04:56:49 +01: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"
|
2013-08-09 00:27:13 +02:00
|
|
|
#include "llvm/Object/ELFObjectFile.h"
|
2013-01-06 04:56:49 +01:00
|
|
|
#include "llvm/Support/Format.h"
|
|
|
|
#include "llvm/Support/MathExtras.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::object;
|
|
|
|
|
2013-08-09 00:27:13 +02:00
|
|
|
template <class ELFT> void printProgramHeaders(const ELFFile<ELFT> *o) {
|
|
|
|
typedef ELFFile<ELFT> ELFO;
|
2013-01-06 04:56:49 +01: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;
|
2013-02-20 21:18:10 +01:00
|
|
|
case ELF::PT_INTERP:
|
|
|
|
outs() << " INTERP ";
|
|
|
|
break;
|
|
|
|
case ELF::PT_DYNAMIC:
|
|
|
|
outs() << " DYNAMIC ";
|
|
|
|
break;
|
2013-02-21 03:21:29 +01:00
|
|
|
case ELF::PT_PHDR:
|
|
|
|
outs() << " PHDR ";
|
|
|
|
break;
|
2013-02-27 18:57:17 +01:00
|
|
|
case ELF::PT_TLS:
|
|
|
|
outs() << " TLS ";
|
|
|
|
break;
|
2013-01-06 04:56:49 +01:00
|
|
|
default:
|
|
|
|
outs() << " UNKNOWN ";
|
|
|
|
}
|
|
|
|
|
2013-01-15 08:44:25 +01:00
|
|
|
const char *Fmt = ELFT::Is64Bits ? "0x%016" PRIx64 " " : "0x%08" PRIx64 " ";
|
2013-01-06 06:23:59 +01:00
|
|
|
|
2013-01-06 04:56:49 +01:00
|
|
|
outs() << "off "
|
2013-01-06 06:23:59 +01:00
|
|
|
<< format(Fmt, (uint64_t)pi->p_offset)
|
2013-01-06 04:56:49 +01:00
|
|
|
<< "vaddr "
|
2013-01-06 06:23:59 +01:00
|
|
|
<< format(Fmt, (uint64_t)pi->p_vaddr)
|
2013-01-06 04:56:49 +01:00
|
|
|
<< "paddr "
|
2013-01-06 06:23:59 +01:00
|
|
|
<< format(Fmt, (uint64_t)pi->p_paddr)
|
2013-05-25 00:23:49 +02:00
|
|
|
<< format("align 2**%u\n", countTrailingZeros<uint64_t>(pi->p_align))
|
2013-01-06 04:56:49 +01:00
|
|
|
<< " filesz "
|
2013-01-06 06:23:59 +01:00
|
|
|
<< format(Fmt, (uint64_t)pi->p_filesz)
|
2013-01-06 04:56:49 +01:00
|
|
|
<< "memsz "
|
2013-01-06 06:23:59 +01:00
|
|
|
<< format(Fmt, (uint64_t)pi->p_memsz)
|
2013-01-06 04:56:49 +01: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-05-09 15:13:28 +02:00
|
|
|
if (const ELF32LEObjectFile *ELFObj = dyn_cast<ELF32LEObjectFile>(Obj))
|
2013-08-09 00:27:13 +02:00
|
|
|
printProgramHeaders(ELFObj->getELFFile());
|
2013-01-06 04:56:49 +01:00
|
|
|
|
|
|
|
// Big-endian 32-bit
|
2013-05-09 15:13:28 +02:00
|
|
|
if (const ELF32BEObjectFile *ELFObj = dyn_cast<ELF32BEObjectFile>(Obj))
|
2013-08-09 00:27:13 +02:00
|
|
|
printProgramHeaders(ELFObj->getELFFile());
|
2013-01-06 04:56:49 +01:00
|
|
|
|
|
|
|
// Little-endian 64-bit
|
2013-05-09 15:13:28 +02:00
|
|
|
if (const ELF64LEObjectFile *ELFObj = dyn_cast<ELF64LEObjectFile>(Obj))
|
2013-08-09 00:27:13 +02:00
|
|
|
printProgramHeaders(ELFObj->getELFFile());
|
2013-01-06 04:56:49 +01:00
|
|
|
|
|
|
|
// Big-endian 64-bit
|
2013-05-09 15:13:28 +02:00
|
|
|
if (const ELF64BEObjectFile *ELFObj = dyn_cast<ELF64BEObjectFile>(Obj))
|
2013-08-09 00:27:13 +02:00
|
|
|
printProgramHeaders(ELFObj->getELFFile());
|
2013-01-06 04:56:49 +01:00
|
|
|
}
|