summaryrefslogtreecommitdiff
path: root/include/llvm/Object
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2013-09-27 21:04:00 +0000
committerRui Ueyama <ruiu@google.com>2013-09-27 21:04:00 +0000
commita6610ee882fcb8bcad60d53fc52b80f00a3fddae (patch)
tree83c3eaa619ccecb6a3b9a53f4d0bf662f3c1f3aa /include/llvm/Object
parent52fbca55ad4c11516b87544a2048667b63d0694c (diff)
downloadllvm-a6610ee882fcb8bcad60d53fc52b80f00a3fddae.tar.gz
llvm-a6610ee882fcb8bcad60d53fc52b80f00a3fddae.tar.bz2
llvm-a6610ee882fcb8bcad60d53fc52b80f00a3fddae.tar.xz
Re-submit r191472 with a fix for big endian.
llvm-objdump: Dump COFF import table if -private-headers option is given. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191557 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Object')
-rw-r--r--include/llvm/Object/COFF.h56
1 files changed, 54 insertions, 2 deletions
diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h
index cb464abeeb..838e8f199a 100644
--- a/include/llvm/Object/COFF.h
+++ b/include/llvm/Object/COFF.h
@@ -23,6 +23,8 @@ namespace llvm {
class ArrayRef;
namespace object {
+class ImportDirectoryEntryRef;
+typedef content_iterator<ImportDirectoryEntryRef> import_directory_iterator;
/// The DOS compatible header at the front of all PE/COFF executables.
struct dos_header {
@@ -137,6 +139,22 @@ struct import_directory_table_entry {
support::ulittle32_t ImportAddressTableRVA;
};
+struct import_lookup_table_entry32 {
+ support::ulittle32_t data;
+
+ bool isOrdinal() const { return data & 0x80000000; }
+
+ uint16_t getOrdinal() const {
+ assert(isOrdinal() && "ILT entry is not an ordinal!");
+ return data & 0xFFFF;
+ }
+
+ uint32_t getHintNameRVA() const {
+ assert(!isOrdinal() && "ILT entry is not a Hint/Name RVA!");
+ return data;
+ }
+};
+
struct coff_symbol {
struct StringTableOffset {
support::ulittle32_t Zeroes;
@@ -202,6 +220,7 @@ struct coff_aux_section_definition {
class COFFObjectFile : public ObjectFile {
private:
+ friend class ImportDirectoryEntryRef;
const coff_file_header *COFFHeader;
const pe32_header *PE32Header;
const data_directory *DataDirectory;
@@ -209,6 +228,8 @@ private:
const coff_symbol *SymbolTable;
const char *StringTable;
uint32_t StringTableSize;
+ const import_directory_table_entry *ImportDirectory;
+ uint32_t NumberOfImportDirectory;
error_code getString(uint32_t offset, StringRef &Res) const;
@@ -216,6 +237,9 @@ private:
const coff_section *toSec(DataRefImpl Sec) const;
const coff_relocation *toRel(DataRefImpl Rel) const;
+ error_code initSymbolTablePtr();
+ error_code initImportTablePtr();
+
protected:
virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const;
virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const;
@@ -287,6 +311,9 @@ public:
virtual unsigned getArch() const;
virtual StringRef getLoadName() const;
+ import_directory_iterator getImportDirectoryBegin() const;
+ import_directory_iterator getImportDirectoryEnd() const;
+
error_code getHeader(const coff_file_header *&Res) const;
error_code getCOFFHeader(const coff_file_header *&Res) const;
error_code getPE32Header(const pe32_header *&Res) const;
@@ -307,12 +334,37 @@ public:
error_code getSectionContents(const coff_section *Sec,
ArrayRef<uint8_t> &Res) const;
+ error_code getRvaPtr(uint32_t Rva, uintptr_t &Res) const;
+ error_code getHintName(uint32_t Rva, uint16_t &Hint, StringRef &Name) const;
+
static inline bool classof(const Binary *v) {
return v->isCOFF();
}
};
-}
-}
+// The iterator for the import directory table.
+class ImportDirectoryEntryRef {
+public:
+ ImportDirectoryEntryRef() : OwningObject(0) {}
+ ImportDirectoryEntryRef(DataRefImpl ImportDirectory,
+ const COFFObjectFile *Owner)
+ : ImportDirectoryPimpl(ImportDirectory), OwningObject(Owner) {}
+
+ bool operator==(const ImportDirectoryEntryRef &Other) const;
+ error_code getNext(ImportDirectoryEntryRef &Result) const;
+ error_code getName(StringRef &Result) const;
+
+ error_code
+ getImportTableEntry(const import_directory_table_entry *&Result) const;
+
+ error_code
+ getImportLookupEntry(const import_lookup_table_entry32 *&Result) const;
+
+private:
+ DataRefImpl ImportDirectoryPimpl;
+ const COFFObjectFile *OwningObject;
+};
+} // end namespace object
+} // end namespace llvm
#endif