LLVM 18.0.0git
COFFImportFile.h
Go to the documentation of this file.
1//===- COFFImportFile.h - COFF short import file implementation -*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
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.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_OBJECT_COFFIMPORTFILE_H
17#define LLVM_OBJECT_COFFIMPORTFILE_H
18
19#include "llvm/ADT/ArrayRef.h"
20#include "llvm/Object/COFF.h"
25
26namespace llvm {
27namespace object {
28
30public:
33
34 static bool classof(Binary const *V) { return V->isCOFFImportFile(); }
35
36 void moveSymbolNext(DataRefImpl &Symb) const override { ++Symb.p; }
37
39 if (Symb.p == 0)
40 OS << "__imp_";
42 return Error::success();
43 }
44
47 }
48
50 return BasicSymbolRef(DataRefImpl(), this);
51 }
52
54 DataRefImpl Symb;
55 Symb.p = isData() ? 1 : 2;
56 return BasicSymbolRef(Symb, this);
57 }
58
59 bool is64Bit() const override { return false; }
60
62 return reinterpret_cast<const object::coff_import_header *>(
64 }
65
66private:
67 bool isData() const {
69 }
70};
71
73 /// The name of the export as specified in the .def file or on the command
74 /// line, i.e. "foo" in "/EXPORT:foo", and "bar" in "/EXPORT:foo=bar". This
75 /// may lack mangling, such as underscore prefixing and stdcall suffixing.
76 std::string Name;
77
78 /// The external, exported name. Only non-empty when export renaming is in
79 /// effect, i.e. "foo" in "/EXPORT:foo=bar".
80 std::string ExtName;
81
82 /// The real, mangled symbol name from the object file. Given
83 /// "/export:foo=bar", this could be "_bar@8" if bar is stdcall.
84 std::string SymbolName;
85
86 /// Creates a weak alias. This is the name of the weak aliasee. In a .def
87 /// file, this is "baz" in "EXPORTS\nfoo = bar == baz".
88 std::string AliasTarget;
89
91 bool Noname = false;
92 bool Data = false;
93 bool Private = false;
94 bool Constant = false;
95
96 friend bool operator==(const COFFShortExport &L, const COFFShortExport &R) {
97 return L.Name == R.Name && L.ExtName == R.ExtName &&
98 L.Ordinal == R.Ordinal && L.Noname == R.Noname &&
99 L.Data == R.Data && L.Private == R.Private;
100 }
101
102 friend bool operator!=(const COFFShortExport &L, const COFFShortExport &R) {
103 return !(L == R);
104 }
105};
106
109 COFF::MachineTypes Machine, bool MinGW);
110
111} // namespace object
112} // namespace llvm
113
114#endif
raw_pwrite_stream & OS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
This is an important base class in LLVM.
Definition: Constant.h:41
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:334
Tagged union holding either a T or a Error.
Definition: Error.h:474
const char * getBufferStart() const
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This is a value type class that represents a single symbol in the list of symbols in the object file.
Definition: SymbolicFile.h:103
MemoryBufferRef Data
Definition: Binary.h:37
const coff_import_header * getCOFFImportHeader() const
Expected< uint32_t > getSymbolFlags(DataRefImpl Symb) const override
bool is64Bit() const override
void moveSymbolNext(DataRefImpl &Symb) const override
COFFImportFile(MemoryBufferRef Source)
basic_symbol_iterator symbol_begin() const override
Error printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override
basic_symbol_iterator symbol_end() const override
static bool classof(Binary const *V)
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
MachineTypes
Definition: COFF.h:92
@ IMPORT_DATA
Definition: COFF.h:702
Error writeImportLibrary(StringRef ImportName, StringRef Path, ArrayRef< COFFShortExport > Exports, COFF::MachineTypes Machine, bool MinGW)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::string Name
The name of the export as specified in the .def file or on the command line, i.e.
std::string SymbolName
The real, mangled symbol name from the object file.
friend bool operator!=(const COFFShortExport &L, const COFFShortExport &R)
std::string AliasTarget
Creates a weak alias.
std::string ExtName
The external, exported name.
friend bool operator==(const COFFShortExport &L, const COFFShortExport &R)