aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2013-01-06 03:56:49 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2013-01-06 03:56:49 +0000
commitb2c064c6954c9bfa49b7a7e3223df5e7849464c0 (patch)
tree672a92775914f0bfb1d3721700433185cc2dbc5d /tools
parent3e5d8ade393d347a1483bf39d48ffebe9541b2b0 (diff)
downloadexternal_llvm-b2c064c6954c9bfa49b7a7e3223df5e7849464c0.zip
external_llvm-b2c064c6954c9bfa49b7a7e3223df5e7849464c0.tar.gz
external_llvm-b2c064c6954c9bfa49b7a7e3223df5e7849464c0.tar.bz2
[objdump] Add --private-headers, -p.
This currently prints the ELF program headers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171649 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/llvm-objdump/CMakeLists.txt1
-rw-r--r--tools/llvm-objdump/ELFDump.cpp87
-rw-r--r--tools/llvm-objdump/llvm-objdump.cpp14
-rw-r--r--tools/llvm-objdump/llvm-objdump.h2
4 files changed, 103 insertions, 1 deletions
diff --git a/tools/llvm-objdump/CMakeLists.txt b/tools/llvm-objdump/CMakeLists.txt
index 5001435..0c49d0b 100644
--- a/tools/llvm-objdump/CMakeLists.txt
+++ b/tools/llvm-objdump/CMakeLists.txt
@@ -10,6 +10,7 @@ set(LLVM_LINK_COMPONENTS
add_llvm_tool(llvm-objdump
llvm-objdump.cpp
COFFDump.cpp
+ ELFDump.cpp
MachODump.cpp
MCFunction.cpp
)
diff --git a/tools/llvm-objdump/ELFDump.cpp b/tools/llvm-objdump/ELFDump.cpp
new file mode 100644
index 0000000..f018eed
--- /dev/null
+++ b/tools/llvm-objdump/ELFDump.cpp
@@ -0,0 +1,87 @@
+//===-- 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;
+
+template<endianness target_endianness, std::size_t max_alignment, bool is64Bits>
+void printProgramHeaders(
+ const ELFObjectFile<target_endianness, max_alignment, is64Bits> *o) {
+ typedef ELFObjectFile<target_endianness, max_alignment, is64Bits> ELFO;
+ 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 ";
+ }
+
+ outs() << "off "
+ << format(is64Bits ? "0x%016x " : "0x%08x ", pi->p_offset)
+ << "vaddr "
+ << format(is64Bits ? "0x%016x " : "0x%08x ", pi->p_vaddr)
+ << "paddr "
+ << format(is64Bits ? "0x%016x " : "0x%08x ", pi->p_paddr)
+ << format("align 2**%d\n", CountTrailingZeros_32(pi->p_align))
+ << " filesz "
+ << format(is64Bits ? "0x%016x " : "0x%08x ", pi->p_filesz)
+ << "memsz "
+ << format(is64Bits ? "0x%016x " : "0x%08x ", pi->p_memsz)
+ << "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
+ if (const ELFObjectFile<support::little, 4, false> *ELFObj =
+ dyn_cast<ELFObjectFile<support::little, 4, false> >(Obj))
+ printProgramHeaders(ELFObj);
+
+ // Big-endian 32-bit
+ if (const ELFObjectFile<support::big, 4, false> *ELFObj =
+ dyn_cast<ELFObjectFile<support::big, 4, false> >(Obj))
+ printProgramHeaders(ELFObj);
+
+ // Little-endian 64-bit
+ if (const ELFObjectFile<support::little, 8, true> *ELFObj =
+ dyn_cast<ELFObjectFile<support::little, 8, true> >(Obj))
+ printProgramHeaders(ELFObj);
+
+ // Big-endian 64-bit
+ if (const ELFObjectFile<support::big, 8, true> *ELFObj =
+ dyn_cast<ELFObjectFile<support::big, 8, true> >(Obj))
+ printProgramHeaders(ELFObj);
+}
diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp
index 24dc9c9..9958dad 100644
--- a/tools/llvm-objdump/llvm-objdump.cpp
+++ b/tools/llvm-objdump/llvm-objdump.cpp
@@ -28,6 +28,7 @@
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/Object/Archive.h"
#include "llvm/Object/COFF.h"
+#include "llvm/Object/ELF.h"
#include "llvm/Object/MachO.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/Casting.h"
@@ -112,6 +113,14 @@ static cl::alias
UnwindInfoShort("u", cl::desc("Alias for --unwind-info"),
cl::aliasopt(UnwindInfo));
+static cl::opt<bool>
+PrivateHeaders("private-headers",
+ cl::desc("Display format specific file headers"));
+
+static cl::alias
+PrivateHeadersShort("p", cl::desc("Alias for --private-headers"),
+ cl::aliasopt(PrivateHeaders));
+
static StringRef ToolName;
bool llvm::error(error_code ec) {
@@ -627,6 +636,8 @@ static void DumpObject(const ObjectFile *o) {
PrintSymbolTable(o);
if (UnwindInfo)
PrintUnwindInfo(o);
+ if (PrivateHeaders && o->isELF())
+ printELFFileHeader(o);
}
/// @brief Dump each object file in \a a;
@@ -706,7 +717,8 @@ int main(int argc, char **argv) {
&& !SectionHeaders
&& !SectionContents
&& !SymbolTable
- && !UnwindInfo) {
+ && !UnwindInfo
+ && !PrivateHeaders) {
cl::PrintHelpMessage();
return 2;
}
diff --git a/tools/llvm-objdump/llvm-objdump.h b/tools/llvm-objdump/llvm-objdump.h
index 9f5a8c3..ca7bced 100644
--- a/tools/llvm-objdump/llvm-objdump.h
+++ b/tools/llvm-objdump/llvm-objdump.h
@@ -19,6 +19,7 @@ namespace llvm {
namespace object {
class COFFObjectFile;
+ class ObjectFile;
class RelocationRef;
}
class error_code;
@@ -32,6 +33,7 @@ bool RelocAddressLess(object::RelocationRef a, object::RelocationRef b);
void DumpBytes(StringRef bytes);
void DisassembleInputMachO(StringRef Filename);
void printCOFFUnwindInfo(const object::COFFObjectFile* o);
+void printELFFileHeader(const object::ObjectFile *o);
class StringRefMemoryObject : public MemoryObject {
virtual void anchor();