Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.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/IR/Mangler.h"
21#include "llvm/Object/COFF.h"
22#include "llvm/Object/ObjectFile.h"
23#include "llvm/Object/SymbolicFile.h"
24#include "llvm/Support/MemoryBufferRef.h"
25#include "llvm/Support/raw_ostream.h"
26
27namespacellvm {
28namespaceobject {
29
30constexpr std::string_viewImportDescriptorPrefix ="__IMPORT_DESCRIPTOR_";
31constexpr std::string_viewNullImportDescriptorSymbolName =
32"__NULL_IMPORT_DESCRIPTOR";
33constexpr std::string_viewNullThunkDataPrefix ="\x7f";
34constexpr std::string_viewNullThunkDataSuffix ="_NULL_THUNK_DATA";
35
36classCOFFImportFile :publicSymbolicFile {
37private:
38enum SymbolIndex { ImpSymbol, ThunkSymbol, ECAuxSymbol, ECThunkSymbol };
39
40public:
41COFFImportFile(MemoryBufferRef Source)
42 :SymbolicFile(ID_COFFImportFile, Source) {}
43
44staticboolclassof(Binaryconst *V) {return V->isCOFFImportFile(); }
45
46voidmoveSymbolNext(DataRefImpl &Symb) const override{ ++Symb.p; }
47
48ErrorprintSymbolName(raw_ostream &OS,DataRefImpl Symb)const override;
49
50Expected<uint32_t>getSymbolFlags(DataRefImpl Symb) const override{
51returnSymbolRef::SF_Global;
52 }
53
54basic_symbol_iteratorsymbol_begin() const override{
55returnBasicSymbolRef(DataRefImpl(),this);
56 }
57
58basic_symbol_iteratorsymbol_end() const override{
59DataRefImpl Symb;
60if (isData())
61 Symb.p = ImpSymbol + 1;
62elseif (COFF::isArm64EC(getMachine()))
63 Symb.p = ECThunkSymbol + 1;
64else
65 Symb.p = ThunkSymbol + 1;
66returnBasicSymbolRef(Symb,this);
67 }
68
69boolis64Bit() const override{returnfalse; }
70
71constcoff_import_header *getCOFFImportHeader() const{
72returnreinterpret_cast<constobject::coff_import_header *>(
73Data.getBufferStart());
74 }
75
76uint16_tgetMachine() const{returngetCOFFImportHeader()->Machine; }
77
78StringRefgetFileFormatName()const;
79StringRefgetExportName()const;
80
81private:
82bool isData() const{
83returngetCOFFImportHeader()->getType() ==COFF::IMPORT_DATA;
84 }
85};
86
87structCOFFShortExport {
88 /// The name of the export as specified in the .def file or on the command
89 /// line, i.e. "foo" in "/EXPORT:foo", and "bar" in "/EXPORT:foo=bar". This
90 /// may lack mangling, such as underscore prefixing and stdcall suffixing.
91 std::stringName;
92
93 /// The external, exported name. Only non-empty when export renaming is in
94 /// effect, i.e. "foo" in "/EXPORT:foo=bar".
95 std::stringExtName;
96
97 /// The real, mangled symbol name from the object file. Given
98 /// "/export:foo=bar", this could be "_bar@8" if bar is stdcall.
99 std::stringSymbolName;
100
101 /// Creates an import library entry that imports from a DLL export with a
102 /// different name. This is the name of the DLL export that should be
103 /// referenced when linking against this import library entry. In a .def
104 /// file, this is "baz" in "EXPORTS\nfoo = bar == baz".
105 std::stringImportName;
106
107 /// Specifies EXPORTAS name. In a .def file, this is "bar" in
108 /// "EXPORTS\nfoo EXPORTAS bar".
109 std::stringExportAs;
110
111uint16_tOrdinal = 0;
112boolNoname =false;
113boolData =false;
114boolPrivate =false;
115boolConstant =false;
116
117friendbooloperator==(constCOFFShortExport &L,constCOFFShortExport &R) {
118return L.Name == R.Name && L.ExtName == R.ExtName &&
119 L.Ordinal == R.Ordinal && L.Noname == R.Noname &&
120 L.Data == R.Data && L.Private == R.Private;
121 }
122
123friendbooloperator!=(constCOFFShortExport &L,constCOFFShortExport &R) {
124return !(L == R);
125 }
126};
127
128/// Writes a COFF import library containing entries described by the Exports
129/// array.
130///
131/// For hybrid targets such as ARM64EC, additional native entry points can be
132/// exposed using the NativeExports parameter. When NativeExports is used, the
133/// output import library will expose these native ARM64 imports alongside the
134/// entries described in the Exports array. Such a library can be used for
135/// linking both ARM64EC and pure ARM64 objects, and the linker will pick only
136/// the exports relevant to the target platform. For non-hybrid targets,
137/// the NativeExports parameter should not be used.
138ErrorwriteImportLibrary(StringRef ImportName,StringRef Path,
139ArrayRef<COFFShortExport> Exports,
140COFF::MachineTypesMachine,bool MinGW,
141ArrayRef<COFFShortExport> NativeExports = {});
142
143}// namespace object
144}// namespace llvm
145
146#endif
ArrayRef.h
Machine
COFF::MachineTypes Machine
Definition:COFFYAML.cpp:390
Mangler.h
MemoryBufferRef.h
ObjectFile.h
COFF.h
OS
raw_pwrite_stream & OS
Definition:SampleProfWriter.cpp:51
SymbolicFile.h
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition:ArrayRef.h:41
llvm::Constant
This is an important base class in LLVM.
Definition:Constant.h:42
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition:Error.h:160
llvm::Expected
Tagged union holding either a T or a Error.
Definition:Error.h:481
llvm::MemoryBufferRef
Definition:MemoryBufferRef.h:22
llvm::MemoryBufferRef::getBufferStart
const char * getBufferStart() const
Definition:MemoryBufferRef.h:35
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::object::BasicSymbolRef
This is a value type class that represents a single symbol in the list of symbols in the object file.
Definition:SymbolicFile.h:103
llvm::object::BasicSymbolRef::SF_Global
@ SF_Global
Definition:SymbolicFile.h:111
llvm::object::Binary
Definition:Binary.h:32
llvm::object::Binary::Data
MemoryBufferRef Data
Definition:Binary.h:37
llvm::object::Binary::ID_COFFImportFile
@ ID_COFFImportFile
Definition:Binary.h:44
llvm::object::COFFImportFile
Definition:COFFImportFile.h:36
llvm::object::COFFImportFile::getCOFFImportHeader
const coff_import_header * getCOFFImportHeader() const
Definition:COFFImportFile.h:71
llvm::object::COFFImportFile::getSymbolFlags
Expected< uint32_t > getSymbolFlags(DataRefImpl Symb) const override
Definition:COFFImportFile.h:50
llvm::object::COFFImportFile::is64Bit
bool is64Bit() const override
Definition:COFFImportFile.h:69
llvm::object::COFFImportFile::moveSymbolNext
void moveSymbolNext(DataRefImpl &Symb) const override
Definition:COFFImportFile.h:46
llvm::object::COFFImportFile::getFileFormatName
StringRef getFileFormatName() const
Definition:COFFImportFile.cpp:38
llvm::object::COFFImportFile::COFFImportFile
COFFImportFile(MemoryBufferRef Source)
Definition:COFFImportFile.h:41
llvm::object::COFFImportFile::symbol_begin
basic_symbol_iterator symbol_begin() const override
Definition:COFFImportFile.h:54
llvm::object::COFFImportFile::getExportName
StringRef getExportName() const
Definition:COFFImportFile.cpp:76
llvm::object::COFFImportFile::printSymbolName
Error printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override
Definition:COFFImportFile.cpp:101
llvm::object::COFFImportFile::symbol_end
basic_symbol_iterator symbol_end() const override
Definition:COFFImportFile.h:58
llvm::object::COFFImportFile::classof
static bool classof(Binary const *V)
Definition:COFFImportFile.h:44
llvm::object::COFFImportFile::getMachine
uint16_t getMachine() const
Definition:COFFImportFile.h:76
llvm::object::SymbolicFile
Definition:SymbolicFile.h:145
llvm::object::content_iterator
Definition:SymbolicFile.h:69
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition:raw_ostream.h:52
uint16_t
llvm::COFF::MachineTypes
MachineTypes
Definition:COFF.h:92
llvm::COFF::IMPORT_DATA
@ IMPORT_DATA
Definition:COFF.h:735
llvm::COFF::isArm64EC
bool isArm64EC(T Machine)
Definition:COFF.h:124
llvm::object::NullImportDescriptorSymbolName
constexpr std::string_view NullImportDescriptorSymbolName
Definition:COFFImportFile.h:31
llvm::object::NullThunkDataPrefix
constexpr std::string_view NullThunkDataPrefix
Definition:COFFImportFile.h:33
llvm::object::NullThunkDataSuffix
constexpr std::string_view NullThunkDataSuffix
Definition:COFFImportFile.h:34
llvm::object::ImportDescriptorPrefix
constexpr std::string_view ImportDescriptorPrefix
Definition:COFFImportFile.h:30
llvm::object::writeImportLibrary
Error writeImportLibrary(StringRef ImportName, StringRef Path, ArrayRef< COFFShortExport > Exports, COFF::MachineTypes Machine, bool MinGW, ArrayRef< COFFShortExport > NativeExports={})
Writes a COFF import library containing entries described by the Exports array.
Definition:COFFImportFile.cpp:661
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
raw_ostream.h
llvm::object::COFFShortExport
Definition:COFFImportFile.h:87
llvm::object::COFFShortExport::Name
std::string Name
The name of the export as specified in the .def file or on the command line, i.e.
Definition:COFFImportFile.h:91
llvm::object::COFFShortExport::SymbolName
std::string SymbolName
The real, mangled symbol name from the object file.
Definition:COFFImportFile.h:99
llvm::object::COFFShortExport::Private
bool Private
Definition:COFFImportFile.h:114
llvm::object::COFFShortExport::ExportAs
std::string ExportAs
Specifies EXPORTAS name.
Definition:COFFImportFile.h:109
llvm::object::COFFShortExport::operator!=
friend bool operator!=(const COFFShortExport &L, const COFFShortExport &R)
Definition:COFFImportFile.h:123
llvm::object::COFFShortExport::Ordinal
uint16_t Ordinal
Definition:COFFImportFile.h:111
llvm::object::COFFShortExport::ImportName
std::string ImportName
Creates an import library entry that imports from a DLL export with a different name.
Definition:COFFImportFile.h:105
llvm::object::COFFShortExport::ExtName
std::string ExtName
The external, exported name.
Definition:COFFImportFile.h:95
llvm::object::COFFShortExport::operator==
friend bool operator==(const COFFShortExport &L, const COFFShortExport &R)
Definition:COFFImportFile.h:117
llvm::object::COFFShortExport::Noname
bool Noname
Definition:COFFImportFile.h:112
llvm::object::COFFShortExport::Data
bool Data
Definition:COFFImportFile.h:113
llvm::object::coff_import_header
Definition:COFF.h:549
llvm::object::coff_import_header::Machine
support::ulittle16_t Machine
Definition:COFF.h:553
llvm::object::coff_import_header::getType
int getType() const
Definition:COFF.h:559
llvm::object::DataRefImpl
Definition:SymbolicFile.h:35
llvm::object::DataRefImpl::p
uintptr_t p
Definition:SymbolicFile.h:41

Generated on Thu Jul 17 2025 10:10:25 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp