Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
SymbolicFile.h
Go to the documentation of this file.
1//===- SymbolicFile.h - Interface that only provides symbols ----*- 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// This file declares the SymbolicFile interface.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_OBJECT_SYMBOLICFILE_H
14#define LLVM_OBJECT_SYMBOLICFILE_H
15
16#include "llvm/ADT/iterator_range.h"
17#include "llvm/BinaryFormat/Magic.h"
18#include "llvm/Object/Binary.h"
19#include "llvm/Support/Error.h"
20#include "llvm/Support/Format.h"
21#include "llvm/Support/MemoryBufferRef.h"
22#include <cinttypes>
23#include <cstdint>
24#include <cstring>
25#include <iterator>
26#include <memory>
27
28namespacellvm {
29
30classLLVMContext;
31classraw_ostream;
32
33namespaceobject {
34
35unionDataRefImpl {
36// This entire union should probably be a
37// char[max(8, sizeof(uintptr_t))] and require the impl to cast.
38struct{
39uint32_ta,b;
40 }d;
41 uintptr_tp;
42
43DataRefImpl() { std::memset(this, 0,sizeof(DataRefImpl)); }
44};
45
46template <typename OStream>
47OStream&operator<<(OStream &OS,constDataRefImpl &D) {
48OS <<"(" <<format("0x%08" PRIxPTR,D.p) <<" (" <<format("0x%08x",D.d.a)
49 <<", " <<format("0x%08x",D.d.b) <<"))";
50returnOS;
51}
52
53inlinebooloperator==(constDataRefImpl &a,constDataRefImpl &b) {
54// Check bitwise identical. This is the only legal way to compare a union w/o
55// knowing which member is in use.
56return std::memcmp(&a, &b,sizeof(DataRefImpl)) == 0;
57}
58
59inlinebooloperator!=(constDataRefImpl &a,constDataRefImpl &b) {
60return !operator==(a, b);
61}
62
63inlinebooloperator<(constDataRefImpl &a,constDataRefImpl &b) {
64// Check bitwise identical. This is the only legal way to compare a union w/o
65// knowing which member is in use.
66return std::memcmp(&a, &b,sizeof(DataRefImpl)) < 0;
67}
68
69template <class content_type>classcontent_iterator {
70 content_type Current;
71
72public:
73usingiterator_category = std::forward_iterator_tag;
74usingvalue_type =const content_type;
75usingdifference_type = std::ptrdiff_t;
76usingpointer =value_type *;
77usingreference =value_type &;
78
79content_iterator(content_type symb) : Current(std::move(symb)) {}
80
81const content_type *operator->() const{return &Current; }
82
83const content_type &operator*() const{return Current; }
84
85booloperator==(constcontent_iterator &other) const{
86return Current == other.Current;
87 }
88
89booloperator!=(constcontent_iterator &other) const{
90return !(*this == other);
91 }
92
93content_iterator &operator++() {// preincrement
94 Current.moveNext();
95return *this;
96 }
97};
98
99classSymbolicFile;
100
101/// This is a value type class that represents a single symbol in the list of
102/// symbols in the object file.
103classBasicSymbolRef {
104DataRefImpl SymbolPimpl;
105constSymbolicFile *OwningObject =nullptr;
106
107public:
108enumFlags :unsigned {
109SF_None = 0,
110SF_Undefined = 1U << 0,// Symbol is defined in another object file
111SF_Global = 1U << 1,// Global symbol
112SF_Weak = 1U << 2,// Weak symbol
113SF_Absolute = 1U << 3,// Absolute symbol
114SF_Common = 1U << 4,// Symbol has common linkage
115SF_Indirect = 1U << 5,// Symbol is an alias to another symbol
116SF_Exported = 1U << 6,// Symbol is visible to other DSOs
117SF_FormatSpecific = 1U << 7,// Specific to the object file format
118// (e.g. section symbols)
119SF_Thumb = 1U << 8,// Thumb symbol in a 32-bit ARM binary
120SF_Hidden = 1U << 9,// Symbol has hidden visibility
121SF_Const = 1U << 10,// Symbol value is constant
122SF_Executable = 1U << 11,// Symbol points to an executable section
123// (IR only)
124 };
125
126BasicSymbolRef() =default;
127BasicSymbolRef(DataRefImpl SymbolP,constSymbolicFile *Owner);
128
129booloperator==(constBasicSymbolRef &Other)const;
130booloperator<(constBasicSymbolRef &Other)const;
131
132voidmoveNext();
133
134ErrorprintName(raw_ostream &OS)const;
135
136 /// Get symbol flags (bitwise OR of SymbolRef::Flags)
137Expected<uint32_t>getFlags()const;
138
139DataRefImplgetRawDataRefImpl()const;
140constSymbolicFile *getObject()const;
141};
142
143usingbasic_symbol_iterator =content_iterator<BasicSymbolRef>;
144
145classSymbolicFile :publicBinary {
146public:
147SymbolicFile(unsignedintType,MemoryBufferRef Source);
148~SymbolicFile()override;
149
150// virtual interface.
151virtualvoidmoveSymbolNext(DataRefImpl &Symb)const = 0;
152
153virtualErrorprintSymbolName(raw_ostream &OS,DataRefImpl Symb)const = 0;
154
155virtualExpected<uint32_t>getSymbolFlags(DataRefImpl Symb)const = 0;
156
157virtualbasic_symbol_iteratorsymbol_begin()const = 0;
158
159virtualbasic_symbol_iteratorsymbol_end()const = 0;
160
161virtualboolis64Bit()const = 0;
162
163// convenience wrappers.
164usingbasic_symbol_iterator_range =iterator_range<basic_symbol_iterator>;
165basic_symbol_iterator_rangesymbols() const{
166returnbasic_symbol_iterator_range(symbol_begin(),symbol_end());
167 }
168
169// construction aux.
170staticExpected<std::unique_ptr<SymbolicFile>>
171createSymbolicFile(MemoryBufferRef Object,llvm::file_magicType,
172LLVMContext *Context,bool InitContent =true);
173
174staticExpected<std::unique_ptr<SymbolicFile>>
175createSymbolicFile(MemoryBufferRef Object) {
176returncreateSymbolicFile(Object,llvm::file_magic::unknown,nullptr);
177 }
178
179staticboolclassof(constBinary *v) {
180return v->isSymbolic();
181 }
182
183staticboolisSymbolicFile(file_magicType,constLLVMContext *Context);
184};
185
186inlineBasicSymbolRef::BasicSymbolRef(DataRefImpl SymbolP,
187constSymbolicFile *Owner)
188 : SymbolPimpl(SymbolP), OwningObject(Owner) {}
189
190inlineboolBasicSymbolRef::operator==(constBasicSymbolRef &Other) const{
191return SymbolPimpl ==Other.SymbolPimpl;
192}
193
194inlineboolBasicSymbolRef::operator<(constBasicSymbolRef &Other) const{
195return SymbolPimpl <Other.SymbolPimpl;
196}
197
198inlinevoidBasicSymbolRef::moveNext() {
199return OwningObject->moveSymbolNext(SymbolPimpl);
200}
201
202inlineErrorBasicSymbolRef::printName(raw_ostream &OS) const{
203return OwningObject->printSymbolName(OS, SymbolPimpl);
204}
205
206inlineExpected<uint32_t>BasicSymbolRef::getFlags() const{
207return OwningObject->getSymbolFlags(SymbolPimpl);
208}
209
210inlineDataRefImplBasicSymbolRef::getRawDataRefImpl() const{
211return SymbolPimpl;
212}
213
214inlineconstSymbolicFile *BasicSymbolRef::getObject() const{
215return OwningObject;
216}
217
218}// end namespace object
219}// end namespace llvm
220
221#endif// LLVM_OBJECT_SYMBOLICFILE_H
Binary.h
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Format.h
Magic.h
MemoryBufferRef.h
OS
raw_pwrite_stream & OS
Definition:SampleProfWriter.cpp:51
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::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition:LLVMContext.h:67
llvm::MemoryBufferRef
Definition:MemoryBufferRef.h:22
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition:Type.h:45
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition:iterator_range.h:42
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::getFlags
Expected< uint32_t > getFlags() const
Get symbol flags (bitwise OR of SymbolRef::Flags)
Definition:SymbolicFile.h:206
llvm::object::BasicSymbolRef::getObject
const SymbolicFile * getObject() const
Definition:SymbolicFile.h:214
llvm::object::BasicSymbolRef::getRawDataRefImpl
DataRefImpl getRawDataRefImpl() const
Definition:SymbolicFile.h:210
llvm::object::BasicSymbolRef::Flags
Flags
Definition:SymbolicFile.h:108
llvm::object::BasicSymbolRef::SF_Global
@ SF_Global
Definition:SymbolicFile.h:111
llvm::object::BasicSymbolRef::SF_Hidden
@ SF_Hidden
Definition:SymbolicFile.h:120
llvm::object::BasicSymbolRef::SF_Executable
@ SF_Executable
Definition:SymbolicFile.h:122
llvm::object::BasicSymbolRef::SF_Exported
@ SF_Exported
Definition:SymbolicFile.h:116
llvm::object::BasicSymbolRef::SF_Thumb
@ SF_Thumb
Definition:SymbolicFile.h:119
llvm::object::BasicSymbolRef::SF_Common
@ SF_Common
Definition:SymbolicFile.h:114
llvm::object::BasicSymbolRef::SF_Indirect
@ SF_Indirect
Definition:SymbolicFile.h:115
llvm::object::BasicSymbolRef::SF_FormatSpecific
@ SF_FormatSpecific
Definition:SymbolicFile.h:117
llvm::object::BasicSymbolRef::SF_Weak
@ SF_Weak
Definition:SymbolicFile.h:112
llvm::object::BasicSymbolRef::SF_Absolute
@ SF_Absolute
Definition:SymbolicFile.h:113
llvm::object::BasicSymbolRef::SF_Undefined
@ SF_Undefined
Definition:SymbolicFile.h:110
llvm::object::BasicSymbolRef::SF_None
@ SF_None
Definition:SymbolicFile.h:109
llvm::object::BasicSymbolRef::SF_Const
@ SF_Const
Definition:SymbolicFile.h:121
llvm::object::BasicSymbolRef::operator==
bool operator==(const BasicSymbolRef &Other) const
Definition:SymbolicFile.h:190
llvm::object::BasicSymbolRef::BasicSymbolRef
BasicSymbolRef()=default
llvm::object::BasicSymbolRef::printName
Error printName(raw_ostream &OS) const
Definition:SymbolicFile.h:202
llvm::object::BasicSymbolRef::operator<
bool operator<(const BasicSymbolRef &Other) const
Definition:SymbolicFile.h:194
llvm::object::BasicSymbolRef::moveNext
void moveNext()
Definition:SymbolicFile.h:198
llvm::object::Binary
Definition:Binary.h:32
llvm::object::SymbolicFile
Definition:SymbolicFile.h:145
llvm::object::SymbolicFile::classof
static bool classof(const Binary *v)
Definition:SymbolicFile.h:179
llvm::object::SymbolicFile::symbol_begin
virtual basic_symbol_iterator symbol_begin() const =0
llvm::object::SymbolicFile::basic_symbol_iterator_range
iterator_range< basic_symbol_iterator > basic_symbol_iterator_range
Definition:SymbolicFile.h:164
llvm::object::SymbolicFile::createSymbolicFile
static Expected< std::unique_ptr< SymbolicFile > > createSymbolicFile(MemoryBufferRef Object, llvm::file_magic Type, LLVMContext *Context, bool InitContent=true)
Definition:SymbolicFile.cpp:37
llvm::object::SymbolicFile::is64Bit
virtual bool is64Bit() const =0
llvm::object::SymbolicFile::symbol_end
virtual basic_symbol_iterator symbol_end() const =0
llvm::object::SymbolicFile::~SymbolicFile
~SymbolicFile() override
llvm::object::SymbolicFile::createSymbolicFile
static Expected< std::unique_ptr< SymbolicFile > > createSymbolicFile(MemoryBufferRef Object)
Definition:SymbolicFile.h:175
llvm::object::SymbolicFile::printSymbolName
virtual Error printSymbolName(raw_ostream &OS, DataRefImpl Symb) const =0
llvm::object::SymbolicFile::getSymbolFlags
virtual Expected< uint32_t > getSymbolFlags(DataRefImpl Symb) const =0
llvm::object::SymbolicFile::symbols
basic_symbol_iterator_range symbols() const
Definition:SymbolicFile.h:165
llvm::object::SymbolicFile::isSymbolicFile
static bool isSymbolicFile(file_magic Type, const LLVMContext *Context)
Definition:SymbolicFile.cpp:98
llvm::object::SymbolicFile::moveSymbolNext
virtual void moveSymbolNext(DataRefImpl &Symb) const =0
llvm::object::content_iterator
Definition:SymbolicFile.h:69
llvm::object::content_iterator::operator*
const content_type & operator*() const
Definition:SymbolicFile.h:83
llvm::object::content_iterator::operator->
const content_type * operator->() const
Definition:SymbolicFile.h:81
llvm::object::content_iterator::iterator_category
std::forward_iterator_tag iterator_category
Definition:SymbolicFile.h:73
llvm::object::content_iterator::operator==
bool operator==(const content_iterator &other) const
Definition:SymbolicFile.h:85
llvm::object::content_iterator::operator++
content_iterator & operator++()
Definition:SymbolicFile.h:93
llvm::object::content_iterator::operator!=
bool operator!=(const content_iterator &other) const
Definition:SymbolicFile.h:89
llvm::object::content_iterator::reference
value_type & reference
Definition:SymbolicFile.h:77
llvm::object::content_iterator::value_type
const content_type value_type
Definition:SymbolicFile.h:74
llvm::object::content_iterator::difference_type
std::ptrdiff_t difference_type
Definition:SymbolicFile.h:75
llvm::object::content_iterator::content_iterator
content_iterator(content_type symb)
Definition:SymbolicFile.h:79
llvm::object::content_iterator::pointer
value_type * pointer
Definition:SymbolicFile.h:76
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition:raw_ostream.h:52
uint32_t
iterator_range.h
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
Error.h
llvm::object::operator<
bool operator<(const ELFSymbolRef &A, const ELFSymbolRef &B)
Definition:ELFObjectFile.h:205
llvm::object::operator!=
bool operator!=(const DataRefImpl &a, const DataRefImpl &b)
Definition:SymbolicFile.h:59
llvm::object::operator<<
raw_ostream & operator<<(raw_ostream &OS, const SectionedAddress &Addr)
Definition:ObjectFile.cpp:34
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::operator==
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
Definition:AddressRanges.h:153
llvm::format
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition:Format.h:125
llvm::IRMemLocation::Other
@ Other
Any other memory.
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:1873
std
Implement std::hash so that hash_code can be used in STL containers.
Definition:BitVector.h:858
llvm::file_magic
file_magic - An "enum class" enumeration of file types based on magic (the first N bytes of the file)...
Definition:Magic.h:20
llvm::file_magic::unknown
@ unknown
Unrecognized file.
Definition:Magic.h:22
llvm::object::DataRefImpl
Definition:SymbolicFile.h:35
llvm::object::DataRefImpl::b
uint32_t b
Definition:SymbolicFile.h:39
llvm::object::DataRefImpl::p
uintptr_t p
Definition:SymbolicFile.h:41
llvm::object::DataRefImpl::d
struct llvm::object::DataRefImpl::@370 d
llvm::object::DataRefImpl::a
uint32_t a
Definition:SymbolicFile.h:39
llvm::object::DataRefImpl::DataRefImpl
DataRefImpl()
Definition:SymbolicFile.h:43

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

©2009-2025 Movatter.jp