LLVM 19.0.0git
Symbol.h
Go to the documentation of this file.
1//===- llvm/TextAPI/Symbol.h - TAPI Symbol ----------------------*- 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#ifndef LLVM_TEXTAPI_SYMBOL_H
10#define LLVM_TEXTAPI_SYMBOL_H
11
13#include "llvm/ADT/StringRef.h"
16#include "llvm/TextAPI/Target.h"
17
18namespace llvm {
19namespace MachO {
20
21// clang-format off
22
23/// Symbol flags.
24enum class SymbolFlags : uint8_t {
25 /// No flags
26 None = 0,
27
28 /// Thread-local value symbol
29 ThreadLocalValue = 1U << 0,
30
31 /// Weak defined symbol
32 WeakDefined = 1U << 1,
33
34 /// Weak referenced symbol
35 WeakReferenced = 1U << 2,
36
37 /// Undefined
38 Undefined = 1U << 3,
39
40 /// Rexported
41 Rexported = 1U << 4,
42
43 /// Data Segment
44 Data = 1U << 5,
45
46 /// Text Segment
47 Text = 1U << 6,
48
49 LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/Text),
50};
51
52// clang-format on
53
54/// Mapping of entry types in TextStubs.
55enum class EncodeKind : uint8_t {
60};
61
62constexpr StringLiteral ObjC1ClassNamePrefix = ".objc_class_name_";
63constexpr StringLiteral ObjC2ClassNamePrefix = "_OBJC_CLASS_$_";
64constexpr StringLiteral ObjC2MetaClassNamePrefix = "_OBJC_METACLASS_$_";
65constexpr StringLiteral ObjC2EHTypePrefix = "_OBJC_EHTYPE_$_";
66constexpr StringLiteral ObjC2IVarPrefix = "_OBJC_IVAR_$_";
67
68/// ObjC Interface symbol mappings.
69enum class ObjCIFSymbolKind : uint8_t {
70 None = 0,
71 /// Is OBJC_CLASS* symbol.
72 Class = 1U << 0,
73 /// Is OBJC_METACLASS* symbol.
74 MetaClass = 1U << 1,
75 /// Is OBJC_EHTYPE* symbol.
76 EHType = 1U << 2,
77
78 LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/EHType),
79};
80
82
83// Keep containers that hold Targets in sorted order and uniqued.
84template <typename C>
85typename C::iterator addEntry(C &Container, const Target &Targ) {
86 auto Iter =
87 lower_bound(Container, Targ, [](const Target &LHS, const Target &RHS) {
88 return LHS < RHS;
89 });
90 if ((Iter != std::end(Container)) && !(Targ < *Iter))
91 return Iter;
92
93 return Container.insert(Iter, Targ);
94}
95
96class Symbol {
97public:
98 Symbol(EncodeKind Kind, StringRef Name, TargetList Targets, SymbolFlags Flags)
99 : Name(Name), Targets(std::move(Targets)), Kind(Kind), Flags(Flags) {}
100
101 void addTarget(Target InputTarget) { addEntry(Targets, InputTarget); }
102 EncodeKind getKind() const { return Kind; }
103 StringRef getName() const { return Name; }
105 return mapToArchitectureSet(Targets);
106 }
107 SymbolFlags getFlags() const { return Flags; }
108
109 bool isWeakDefined() const {
111 }
112
113 bool isWeakReferenced() const {
115 }
116
117 bool isThreadLocalValue() const {
118 return (Flags & SymbolFlags::ThreadLocalValue) ==
120 }
121
122 bool isUndefined() const {
124 }
125
126 bool isReexported() const {
128 }
129
130 bool isData() const {
131 return (Flags & SymbolFlags::Data) == SymbolFlags::Data;
132 }
133
134 bool isText() const {
135 return (Flags & SymbolFlags::Text) == SymbolFlags::Text;
136 }
137
138 bool hasArchitecture(Architecture Arch) const {
139 return mapToArchitectureSet(Targets).contains(Arch);
140 }
141
142 bool hasTarget(const Target &Targ) const {
143 return llvm::is_contained(Targets, Targ);
144 }
145
148 const_target_range targets() const { return {Targets}; }
149
152 std::function<bool(const Target &)>>;
156
157#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
158 void dump(raw_ostream &OS) const;
159 void dump() const { dump(llvm::errs()); }
160#endif
161
162 bool operator==(const Symbol &O) const;
163
164 bool operator!=(const Symbol &O) const { return !(*this == O); }
165
166 bool operator<(const Symbol &O) const {
167 return std::tie(Kind, Name) < std::tie(O.Kind, O.Name);
168 }
169
170private:
171 StringRef Name;
172 TargetList Targets;
173 EncodeKind Kind;
174 SymbolFlags Flags;
175};
176
177/// Lightweight struct for passing around symbol information.
182
183 bool operator<(const SimpleSymbol &O) const {
184 return std::tie(Name, Kind, ObjCInterfaceType) <
185 std::tie(O.Name, O.Kind, O.ObjCInterfaceType);
186 }
187};
188
189/// Get symbol classification by parsing the name of a symbol.
190///
191/// \param SymName The name of symbol.
192SimpleSymbol parseSymbol(StringRef SymName);
193
194} // end namespace MachO.
195} // end namespace llvm.
196
197#endif // LLVM_TEXTAPI_SYMBOL_H
raw_pwrite_stream & OS
Value * RHS
Value * LHS
bool contains(ArchitectureSet Archs) const
void dump() const
Definition: Symbol.h:159
bool isData() const
Definition: Symbol.h:130
void addTarget(Target InputTarget)
Definition: Symbol.h:101
SymbolFlags getFlags() const
Definition: Symbol.h:107
bool isWeakDefined() const
Definition: Symbol.h:109
bool hasArchitecture(Architecture Arch) const
Definition: Symbol.h:138
bool isUndefined() const
Definition: Symbol.h:122
TargetList::const_iterator const_target_iterator
Definition: Symbol.h:146
bool operator<(const Symbol &O) const
Definition: Symbol.h:166
const_target_range targets() const
Definition: Symbol.h:148
bool operator==(const Symbol &O) const
Definition: Symbol.cpp:57
bool isThreadLocalValue() const
Definition: Symbol.h:117
bool operator!=(const Symbol &O) const
Definition: Symbol.h:164
ArchitectureSet getArchitectures() const
Definition: Symbol.h:104
Symbol(EncodeKind Kind, StringRef Name, TargetList Targets, SymbolFlags Flags)
Definition: Symbol.h:98
StringRef getName() const
Definition: Symbol.h:103
bool hasTarget(const Target &Targ) const
Definition: Symbol.h:142
bool isText() const
Definition: Symbol.h:134
EncodeKind getKind() const
Definition: Symbol.h:102
bool isWeakReferenced() const
Definition: Symbol.h:113
bool isReexported() const
Definition: Symbol.h:126
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition: StringRef.h:849
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Specialization of filter_iterator_base for forward iteration only.
Definition: STLExtras.h:506
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
@ LLVM_MARK_AS_BITMASK_ENUM
Definition: FileTypes.h:45
constexpr StringLiteral ObjC2IVarPrefix
Definition: Symbol.h:66
constexpr StringLiteral ObjC1ClassNamePrefix
Definition: Symbol.h:62
C::iterator addEntry(C &Container, StringRef InstallName)
constexpr StringLiteral ObjC2ClassNamePrefix
Definition: Symbol.h:63
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
Definition: Architecture.h:27
ObjCIFSymbolKind
ObjC Interface symbol mappings.
Definition: Symbol.h:69
@ EHType
Is OBJC_EHTYPE* symbol.
@ Class
Is OBJC_CLASS* symbol.
@ MetaClass
Is OBJC_METACLASS* symbol.
EncodeKind
Mapping of entry types in TextStubs.
Definition: Symbol.h:55
SimpleSymbol parseSymbol(StringRef SymName)
Get symbol classification by parsing the name of a symbol.
Definition: Symbol.cpp:75
constexpr StringLiteral ObjC2MetaClassNamePrefix
Definition: Symbol.h:64
SymbolFlags
Symbol flags.
Definition: Symbol.h:24
@ ThreadLocalValue
Thread-local value symbol.
@ WeakReferenced
Weak referenced symbol.
@ WeakDefined
Weak defined symbol.
ArchitectureSet mapToArchitectureSet(ArrayRef< Target > Targets)
Definition: Target.cpp:69
constexpr StringLiteral ObjC2EHTypePrefix
Definition: Symbol.h:65
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1950
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:1858
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1888
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
Lightweight struct for passing around symbol information.
Definition: Symbol.h:178
bool operator<(const SimpleSymbol &O) const
Definition: Symbol.h:183
ObjCIFSymbolKind ObjCInterfaceType
Definition: Symbol.h:181