2015-08-28 09:40:30 +02:00
|
|
|
//===- COFFImportFile.h - COFF short import file implementation -*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// COFF short import file is a special kind of file which contains
|
|
|
|
// only symbol names for DLL-exported symbols. This class implements
|
2017-06-02 18:26:24 +02:00
|
|
|
// SymbolicFile interface for the file.
|
2015-08-28 09:40:30 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_OBJECT_COFF_IMPORT_FILE_H
|
|
|
|
#define LLVM_OBJECT_COFF_IMPORT_FILE_H
|
|
|
|
|
|
|
|
#include "llvm/Object/COFF.h"
|
|
|
|
#include "llvm/Object/IRObjectFile.h"
|
|
|
|
#include "llvm/Object/ObjectFile.h"
|
|
|
|
#include "llvm/Object/SymbolicFile.h"
|
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2015-08-28 09:48:41 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2015-08-28 09:40:30 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace object {
|
|
|
|
|
|
|
|
class COFFImportFile : public SymbolicFile {
|
|
|
|
public:
|
|
|
|
COFFImportFile(MemoryBufferRef Source)
|
|
|
|
: SymbolicFile(ID_COFFImportFile, Source) {}
|
|
|
|
|
|
|
|
static inline bool classof(Binary const *V) { return V->isCOFFImportFile(); }
|
|
|
|
|
|
|
|
void moveSymbolNext(DataRefImpl &Symb) const override { ++Symb.p; }
|
|
|
|
|
|
|
|
std::error_code printSymbolName(raw_ostream &OS,
|
|
|
|
DataRefImpl Symb) const override {
|
2015-09-01 08:01:53 +02:00
|
|
|
if (Symb.p == 0)
|
2015-08-28 09:40:30 +02:00
|
|
|
OS << "__imp_";
|
|
|
|
OS << StringRef(Data.getBufferStart() + sizeof(coff_import_header));
|
|
|
|
return std::error_code();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t getSymbolFlags(DataRefImpl Symb) const override {
|
|
|
|
return SymbolRef::SF_Global;
|
|
|
|
}
|
|
|
|
|
2016-11-22 04:38:40 +01:00
|
|
|
basic_symbol_iterator symbol_begin() const override {
|
2015-08-28 09:40:30 +02:00
|
|
|
return BasicSymbolRef(DataRefImpl(), this);
|
|
|
|
}
|
|
|
|
|
2016-11-22 04:38:40 +01:00
|
|
|
basic_symbol_iterator symbol_end() const override {
|
2015-08-28 09:40:30 +02:00
|
|
|
DataRefImpl Symb;
|
2017-04-28 06:29:43 +02:00
|
|
|
Symb.p = isData() ? 1 : 2;
|
2015-08-28 09:40:30 +02:00
|
|
|
return BasicSymbolRef(Symb, this);
|
|
|
|
}
|
|
|
|
|
2015-08-28 12:27:50 +02:00
|
|
|
const coff_import_header *getCOFFImportHeader() const {
|
|
|
|
return reinterpret_cast<const object::coff_import_header *>(
|
|
|
|
Data.getBufferStart());
|
|
|
|
}
|
|
|
|
|
2015-08-28 09:40:30 +02:00
|
|
|
private:
|
2017-04-28 06:29:43 +02:00
|
|
|
bool isData() const {
|
|
|
|
return getCOFFImportHeader()->getType() == COFF::IMPORT_DATA;
|
2015-08-28 09:40:30 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace object
|
|
|
|
} // namespace llvm
|
|
|
|
|
|
|
|
#endif
|