1 //===- COFF.h - COFF object file implementation -----------------*- 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 //===----------------------------------------------------------------------===//
10 // This file declares the COFFObjectFile class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_OBJECT_COFF_H
15 #define LLVM_OBJECT_COFF_H
17 #include "llvm/Object/ObjectFile.h"
18 #include "llvm/Support/COFF.h"
19 #include "llvm/Support/Endian.h"
24 struct coff_file_header {
25 support::ulittle16_t Machine;
26 support::ulittle16_t NumberOfSections;
27 support::ulittle32_t TimeDateStamp;
28 support::ulittle32_t PointerToSymbolTable;
29 support::ulittle32_t NumberOfSymbols;
30 support::ulittle16_t SizeOfOptionalHeader;
31 support::ulittle16_t Characteristics;
35 struct StringTableOffset {
36 support::ulittle32_t Zeroes;
37 support::ulittle32_t Offset;
42 StringTableOffset Offset;
45 support::ulittle32_t Value;
46 support::little16_t SectionNumber;
49 support::ulittle8_t BaseType;
50 support::ulittle8_t ComplexType;
53 support::ulittle8_t StorageClass;
54 support::ulittle8_t NumberOfAuxSymbols;
59 support::ulittle32_t VirtualSize;
60 support::ulittle32_t VirtualAddress;
61 support::ulittle32_t SizeOfRawData;
62 support::ulittle32_t PointerToRawData;
63 support::ulittle32_t PointerToRelocations;
64 support::ulittle32_t PointerToLinenumbers;
65 support::ulittle16_t NumberOfRelocations;
66 support::ulittle16_t NumberOfLinenumbers;
67 support::ulittle32_t Characteristics;
70 class COFFObjectFile : public ObjectFile {
72 const coff_file_header *Header;
73 const coff_section *SectionTable;
74 const coff_symbol *SymbolTable;
75 const char *StringTable;
76 uint32_t StringTableSize;
78 error_code getSection(int32_t index,
79 const coff_section *&Res) const;
80 error_code getString(uint32_t offset, StringRef &Res) const;
82 const coff_symbol *toSymb(DataRefImpl Symb) const;
83 const coff_section *toSec(DataRefImpl Sec) const;
86 virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const;
87 virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const;
88 virtual error_code getSymbolAddress(DataRefImpl Symb, uint64_t &Res) const;
89 virtual error_code getSymbolSize(DataRefImpl Symb, uint64_t &Res) const;
90 virtual error_code getSymbolNMTypeChar(DataRefImpl Symb, char &Res) const;
91 virtual error_code isSymbolInternal(DataRefImpl Symb, bool &Res) const;
93 virtual error_code getSectionNext(DataRefImpl Sec, SectionRef &Res) const;
94 virtual error_code getSectionName(DataRefImpl Sec, StringRef &Res) const;
95 virtual error_code getSectionAddress(DataRefImpl Sec, uint64_t &Res) const;
96 virtual error_code getSectionSize(DataRefImpl Sec, uint64_t &Res) const;
97 virtual error_code getSectionContents(DataRefImpl Sec, StringRef &Res) const;
98 virtual error_code isSectionText(DataRefImpl Sec, bool &Res) const;
101 COFFObjectFile(MemoryBuffer *Object, error_code &ec);
102 virtual symbol_iterator begin_symbols() const;
103 virtual symbol_iterator end_symbols() const;
104 virtual section_iterator begin_sections() const;
105 virtual section_iterator end_sections() const;
107 virtual uint8_t getBytesInAddress() const;
108 virtual StringRef getFileFormatName() const;
109 virtual unsigned getArch() const;