• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- COFFImportFile.h - COFF short import file implementation -*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // COFF short import file is a special kind of file which contains
11 // only symbol names for DLL-exported symbols. This class implements
12 // SymbolicFile interface for the file.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_OBJECT_COFF_IMPORT_FILE_H
17 #define LLVM_OBJECT_COFF_IMPORT_FILE_H
18 
19 #include "llvm/Object/COFF.h"
20 #include "llvm/Object/IRObjectFile.h"
21 #include "llvm/Object/ObjectFile.h"
22 #include "llvm/Object/SymbolicFile.h"
23 #include "llvm/Support/MemoryBuffer.h"
24 #include "llvm/Support/raw_ostream.h"
25 
26 namespace llvm {
27 namespace object {
28 
29 class COFFImportFile : public SymbolicFile {
30 public:
COFFImportFile(MemoryBufferRef Source)31   COFFImportFile(MemoryBufferRef Source)
32       : SymbolicFile(ID_COFFImportFile, Source) {}
33 
classof(Binary const * V)34   static inline bool classof(Binary const *V) { return V->isCOFFImportFile(); }
35 
moveSymbolNext(DataRefImpl & Symb)36   void moveSymbolNext(DataRefImpl &Symb) const override { ++Symb.p; }
37 
printSymbolName(raw_ostream & OS,DataRefImpl Symb)38   std::error_code printSymbolName(raw_ostream &OS,
39                                   DataRefImpl Symb) const override {
40     if (Symb.p == 0)
41       OS << "__imp_";
42     OS << StringRef(Data.getBufferStart() + sizeof(coff_import_header));
43     return std::error_code();
44   }
45 
getSymbolFlags(DataRefImpl Symb)46   uint32_t getSymbolFlags(DataRefImpl Symb) const override {
47     return SymbolRef::SF_Global;
48   }
49 
symbol_begin_impl()50   basic_symbol_iterator symbol_begin_impl() const override {
51     return BasicSymbolRef(DataRefImpl(), this);
52   }
53 
symbol_end_impl()54   basic_symbol_iterator symbol_end_impl() const override {
55     DataRefImpl Symb;
56     Symb.p = isCode() ? 2 : 1;
57     return BasicSymbolRef(Symb, this);
58   }
59 
getCOFFImportHeader()60   const coff_import_header *getCOFFImportHeader() const {
61     return reinterpret_cast<const object::coff_import_header *>(
62         Data.getBufferStart());
63   }
64 
65 private:
isCode()66   bool isCode() const {
67     return getCOFFImportHeader()->getType() == COFF::IMPORT_CODE;
68   }
69 };
70 
71 } // namespace object
72 } // namespace llvm
73 
74 #endif
75