1 //===- COFFImportFile.h - COFF short import file implementation -*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // COFF short import file is a special kind of file which contains
10 // only symbol names for DLL-exported symbols. This class implements
11 // exporting of Symbols to create libraries and a SymbolicFile
12 // interface for the file type.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_OBJECT_COFF_IMPORT_FILE_H
17 #define LLVM_OBJECT_COFF_IMPORT_FILE_H
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/Object/COFF.h"
21 #include "llvm/Object/IRObjectFile.h"
22 #include "llvm/Object/ObjectFile.h"
23 #include "llvm/Object/SymbolicFile.h"
24 #include "llvm/Support/MemoryBuffer.h"
25 #include "llvm/Support/raw_ostream.h"
30 class COFFImportFile
: public SymbolicFile
{
32 COFFImportFile(MemoryBufferRef Source
)
33 : SymbolicFile(ID_COFFImportFile
, Source
) {}
35 static bool classof(Binary
const *V
) { return V
->isCOFFImportFile(); }
37 void moveSymbolNext(DataRefImpl
&Symb
) const override
{ ++Symb
.p
; }
39 std::error_code
printSymbolName(raw_ostream
&OS
,
40 DataRefImpl Symb
) const override
{
43 OS
<< StringRef(Data
.getBufferStart() + sizeof(coff_import_header
));
44 return std::error_code();
47 uint32_t getSymbolFlags(DataRefImpl Symb
) const override
{
48 return SymbolRef::SF_Global
;
51 basic_symbol_iterator
symbol_begin() const override
{
52 return BasicSymbolRef(DataRefImpl(), this);
55 basic_symbol_iterator
symbol_end() const override
{
57 Symb
.p
= isData() ? 1 : 2;
58 return BasicSymbolRef(Symb
, this);
61 const coff_import_header
*getCOFFImportHeader() const {
62 return reinterpret_cast<const object::coff_import_header
*>(
63 Data
.getBufferStart());
68 return getCOFFImportHeader()->getType() == COFF::IMPORT_DATA
;
72 struct COFFShortExport
{
75 std::string SymbolName
;
76 std::string AliasTarget
;
82 bool Constant
= false;
84 friend bool operator==(const COFFShortExport
&L
, const COFFShortExport
&R
) {
85 return L
.Name
== R
.Name
&& L
.ExtName
== R
.ExtName
&&
86 L
.Ordinal
== R
.Ordinal
&& L
.Noname
== R
.Noname
&&
87 L
.Data
== R
.Data
&& L
.Private
== R
.Private
;
90 friend bool operator!=(const COFFShortExport
&L
, const COFFShortExport
&R
) {
95 Error
writeImportLibrary(StringRef ImportName
, StringRef Path
,
96 ArrayRef
<COFFShortExport
> Exports
,
97 COFF::MachineTypes Machine
, bool MinGW
);