LLVM  15.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"
21 #include "llvm/Object/ObjectFile.h"
25 
26 namespace llvm {
27 namespace object {
28 
29 class COFFImportFile : public SymbolicFile {
30 public:
33 
34  static bool classof(Binary const *V) { return V->isCOFFImportFile(); }
35 
36  void moveSymbolNext(DataRefImpl &Symb) const override { ++Symb.p; }
37 
38  Error printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override {
39  if (Symb.p == 0)
40  OS << "__imp_";
42  return Error::success();
43  }
44 
46  return SymbolRef::SF_Global;
47  }
48 
50  return BasicSymbolRef(DataRefImpl(), this);
51  }
52 
53  basic_symbol_iterator symbol_end() const override {
54  DataRefImpl Symb;
55  Symb.p = isData() ? 1 : 2;
56  return BasicSymbolRef(Symb, this);
57  }
58 
60  return reinterpret_cast<const object::coff_import_header *>(
62  }
63 
64 private:
65  bool isData() const {
67  }
68 };
69 
71  /// The name of the export as specified in the .def file or on the command
72  /// line, i.e. "foo" in "/EXPORT:foo", and "bar" in "/EXPORT:foo=bar". This
73  /// may lack mangling, such as underscore prefixing and stdcall suffixing.
74  std::string Name;
75 
76  /// The external, exported name. Only non-empty when export renaming is in
77  /// effect, i.e. "foo" in "/EXPORT:foo=bar".
78  std::string ExtName;
79 
80  /// The real, mangled symbol name from the object file. Given
81  /// "/export:foo=bar", this could be "_bar@8" if bar is stdcall.
82  std::string SymbolName;
83 
84  /// Creates a weak alias. This is the name of the weak aliasee. In a .def
85  /// file, this is "baz" in "EXPORTS\nfoo = bar == baz".
86  std::string AliasTarget;
87 
89  bool Noname = false;
90  bool Data = false;
91  bool Private = false;
92  bool Constant = false;
93 
94  friend bool operator==(const COFFShortExport &L, const COFFShortExport &R) {
95  return L.Name == R.Name && L.ExtName == R.ExtName &&
96  L.Ordinal == R.Ordinal && L.Noname == R.Noname &&
97  L.Data == R.Data && L.Private == R.Private;
98  }
99 
100  friend bool operator!=(const COFFShortExport &L, const COFFShortExport &R) {
101  return !(L == R);
102  }
103 };
104 
107  COFF::MachineTypes Machine, bool MinGW);
108 
109 } // namespace object
110 } // namespace llvm
111 
112 #endif
llvm::object::COFFShortExport::operator==
friend bool operator==(const COFFShortExport &L, const COFFShortExport &R)
Definition: COFFImportFile.h:94
llvm::object::COFFShortExport
Definition: COFFImportFile.h:70
llvm::MemoryBufferRef::getBufferStart
const char * getBufferStart() const
Definition: MemoryBufferRef.h:35
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::object::COFFImportFile::classof
static bool classof(Binary const *V)
Definition: COFFImportFile.h:34
llvm::object::coff_import_header::getType
int getType() const
Definition: COFF.h:551
llvm::object::COFFImportFile::symbol_end
basic_symbol_iterator symbol_end() const override
Definition: COFFImportFile.h:53
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:329
llvm::object::Binary::ID_COFFImportFile
@ ID_COFFImportFile
Definition: Binary.h:44
MemoryBufferRef.h
llvm::object::Binary::Data
MemoryBufferRef Data
Definition: Binary.h:37
llvm::object::COFFShortExport::ExtName
std::string ExtName
The external, exported name.
Definition: COFFImportFile.h:78
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
llvm::object::COFFShortExport::Ordinal
uint16_t Ordinal
Definition: COFFImportFile.h:88
llvm::object::COFFShortExport::operator!=
friend bool operator!=(const COFFShortExport &L, const COFFShortExport &R)
Definition: COFFImportFile.h:100
SymbolicFile.h
llvm::MemoryBufferRef
Definition: MemoryBufferRef.h:22
llvm::object::COFFImportFile::getCOFFImportHeader
const coff_import_header * getCOFFImportHeader() const
Definition: COFFImportFile.h:59
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::COFFShortExport::SymbolName
std::string SymbolName
The real, mangled symbol name from the object file.
Definition: COFFImportFile.h:82
llvm::object::Binary::isCOFFImportFile
bool isCOFFImportFile() const
Definition: Binary.h:140
llvm::object::COFFShortExport::Noname
bool Noname
Definition: COFFImportFile.h:89
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::object::DataRefImpl::p
uintptr_t p
Definition: SymbolicFile.h:41
object
bar al al movzbl eax ret Missed when stored in a memory object
Definition: README.txt:1411
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::object::COFFImportFile::symbol_begin
basic_symbol_iterator symbol_begin() const override
Definition: COFFImportFile.h:49
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:74
ArrayRef.h
llvm::object::writeImportLibrary
Error writeImportLibrary(StringRef ImportName, StringRef Path, ArrayRef< COFFShortExport > Exports, COFF::MachineTypes Machine, bool MinGW)
Definition: COFFImportFile.cpp:575
ObjectFile.h
llvm::object::COFFImportFile::moveSymbolNext
void moveSymbolNext(DataRefImpl &Symb) const override
Definition: COFFImportFile.h:36
llvm::object::content_iterator
Definition: SymbolicFile.h:69
llvm::Sched::Source
@ Source
Definition: TargetLowering.h:99
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::object::Binary
Definition: Binary.h:32
llvm::object::DataRefImpl
Definition: SymbolicFile.h:35
llvm::object::COFFShortExport::Private
bool Private
Definition: COFFImportFile.h:91
llvm::object::COFFImportFile::printSymbolName
Error printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override
Definition: COFFImportFile.h:38
uint16_t
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::object::COFFImportFile::COFFImportFile
COFFImportFile(MemoryBufferRef Source)
Definition: COFFImportFile.h:31
llvm::COFF::MachineTypes
MachineTypes
Definition: COFF.h:92
llvm::object::COFFImportFile
Definition: COFFImportFile.h:29
llvm::object::COFFShortExport::Data
bool Data
Definition: COFFImportFile.h:90
llvm::object::COFFImportFile::getSymbolFlags
Expected< uint32_t > getSymbolFlags(DataRefImpl Symb) const override
Definition: COFFImportFile.h:45
llvm::COFF::IMPORT_DATA
@ IMPORT_DATA
Definition: COFF.h:687
Machine
COFF::MachineTypes Machine
Definition: COFFYAML.cpp:369
COFF.h
llvm::object::BasicSymbolRef::SF_Global
@ SF_Global
Definition: SymbolicFile.h:111
llvm::object::COFFShortExport::AliasTarget
std::string AliasTarget
Creates a weak alias.
Definition: COFFImportFile.h:86
llvm::object::coff_import_header
Definition: COFF.h:541
raw_ostream.h
llvm::object::SymbolicFile
Definition: SymbolicFile.h:145