LLVM  14.0.0git
IFSStub.h
Go to the documentation of this file.
1 //===- IFSStub.h ------------------------------------------------*- 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 /// \file
10 /// This file defines an internal representation of an InterFace Stub.
11 ///
12 //===-----------------------------------------------------------------------===/
13 
14 #ifndef LLVM_INTERFACESTUB_IFSSTUB_H
15 #define LLVM_INTERFACESTUB_IFSSTUB_H
16 
17 #include "llvm/Support/Error.h"
19 #include <set>
20 #include <vector>
21 
22 namespace llvm {
23 namespace ifs {
24 
25 typedef uint16_t IFSArch;
26 
27 enum class IFSSymbolType {
28  NoType,
29  Object,
30  Func,
31  TLS,
32 
33  // Type information is 4 bits, so 16 is safely out of range.
34  Unknown = 16,
35 };
36 
37 enum class IFSEndiannessType {
38  Little,
39  Big,
40 
41  // Endianness info is 1 bytes, 256 is safely out of range.
42  Unknown = 256,
43 };
44 
45 enum class IFSBitWidthType {
46  IFS32,
47  IFS64,
48 
49  // Bit width info is 1 bytes, 256 is safely out of range.
50  Unknown = 256,
51 };
52 
53 struct IFSSymbol {
54  IFSSymbol() = default;
55  explicit IFSSymbol(std::string SymbolName) : Name(std::move(SymbolName)) {}
56  std::string Name;
59  bool Undefined;
60  bool Weak;
62  bool operator<(const IFSSymbol &RHS) const { return Name < RHS.Name; }
63 };
64 
65 struct IFSTarget {
72 
73  bool empty();
74 };
75 
76 inline bool operator==(const IFSTarget &Lhs, const IFSTarget &Rhs) {
77  if (Lhs.Arch != Rhs.Arch || Lhs.BitWidth != Rhs.BitWidth ||
78  Lhs.Endianness != Rhs.Endianness ||
79  Lhs.ObjectFormat != Rhs.ObjectFormat || Lhs.Triple != Rhs.Triple)
80  return false;
81  return true;
82 }
83 
84 inline bool operator!=(const IFSTarget &Lhs, const IFSTarget &Rhs) {
85  return !(Lhs == Rhs);
86 }
87 
88 // A cumulative representation of InterFace stubs.
89 // Both textual and binary stubs will read into and write from this object.
90 struct IFSStub {
91  // TODO: Add support for symbol versioning.
95  std::vector<std::string> NeededLibs;
96  std::vector<IFSSymbol> Symbols;
97 
98  IFSStub() {}
99  IFSStub(const IFSStub &Stub);
100  IFSStub(IFSStub &&Stub);
101 };
102 
103 // Create a alias class for IFSStub.
104 // LLVM's YAML library does not allow mapping a class with 2 traits,
105 // which prevents us using 'Target:' field with different definitions.
106 // This class makes it possible to map a second traits so the same data
107 // structure can be used for 2 different yaml schema.
110  IFSStubTriple(const IFSStub &Stub);
111  IFSStubTriple(const IFSStubTriple &Stub);
113 };
114 
115 /// This function convert bit width type from IFS enum to ELF format
116 /// Currently, ELFCLASS32 and ELFCLASS64 are supported.
117 ///
118 /// @param BitWidth IFS bit width type.
120 
121 /// This function convert endianness type from IFS enum to ELF format
122 /// Currently, ELFDATA2LSB and ELFDATA2MSB are supported.
123 ///
124 /// @param Endianness IFS endianness type.
126 
127 /// This function convert symbol type from IFS enum to ELF format
128 /// Currently, STT_NOTYPE, STT_OBJECT, STT_FUNC, and STT_TLS are supported.
129 ///
130 /// @param SymbolType IFS symbol type.
132 
133 /// This function extracts ELF bit width from e_ident[EI_CLASS] of an ELF file
134 /// Currently, ELFCLASS32 and ELFCLASS64 are supported.
135 /// Other endianness types are mapped to IFSBitWidthType::Unknown.
136 ///
137 /// @param BitWidth e_ident[EI_CLASS] value to extract bit width from.
139 
140 /// This function extracts ELF endianness from e_ident[EI_DATA] of an ELF file
141 /// Currently, ELFDATA2LSB and ELFDATA2MSB are supported.
142 /// Other endianness types are mapped to IFSEndiannessType::Unknown.
143 ///
144 /// @param Endianness e_ident[EI_DATA] value to extract endianness type from.
146 
147 /// This function extracts symbol type from a symbol's st_info member and
148 /// maps it to an IFSSymbolType enum.
149 /// Currently, STT_NOTYPE, STT_OBJECT, STT_FUNC, and STT_TLS are supported.
150 /// Other symbol types are mapped to IFSSymbolType::Unknown.
151 ///
152 /// @param SymbolType Binary symbol st_info to extract symbol type from.
154 } // namespace ifs
155 } // end namespace llvm
156 
157 #endif // LLVM_INTERFACESTUB_IFSSTUB_H
llvm::ifs::IFSSymbolType::Unknown
@ Unknown
llvm::ifs::IFSStub::NeededLibs
std::vector< std::string > NeededLibs
Definition: IFSStub.h:95
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::msgpack::Endianness
constexpr support::endianness Endianness
The endianness of all multi-byte encoded values in MessagePack.
Definition: MsgPack.h:24
llvm::ifs::IFSBitWidthType
IFSBitWidthType
Definition: IFSStub.h:45
llvm::ifs::IFSSymbol
Definition: IFSStub.h:53
llvm::ifs::IFSStub::IFSStub
IFSStub()
Definition: IFSStub.h:98
llvm::ifs::operator==
bool operator==(const IFSTarget &Lhs, const IFSTarget &Rhs)
Definition: IFSStub.h:76
llvm::ifs::convertIFSSymbolTypeToELF
uint8_t convertIFSSymbolTypeToELF(IFSSymbolType SymbolType)
This function convert symbol type from IFS enum to ELF format Currently, STT_NOTYPE,...
Definition: IFSStub.cpp:83
llvm::ifs::IFSTarget::Arch
Optional< IFSArch > Arch
Definition: IFSStub.h:68
VersionTuple.h
llvm::XCOFF::SymbolType
SymbolType
Definition: XCOFF.h:183
Error.h
llvm::Optional< std::string >
llvm::ifs::operator!=
bool operator!=(const IFSTarget &Lhs, const IFSTarget &Rhs)
Definition: IFSStub.h:84
llvm::ifs::IFSSymbol::Name
std::string Name
Definition: IFSStub.h:56
llvm::ifs::IFSSymbol::IFSSymbol
IFSSymbol()=default
llvm::ifs::convertELFSymbolTypeToIFS
IFSSymbolType convertELFSymbolTypeToIFS(uint8_t SymbolType)
This function extracts symbol type from a symbol's st_info member and maps it to an IFSSymbolType enu...
Definition: IFSStub.cpp:119
llvm::ifs::IFSBitWidthType::Unknown
@ Unknown
llvm::ifs::IFSArch
uint16_t IFSArch
Definition: IFSStub.h:25
llvm::ifs::IFSSymbol::Size
uint64_t Size
Definition: IFSStub.h:57
llvm::ifs::IFSSymbolType
IFSSymbolType
Definition: IFSStub.h:27
llvm::ifs::convertIFSBitWidthToELF
uint8_t convertIFSBitWidthToELF(IFSBitWidthType BitWidth)
This function convert bit width type from IFS enum to ELF format Currently, ELFCLASS32 and ELFCLASS64...
Definition: IFSStub.cpp:61
llvm::ifs::IFSSymbol::IFSSymbol
IFSSymbol(std::string SymbolName)
Definition: IFSStub.h:55
llvm::ifs::IFSStub
Definition: IFSStub.h:90
llvm::ifs::IFSSymbolType::TLS
@ TLS
llvm::ifs::IFSTarget::empty
bool empty()
Definition: IFSStub.cpp:56
llvm::ifs::IFSStubTriple::IFSStubTriple
IFSStubTriple()
Definition: IFSStub.h:109
llvm::ifs::IFSBitWidthType::IFS32
@ IFS32
llvm::ifs::IFSSymbol::Warning
Optional< std::string > Warning
Definition: IFSStub.h:61
llvm::VersionTuple
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:29
llvm::ifs::IFSEndiannessType::Big
@ Big
llvm::ifs::IFSStub::SoName
Optional< std::string > SoName
Definition: IFSStub.h:93
llvm::ifs::IFSTarget::BitWidth
Optional< IFSBitWidthType > BitWidth
Definition: IFSStub.h:71
llvm::ifs::IFSEndiannessType::Unknown
@ Unknown
llvm::ifs::convertELFEndiannessToIFS
IFSEndiannessType convertELFEndiannessToIFS(uint8_t Endianness)
This function extracts ELF endianness from e_ident[EI_DATA] of an ELF file Currently,...
Definition: IFSStub.cpp:108
llvm::ifs::IFSTarget::ArchString
Optional< std::string > ArchString
Definition: IFSStub.h:69
llvm::ifs::IFSSymbol::Undefined
bool Undefined
Definition: IFSStub.h:59
llvm::ifs::IFSSymbolType::NoType
@ NoType
llvm::ifs::IFSTarget::Triple
Optional< std::string > Triple
Definition: IFSStub.h:66
uint64_t
llvm::ifs::convertELFBitWidthToIFS
IFSBitWidthType convertELFBitWidthToIFS(uint8_t BitWidth)
This function extracts ELF bit width from e_ident[EI_CLASS] of an ELF file Currently,...
Definition: IFSStub.cpp:97
llvm::ifs::IFSBitWidthType::IFS64
@ IFS64
llvm::ifs::IFSEndiannessType::Little
@ Little
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1605
llvm::ifs::IFSStubTriple
Definition: IFSStub.h:108
llvm::ifs::convertIFSEndiannessToELF
uint8_t convertIFSEndiannessToELF(IFSEndiannessType Endianness)
This function convert endianness type from IFS enum to ELF format Currently, ELFDATA2LSB and ELFDATA2...
Definition: IFSStub.cpp:72
llvm::ifs::IFSEndiannessType
IFSEndiannessType
Definition: IFSStub.h:37
llvm::ifs::IFSSymbolType::Func
@ Func
llvm::ifs::IFSSymbol::Weak
bool Weak
Definition: IFSStub.h:60
llvm::ifs::IFSTarget
Definition: IFSStub.h:65
llvm::AMDGPU::HSAMD::Kernel::Key::SymbolName
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
Definition: AMDGPUMetadata.h:381
std
Definition: BitVector.h:838
uint16_t
llvm::ifs::IFSStub::Target
IFSTarget Target
Definition: IFSStub.h:94
llvm::ifs::IFSStub::IfsVersion
VersionTuple IfsVersion
Definition: IFSStub.h:92
llvm::BitWidth
constexpr unsigned BitWidth
Definition: BitmaskEnum.h:147
llvm::ifs::IFSSymbolType::Object
@ Object
llvm::ifs::IFSStub::Symbols
std::vector< IFSSymbol > Symbols
Definition: IFSStub.h:96
llvm::ifs::IFSTarget::ObjectFormat
Optional< std::string > ObjectFormat
Definition: IFSStub.h:67
llvm::ifs::IFSTarget::Endianness
Optional< IFSEndiannessType > Endianness
Definition: IFSStub.h:70
llvm::ifs::IFSSymbol::Type
IFSSymbolType Type
Definition: IFSStub.h:58
llvm::ifs::IFSSymbol::operator<
bool operator<(const IFSSymbol &RHS) const
Definition: IFSStub.h:62