1 //===- COFFImportFile.h - COFF short import 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 // COFF short import file is a special kind of file which contains
11 // only symbol names for DLL-exported symbols. This class implements
12 // exporting of Symbols to create libraries and a SymbolicFile
13 // interface for the file type.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_OBJECT_COFF_IMPORT_FILE_H
18 #define LLVM_OBJECT_COFF_IMPORT_FILE_H
20 #include "llvm/ADT/ArrayRef.h"
21 #include "llvm/Object/COFF.h"
22 #include "llvm/Object/IRObjectFile.h"
23 #include "llvm/Object/ObjectFile.h"
24 #include "llvm/Object/SymbolicFile.h"
25 #include "llvm/Support/MemoryBuffer.h"
26 #include "llvm/Support/raw_ostream.h"
31 class COFFImportFile : public SymbolicFile {
33 COFFImportFile(MemoryBufferRef Source)
34 : SymbolicFile(ID_COFFImportFile, Source) {}
36 static bool classof(Binary const *V) { return V->isCOFFImportFile(); }
38 void moveSymbolNext(DataRefImpl &Symb) const override { ++Symb.p; }
40 std::error_code printSymbolName(raw_ostream &OS,
41 DataRefImpl Symb) const override {
44 OS << StringRef(Data.getBufferStart() + sizeof(coff_import_header));
45 return std::error_code();
48 uint32_t getSymbolFlags(DataRefImpl Symb) const override {
49 return SymbolRef::SF_Global;
52 basic_symbol_iterator symbol_begin() const override {
53 return BasicSymbolRef(DataRefImpl(), this);
56 basic_symbol_iterator symbol_end() const override {
58 Symb.p = isData() ? 1 : 2;
59 return BasicSymbolRef(Symb, this);
62 const coff_import_header *getCOFFImportHeader() const {
63 return reinterpret_cast<const object::coff_import_header *>(
64 Data.getBufferStart());
69 return getCOFFImportHeader()->getType() == COFF::IMPORT_DATA;
73 struct COFFShortExport {
81 bool Constant = false;
84 return ExtName.size() && ExtName != Name;
87 friend bool operator==(const COFFShortExport &L, const COFFShortExport &R) {
88 return L.Name == R.Name && L.ExtName == R.ExtName &&
89 L.Ordinal == R.Ordinal && L.Noname == R.Noname &&
90 L.Data == R.Data && L.Private == R.Private;
93 friend bool operator!=(const COFFShortExport &L, const COFFShortExport &R) {
98 std::error_code writeImportLibrary(StringRef ImportName,
100 ArrayRef<COFFShortExport> Exports,
101 COFF::MachineTypes Machine);
103 } // namespace object