LLVM 22.0.0git
JITLink.h
Go to the documentation of this file.
1//===------------ JITLink.h - JIT linker functionality ----------*- 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// Contains generic JIT-linker types.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_EXECUTIONENGINE_JITLINK_JITLINK_H
14#define LLVM_EXECUTIONENGINE_JITLINK_JITLINK_H
15
16#include "llvm/ADT/DenseMap.h"
17#include "llvm/ADT/DenseSet.h"
19#include "llvm/ADT/STLExtras.h"
31#include "llvm/Support/Endian.h"
32#include "llvm/Support/Error.h"
38#include <optional>
39
40#include <map>
41#include <string>
42#include <system_error>
43
44namespace llvm {
45namespace jitlink {
46
47class LinkGraph;
48class Symbol;
49class Section;
50
51/// Base class for errors originating in JIT linker, e.g. missing relocation
52/// support.
53class LLVM_ABI JITLinkError : public ErrorInfo<JITLinkError> {
54public:
55 static char ID;
56
57 JITLinkError(Twine ErrMsg) : ErrMsg(ErrMsg.str()) {}
58
59 void log(raw_ostream &OS) const override;
60 const std::string &getErrorMessage() const { return ErrMsg; }
61 std::error_code convertToErrorCode() const override;
62
63private:
64 std::string ErrMsg;
65};
66
67/// Represents fixups and constraints in the LinkGraph.
68class Edge {
69public:
70 using Kind = uint8_t;
71
73 Invalid, // Invalid edge value.
74 FirstKeepAlive, // Keeps target alive. Offset/addend zero.
75 KeepAlive = FirstKeepAlive, // Tag first edge kind that preserves liveness.
76 FirstRelocation // First architecture specific relocation.
77 };
78
80 using AddendT = int64_t;
81
82 Edge(Kind K, OffsetT Offset, Symbol &Target, AddendT Addend)
83 : Target(&Target), Offset(Offset), Addend(Addend), K(K) {}
84
85 OffsetT getOffset() const { return Offset; }
86 void setOffset(OffsetT Offset) { this->Offset = Offset; }
87 Kind getKind() const { return K; }
88 void setKind(Kind K) { this->K = K; }
89 bool isRelocation() const { return K >= FirstRelocation; }
91 assert(isRelocation() && "Not a relocation edge");
92 return K - FirstRelocation;
93 }
94 bool isKeepAlive() const { return K >= FirstKeepAlive; }
95 Symbol &getTarget() const { return *Target; }
96 void setTarget(Symbol &Target) { this->Target = &Target; }
97 AddendT getAddend() const { return Addend; }
98 void setAddend(AddendT Addend) { this->Addend = Addend; }
99
100private:
101 Symbol *Target = nullptr;
102 OffsetT Offset = 0;
103 AddendT Addend = 0;
104 Kind K = 0;
105};
106
107/// Returns the string name of the given generic edge kind, or "unknown"
108/// otherwise. Useful for debugging.
109LLVM_ABI const char *getGenericEdgeKindName(Edge::Kind K);
110
111/// Base class for Addressable entities (externals, absolutes, blocks).
113 friend class LinkGraph;
114
115protected:
116 Addressable(orc::ExecutorAddr Address, bool IsDefined)
117 : Address(Address), IsDefined(IsDefined), IsAbsolute(false) {}
118
120 : Address(Address), IsDefined(false), IsAbsolute(true) {
121 assert(!(IsDefined && IsAbsolute) &&
122 "Block cannot be both defined and absolute");
123 }
124
125public:
126 Addressable(const Addressable &) = delete;
127 Addressable &operator=(const Addressable &) = default;
130
131 orc::ExecutorAddr getAddress() const { return Address; }
132 void setAddress(orc::ExecutorAddr Address) { this->Address = Address; }
133
134 /// Returns true if this is a defined addressable, in which case you
135 /// can downcast this to a Block.
136 bool isDefined() const { return static_cast<bool>(IsDefined); }
137 bool isAbsolute() const { return static_cast<bool>(IsAbsolute); }
138
139private:
140 void setAbsolute(bool IsAbsolute) {
141 assert(!IsDefined && "Cannot change the Absolute flag on a defined block");
142 this->IsAbsolute = IsAbsolute;
143 }
144
145 orc::ExecutorAddr Address;
146 uint64_t IsDefined : 1;
147 uint64_t IsAbsolute : 1;
148
149protected:
150 // bitfields for Block, allocated here to improve packing.
154};
155
157
158/// An Addressable with content and edges.
159class Block : public Addressable {
160 friend class LinkGraph;
161
162private:
163 /// Create a zero-fill defined addressable.
166 : Addressable(Address, true), Parent(&Parent), Size(Size) {
167 assert(isPowerOf2_64(Alignment) && "Alignment must be power of 2");
168 assert(AlignmentOffset < Alignment &&
169 "Alignment offset cannot exceed alignment");
170 assert(AlignmentOffset <= MaxAlignmentOffset &&
171 "Alignment offset exceeds maximum");
172 ContentMutable = false;
173 P2Align = Alignment ? llvm::countr_zero(Alignment) : 0;
174 this->AlignmentOffset = AlignmentOffset;
175 }
176
177 /// Create a defined addressable for the given content.
178 /// The Content is assumed to be non-writable, and will be copied when
179 /// mutations are required.
182 : Addressable(Address, true), Parent(&Parent), Data(Content.data()),
183 Size(Content.size()) {
184 assert(isPowerOf2_64(Alignment) && "Alignment must be power of 2");
185 assert(AlignmentOffset < Alignment &&
186 "Alignment offset cannot exceed alignment");
187 assert(AlignmentOffset <= MaxAlignmentOffset &&
188 "Alignment offset exceeds maximum");
189 ContentMutable = false;
190 P2Align = Alignment ? llvm::countr_zero(Alignment) : 0;
191 this->AlignmentOffset = AlignmentOffset;
192 }
193
194 /// Create a defined addressable for the given content.
195 /// The content is assumed to be writable, and the caller is responsible
196 /// for ensuring that it lives for the duration of the Block's lifetime.
197 /// The standard way to achieve this is to allocate it on the Graph's
198 /// allocator.
199 Block(Section &Parent, MutableArrayRef<char> Content,
201 : Addressable(Address, true), Parent(&Parent), Data(Content.data()),
202 Size(Content.size()) {
203 assert(isPowerOf2_64(Alignment) && "Alignment must be power of 2");
204 assert(AlignmentOffset < Alignment &&
205 "Alignment offset cannot exceed alignment");
206 assert(AlignmentOffset <= MaxAlignmentOffset &&
207 "Alignment offset exceeds maximum");
208 ContentMutable = true;
209 P2Align = Alignment ? llvm::countr_zero(Alignment) : 0;
210 this->AlignmentOffset = AlignmentOffset;
211 }
212
213public:
214 using EdgeVector = std::vector<Edge>;
215 using edge_iterator = EdgeVector::iterator;
216 using const_edge_iterator = EdgeVector::const_iterator;
217
218 Block(const Block &) = delete;
219 Block &operator=(const Block &) = delete;
220 Block(Block &&) = delete;
221 Block &operator=(Block &&) = delete;
222
223 /// Return the parent section for this block.
224 Section &getSection() const { return *Parent; }
225
226 /// Returns true if this is a zero-fill block.
227 ///
228 /// If true, getSize is callable but getContent is not (the content is
229 /// defined to be a sequence of zero bytes of length Size).
230 bool isZeroFill() const { return !Data; }
231
232 /// Returns the size of this defined addressable.
233 size_t getSize() const { return Size; }
234
235 /// Turns this block into a zero-fill block of the given size.
236 void setZeroFillSize(size_t Size) {
237 Data = nullptr;
238 this->Size = Size;
239 }
240
241 /// Returns the address range of this defined addressable.
244 }
245
246 /// Get the content for this block. Block must not be a zero-fill block.
248 assert(Data && "Block does not contain content");
249 return ArrayRef<char>(Data, Size);
250 }
251
252 /// Set the content for this block.
253 /// Caller is responsible for ensuring the underlying bytes are not
254 /// deallocated while pointed to by this block.
256 assert(Content.data() && "Setting null content");
257 Data = Content.data();
258 Size = Content.size();
259 ContentMutable = false;
260 }
261
262 /// Get mutable content for this block.
263 ///
264 /// If this Block's content is not already mutable this will trigger a copy
265 /// of the existing immutable content to a new, mutable buffer allocated using
266 /// LinkGraph::allocateContent.
268
269 /// Get mutable content for this block.
270 ///
271 /// This block's content must already be mutable. It is a programmatic error
272 /// to call this on a block with immutable content -- consider using
273 /// getMutableContent instead.
275 assert(Data && "Block does not contain content");
276 assert(ContentMutable && "Content is not mutable");
277 return MutableArrayRef<char>(const_cast<char *>(Data), Size);
278 }
279
280 /// Set mutable content for this block.
281 ///
282 /// The caller is responsible for ensuring that the memory pointed to by
283 /// MutableContent is not deallocated while pointed to by this block.
285 assert(MutableContent.data() && "Setting null content");
286 Data = MutableContent.data();
287 Size = MutableContent.size();
288 ContentMutable = true;
289 }
290
291 /// Returns true if this block's content is mutable.
292 ///
293 /// This is primarily useful for asserting that a block is already in a
294 /// mutable state prior to modifying the content. E.g. when applying
295 /// fixups we expect the block to already be mutable as it should have been
296 /// copied to working memory.
297 bool isContentMutable() const { return ContentMutable; }
298
299 /// Get the alignment for this content.
300 uint64_t getAlignment() const { return 1ull << P2Align; }
301
302 /// Set the alignment for this content.
303 void setAlignment(uint64_t Alignment) {
304 assert(isPowerOf2_64(Alignment) && "Alignment must be a power of two");
305 P2Align = Alignment ? llvm::countr_zero(Alignment) : 0;
306 }
307
308 /// Get the alignment offset for this content.
310
311 /// Set the alignment offset for this content.
313 assert(AlignmentOffset < (1ull << P2Align) &&
314 "Alignment offset can't exceed alignment");
315 this->AlignmentOffset = AlignmentOffset;
316 }
317
318 /// Add an edge to this block.
319 void addEdge(Edge::Kind K, Edge::OffsetT Offset, Symbol &Target,
320 Edge::AddendT Addend) {
321 assert((K == Edge::KeepAlive || !isZeroFill()) &&
322 "Adding edge to zero-fill block?");
323 Edges.push_back(Edge(K, Offset, Target, Addend));
324 }
325
326 /// Add an edge by copying an existing one. This is typically used when
327 /// moving edges between blocks.
328 void addEdge(const Edge &E) { Edges.push_back(E); }
329
330 /// Return the list of edges attached to this content.
332 return make_range(Edges.begin(), Edges.end());
333 }
334
335 /// Returns the list of edges attached to this content.
337 return make_range(Edges.begin(), Edges.end());
338 }
339
340 /// Returns an iterator over all edges at the given offset within the block.
341 auto edges_at(Edge::OffsetT O) {
342 return make_filter_range(edges(),
343 [O](const Edge &E) { return E.getOffset() == O; });
344 }
345
346 /// Returns an iterator over all edges at the given offset within the block.
347 auto edges_at(Edge::OffsetT O) const {
348 return make_filter_range(edges(),
349 [O](const Edge &E) { return E.getOffset() == O; });
350 }
351
352 /// Return the size of the edges list.
353 size_t edges_size() const { return Edges.size(); }
354
355 /// Returns true if the list of edges is empty.
356 bool edges_empty() const { return Edges.empty(); }
357
358 /// Remove the edge pointed to by the given iterator.
359 /// Returns an iterator to the new next element.
360 edge_iterator removeEdge(edge_iterator I) { return Edges.erase(I); }
361
362 /// Returns the address of the fixup for the given edge, which is equal to
363 /// this block's address plus the edge's offset.
365 return getAddress() + E.getOffset();
366 }
367
368private:
369 static constexpr uint64_t MaxAlignmentOffset = (1ULL << 56) - 1;
370
371 void setSection(Section &Parent) { this->Parent = &Parent; }
372
373 Section *Parent;
374 const char *Data = nullptr;
375 size_t Size = 0;
376 std::vector<Edge> Edges;
377};
378
379// Align an address to conform with block alignment requirements.
381 uint64_t Delta = (B.getAlignmentOffset() - Addr) % B.getAlignment();
382 return Addr + Delta;
383}
384
385// Align a orc::ExecutorAddr to conform with block alignment requirements.
387 return orc::ExecutorAddr(alignToBlock(Addr.getValue(), B));
388}
389
390// Returns true if the given blocks contains exactly one valid c-string.
391// Zero-fill blocks of size 1 count as valid empty strings. Content blocks
392// must end with a zero, and contain no zeros before the end.
393LLVM_ABI bool isCStringBlock(Block &B);
394
395/// Describes symbol linkage. This can be used to resolve definition clashes.
396enum class Linkage : uint8_t {
397 Strong,
398 Weak,
399};
400
401/// Holds target-specific properties for a symbol.
403
404/// For errors and debugging output.
405LLVM_ABI const char *getLinkageName(Linkage L);
406
407/// Defines the scope in which this symbol should be visible:
408/// Default -- Visible in the public interface of the linkage unit.
409/// Hidden -- Visible within the linkage unit, but not exported from it.
410/// SideEffectsOnly -- Like hidden, but symbol can only be looked up once
411/// to trigger materialization of the containing graph.
412/// Local -- Visible only within the LinkGraph.
414
415/// For debugging output.
416LLVM_ABI const char *getScopeName(Scope S);
417
419
420/// Symbol representation.
421///
422/// Symbols represent locations within Addressable objects.
423/// They can be either Named or Anonymous.
424/// Anonymous symbols have neither linkage nor visibility, and must point at
425/// ContentBlocks.
426/// Named symbols may be in one of four states:
427/// - Null: Default initialized. Assignable, but otherwise unusable.
428/// - Defined: Has both linkage and visibility and points to a ContentBlock
429/// - Common: Has both linkage and visibility, points to a null Addressable.
430/// - External: Has neither linkage nor visibility, points to an external
431/// Addressable.
432///
433class Symbol {
434 friend class LinkGraph;
435
436private:
439 Scope S, bool IsLive, bool IsCallable)
440 : Name(std::move(Name)), Base(&Base), Offset(Offset), WeakRef(0),
441 Size(Size) {
442 assert(Offset <= MaxOffset && "Offset out of range");
443 setLinkage(L);
444 setScope(S);
445 setLive(IsLive);
446 setCallable(IsCallable);
448 }
449
450 static Symbol &constructExternal(BumpPtrAllocator &Allocator,
451 Addressable &Base,
454 bool WeaklyReferenced) {
455 assert(!Base.isDefined() &&
456 "Cannot create external symbol from defined block");
457 assert(Name && "External symbol name cannot be empty");
458 auto *Sym = Allocator.Allocate<Symbol>();
459 new (Sym)
460 Symbol(Base, 0, std::move(Name), Size, L, Scope::Default, false, false);
461 Sym->setWeaklyReferenced(WeaklyReferenced);
462 return *Sym;
463 }
464
465 static Symbol &constructAbsolute(BumpPtrAllocator &Allocator,
466 Addressable &Base,
467 orc::SymbolStringPtr &&Name,
469 Scope S, bool IsLive) {
470 assert(!Base.isDefined() &&
471 "Cannot create absolute symbol from a defined block");
472 auto *Sym = Allocator.Allocate<Symbol>();
473 new (Sym) Symbol(Base, 0, std::move(Name), Size, L, S, IsLive, false);
474 return *Sym;
475 }
476
477 static Symbol &constructAnonDef(BumpPtrAllocator &Allocator, Block &Base,
479 orc::ExecutorAddrDiff Size, bool IsCallable,
480 bool IsLive) {
481 assert((Offset + Size) <= Base.getSize() &&
482 "Symbol extends past end of block");
483 auto *Sym = Allocator.Allocate<Symbol>();
484 new (Sym) Symbol(Base, Offset, nullptr, Size, Linkage::Strong, Scope::Local,
485 IsLive, IsCallable);
486 return *Sym;
487 }
488
489 static Symbol &constructNamedDef(BumpPtrAllocator &Allocator, Block &Base,
491 orc::SymbolStringPtr Name,
493 Scope S, bool IsLive, bool IsCallable) {
494 assert((Offset + Size) <= Base.getSize() &&
495 "Symbol extends past end of block");
496 assert(Name && "Name cannot be empty");
497 auto *Sym = Allocator.Allocate<Symbol>();
498 new (Sym)
499 Symbol(Base, Offset, std::move(Name), Size, L, S, IsLive, IsCallable);
500 return *Sym;
501 }
502
503public:
504 /// Create a null Symbol. This allows Symbols to be default initialized for
505 /// use in containers (e.g. as map values). Null symbols are only useful for
506 /// assigning to.
507 Symbol() = default;
508
509 // Symbols are not movable or copyable.
510 Symbol(const Symbol &) = delete;
511 Symbol &operator=(const Symbol &) = delete;
512 Symbol(Symbol &&) = delete;
513 Symbol &operator=(Symbol &&) = delete;
514
515 /// Returns true if this symbol has a name.
516 bool hasName() const { return Name != nullptr; }
517
518 /// Returns the name of this symbol (empty if the symbol is anonymous).
520 assert((hasName() || getScope() == Scope::Local) &&
521 "Anonymous symbol has non-local scope");
522
523 return Name;
524 }
525
526 /// Rename this symbol. The client is responsible for updating scope and
527 /// linkage if this name-change requires it.
528 void setName(const orc::SymbolStringPtr Name) { this->Name = Name; }
529
530 /// Returns true if this Symbol has content (potentially) defined within this
531 /// object file (i.e. is anything but an external or absolute symbol).
532 bool isDefined() const {
533 assert(Base && "Attempt to access null symbol");
534 return Base->isDefined();
535 }
536
537 /// Returns true if this symbol is live (i.e. should be treated as a root for
538 /// dead stripping).
539 bool isLive() const {
540 assert(Base && "Attempting to access null symbol");
541 return IsLive;
542 }
543
544 /// Set this symbol's live bit.
545 void setLive(bool IsLive) { this->IsLive = IsLive; }
546
547 /// Returns true is this symbol is callable.
548 bool isCallable() const { return IsCallable; }
549
550 /// Set this symbol's callable bit.
551 void setCallable(bool IsCallable) { this->IsCallable = IsCallable; }
552
553 /// Returns true if the underlying addressable is an unresolved external.
554 bool isExternal() const {
555 assert(Base && "Attempt to access null symbol");
556 return !Base->isDefined() && !Base->isAbsolute();
557 }
558
559 /// Returns true if the underlying addressable is an absolute symbol.
560 bool isAbsolute() const {
561 assert(Base && "Attempt to access null symbol");
562 return Base->isAbsolute();
563 }
564
565 /// Return the addressable that this symbol points to.
567 assert(Base && "Cannot get underlying addressable for null symbol");
568 return *Base;
569 }
570
571 /// Return the addressable that this symbol points to.
573 assert(Base && "Cannot get underlying addressable for null symbol");
574 return *Base;
575 }
576
577 /// Return the Block for this Symbol (Symbol must be defined).
579 assert(Base && "Cannot get block for null symbol");
580 assert(Base->isDefined() && "Not a defined symbol");
581 return static_cast<Block &>(*Base);
582 }
583
584 /// Return the Block for this Symbol (Symbol must be defined).
585 const Block &getBlock() const {
586 assert(Base && "Cannot get block for null symbol");
587 assert(Base->isDefined() && "Not a defined symbol");
588 return static_cast<const Block &>(*Base);
589 }
590
591 /// Return the Section for this Symbol (Symbol must be defined).
592 Section &getSection() const { return getBlock().getSection(); }
593
594 /// Returns the offset for this symbol within the underlying addressable.
596
598 assert(NewOffset <= getBlock().getSize() && "Offset out of range");
599 Offset = NewOffset;
600 }
601
602 /// Returns the address of this symbol.
603 orc::ExecutorAddr getAddress() const { return Base->getAddress() + Offset; }
604
605 /// Returns the size of this symbol.
607
608 /// Set the size of this symbol.
610 assert(Base && "Cannot set size for null Symbol");
611 assert((Size == 0 || Base->isDefined()) &&
612 "Non-zero size can only be set for defined symbols");
613 assert((Offset + Size <= static_cast<const Block &>(*Base).getSize()) &&
614 "Symbol size cannot extend past the end of its containing block");
615 this->Size = Size;
616 }
617
618 /// Returns the address range of this symbol.
621 }
622
623 /// Returns true if this symbol is backed by a zero-fill block.
624 /// This method may only be called on defined symbols.
625 bool isSymbolZeroFill() const { return getBlock().isZeroFill(); }
626
627 /// Returns the content in the underlying block covered by this symbol.
628 /// This method may only be called on defined non-zero-fill symbols.
630 return getBlock().getContent().slice(Offset, Size);
631 }
632
633 /// Get the linkage for this Symbol.
634 Linkage getLinkage() const { return static_cast<Linkage>(L); }
635
636 /// Set the linkage for this Symbol.
638 assert((L == Linkage::Strong || (!Base->isAbsolute() && Name)) &&
639 "Linkage can only be applied to defined named symbols");
640 this->L = static_cast<uint8_t>(L);
641 }
642
643 /// Get the visibility for this Symbol.
644 Scope getScope() const { return static_cast<Scope>(S); }
645
646 /// Set the visibility for this Symbol.
647 void setScope(Scope S) {
648 assert((hasName() || S == Scope::Local) &&
649 "Can not set anonymous symbol to non-local scope");
650 assert((S != Scope::Local || Base->isDefined() || Base->isAbsolute()) &&
651 "Invalid visibility for symbol type");
652 this->S = static_cast<uint8_t>(S);
653 }
654
655 /// Get the target flags of this Symbol.
656 TargetFlagsType getTargetFlags() const { return TargetFlags; }
657
658 /// Set the target flags for this Symbol.
660 assert(Flags <= 1 && "Add more bits to store more than single flag");
661 TargetFlags = Flags;
662 }
663
664 /// Returns true if this is a weakly referenced external symbol.
665 /// This method may only be called on external symbols.
666 bool isWeaklyReferenced() const {
667 assert(isExternal() && "isWeaklyReferenced called on non-external");
668 return WeakRef;
669 }
670
671 /// Set the WeaklyReferenced value for this symbol.
672 /// This method may only be called on external symbols.
673 void setWeaklyReferenced(bool WeakRef) {
674 assert(isExternal() && "setWeaklyReferenced called on non-external");
675 this->WeakRef = WeakRef;
676 }
677
678private:
679 void makeExternal(Addressable &A) {
680 assert(!A.isDefined() && !A.isAbsolute() &&
681 "Attempting to make external with defined or absolute block");
682 Base = &A;
683 Offset = 0;
685 IsLive = 0;
686 // note: Size, Linkage and IsCallable fields left unchanged.
687 }
688
689 void makeAbsolute(Addressable &A) {
690 assert(!A.isDefined() && A.isAbsolute() &&
691 "Attempting to make absolute with defined or external block");
692 Base = &A;
693 Offset = 0;
694 }
695
696 void setBlock(Block &B) { Base = &B; }
697
698 static constexpr uint64_t MaxOffset = (1ULL << 59) - 1;
699
700 orc::SymbolStringPtr Name = nullptr;
701 Addressable *Base = nullptr;
702 uint64_t Offset : 57;
703 uint64_t L : 1;
704 uint64_t S : 2;
705 uint64_t IsLive : 1;
706 uint64_t IsCallable : 1;
707 uint64_t WeakRef : 1;
708 uint64_t TargetFlags : 1;
709 size_t Size = 0;
710};
711
712LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const Symbol &A);
713
714LLVM_ABI void printEdge(raw_ostream &OS, const Block &B, const Edge &E,
715 StringRef EdgeKindName);
716
717/// Represents an object file section.
718class Section {
719 friend class LinkGraph;
720
721private:
723 : Name(Name), Prot(Prot), SecOrdinal(SecOrdinal) {}
724
725 using SymbolSet = DenseSet<Symbol *>;
727
728public:
731
734
736
737 // Sections are not movable or copyable.
738 Section(const Section &) = delete;
739 Section &operator=(const Section &) = delete;
740 Section(Section &&) = delete;
741 Section &operator=(Section &&) = delete;
742
743 /// Returns the name of this section.
744 StringRef getName() const { return Name; }
745
746 /// Returns the protection flags for this section.
747 orc::MemProt getMemProt() const { return Prot; }
748
749 /// Set the protection flags for this section.
750 void setMemProt(orc::MemProt Prot) { this->Prot = Prot; }
751
752 /// Get the memory lifetime policy for this section.
754
755 /// Set the memory lifetime policy for this section.
756 void setMemLifetime(orc::MemLifetime ML) { this->ML = ML; }
757
758 /// Returns the ordinal for this section.
759 SectionOrdinal getOrdinal() const { return SecOrdinal; }
760
761 /// Set the ordinal for this section. Ordinals are used to order the layout
762 /// of sections with the same permissions.
763 void setOrdinal(SectionOrdinal SecOrdinal) { this->SecOrdinal = SecOrdinal; }
764
765 /// Returns true if this section is empty (contains no blocks or symbols).
766 bool empty() const { return Blocks.empty(); }
767
768 /// Returns an iterator over the blocks defined in this section.
770 return make_range(Blocks.begin(), Blocks.end());
771 }
772
773 /// Returns an iterator over the blocks defined in this section.
775 return make_range(Blocks.begin(), Blocks.end());
776 }
777
778 /// Returns the number of blocks in this section.
779 BlockSet::size_type blocks_size() const { return Blocks.size(); }
780
781 /// Returns an iterator over the symbols defined in this section.
783 return make_range(Symbols.begin(), Symbols.end());
784 }
785
786 /// Returns an iterator over the symbols defined in this section.
788 return make_range(Symbols.begin(), Symbols.end());
789 }
790
791 /// Return the number of symbols in this section.
792 SymbolSet::size_type symbols_size() const { return Symbols.size(); }
793
794private:
795 void addSymbol(Symbol &Sym) {
796 assert(!Symbols.count(&Sym) && "Symbol is already in this section");
797 Symbols.insert(&Sym);
798 }
799
800 void removeSymbol(Symbol &Sym) {
801 assert(Symbols.count(&Sym) && "symbol is not in this section");
802 Symbols.erase(&Sym);
803 }
804
805 void addBlock(Block &B) {
806 assert(!Blocks.count(&B) && "Block is already in this section");
807 Blocks.insert(&B);
808 }
809
810 void removeBlock(Block &B) {
811 assert(Blocks.count(&B) && "Block is not in this section");
812 Blocks.erase(&B);
813 }
814
815 void transferContentTo(Section &DstSection) {
816 if (&DstSection == this)
817 return;
818 for (auto *S : Symbols)
819 DstSection.addSymbol(*S);
820 for (auto *B : Blocks)
821 DstSection.addBlock(*B);
822 Symbols.clear();
823 Blocks.clear();
824 }
825
826 StringRef Name;
827 orc::MemProt Prot;
829 SectionOrdinal SecOrdinal = 0;
831 SymbolSet Symbols;
832};
833
834/// Represents a section address range via a pair of Block pointers
835/// to the first and last Blocks in the section.
837public:
838 SectionRange() = default;
839 SectionRange(const Section &Sec) {
840 if (Sec.blocks().empty())
841 return;
842 First = Last = *Sec.blocks().begin();
843 for (auto *B : Sec.blocks()) {
844 if (B->getAddress() < First->getAddress())
845 First = B;
846 if (B->getAddress() > Last->getAddress())
847 Last = B;
848 }
849 }
851 assert((!Last || First) && "First can not be null if end is non-null");
852 return First;
853 }
855 assert((First || !Last) && "Last can not be null if start is non-null");
856 return Last;
857 }
858 bool empty() const {
859 assert((First || !Last) && "Last can not be null if start is non-null");
860 return !First;
861 }
863 return First ? First->getAddress() : orc::ExecutorAddr();
864 }
866 return Last ? Last->getAddress() + Last->getSize() : orc::ExecutorAddr();
867 }
869
872 }
873
874private:
875 Block *First = nullptr;
876 Block *Last = nullptr;
877};
878
880private:
885
886 template <typename... ArgTs>
887 Addressable &createAddressable(ArgTs &&... Args) {
888 Addressable *A =
889 reinterpret_cast<Addressable *>(Allocator.Allocate<Addressable>());
890 new (A) Addressable(std::forward<ArgTs>(Args)...);
891 return *A;
892 }
893
894 void destroyAddressable(Addressable &A) {
895 A.~Addressable();
896 Allocator.Deallocate(&A);
897 }
898
899 template <typename... ArgTs> Block &createBlock(ArgTs &&... Args) {
900 Block *B = reinterpret_cast<Block *>(Allocator.Allocate<Block>());
901 new (B) Block(std::forward<ArgTs>(Args)...);
902 B->getSection().addBlock(*B);
903 return *B;
904 }
905
906 void destroyBlock(Block &B) {
907 B.~Block();
908 Allocator.Deallocate(&B);
909 }
910
911 void destroySymbol(Symbol &S) {
912 S.~Symbol();
913 Allocator.Deallocate(&S);
914 }
915
916 static iterator_range<Section::block_iterator> getSectionBlocks(Section &S) {
917 return S.blocks();
918 }
919
921 getSectionConstBlocks(const Section &S) {
922 return S.blocks();
923 }
924
926 getSectionSymbols(Section &S) {
927 return S.symbols();
928 }
929
931 getSectionConstSymbols(const Section &S) {
932 return S.symbols();
933 }
934
935 struct GetExternalSymbolMapEntryValue {
936 Symbol *operator()(ExternalSymbolMap::value_type &KV) const {
937 return KV.second;
938 }
939 };
940
941 struct GetSectionMapEntryValue {
942 Section &operator()(SectionMap::value_type &KV) const { return *KV.second; }
943 };
944
945 struct GetSectionMapEntryConstValue {
946 const Section &operator()(const SectionMap::value_type &KV) const {
947 return *KV.second;
948 }
949 };
950
951public:
954 GetExternalSymbolMapEntryValue>;
956
961
962 template <typename OuterItrT, typename InnerItrT, typename T,
963 iterator_range<InnerItrT> getInnerRange(
964 typename OuterItrT::reference)>
966 : public iterator_facade_base<
967 nested_collection_iterator<OuterItrT, InnerItrT, T, getInnerRange>,
968 std::forward_iterator_tag, T> {
969 public:
971
972 nested_collection_iterator(OuterItrT OuterI, OuterItrT OuterE)
973 : OuterI(OuterI), OuterE(OuterE),
974 InnerI(getInnerBegin(OuterI, OuterE)) {
975 moveToNonEmptyInnerOrEnd();
976 }
977
979 return (OuterI == RHS.OuterI) && (InnerI == RHS.InnerI);
980 }
981
982 T operator*() const {
983 assert(InnerI != getInnerRange(*OuterI).end() && "Dereferencing end?");
984 return *InnerI;
985 }
986
988 ++InnerI;
989 moveToNonEmptyInnerOrEnd();
990 return *this;
991 }
992
993 private:
994 static InnerItrT getInnerBegin(OuterItrT OuterI, OuterItrT OuterE) {
995 return OuterI != OuterE ? getInnerRange(*OuterI).begin() : InnerItrT();
996 }
997
998 void moveToNonEmptyInnerOrEnd() {
999 while (OuterI != OuterE && InnerI == getInnerRange(*OuterI).end()) {
1000 ++OuterI;
1001 InnerI = getInnerBegin(OuterI, OuterE);
1002 }
1003 }
1004
1005 OuterItrT OuterI, OuterE;
1006 InnerItrT InnerI;
1007 };
1008
1011 Symbol *, getSectionSymbols>;
1012
1016 getSectionConstSymbols>;
1017
1020 Block *, getSectionBlocks>;
1021
1025 getSectionConstBlocks>;
1026
1027 using GetEdgeKindNameFunction = const char *(*)(Edge::Kind);
1028
1029 LinkGraph(std::string Name, std::shared_ptr<orc::SymbolStringPool> SSP,
1030 Triple TT, SubtargetFeatures Features,
1031 GetEdgeKindNameFunction GetEdgeKindName)
1032 : Name(std::move(Name)), SSP(std::move(SSP)), TT(std::move(TT)),
1033 Features(std::move(Features)),
1034 GetEdgeKindName(std::move(GetEdgeKindName)) {
1035 assert(!(Triple::getArchPointerBitWidth(this->TT.getArch()) % 8) &&
1036 "Arch bitwidth is not a multiple of 8");
1037 }
1038
1039 LinkGraph(const LinkGraph &) = delete;
1040 LinkGraph &operator=(const LinkGraph &) = delete;
1041 LinkGraph(LinkGraph &&) = delete;
1044
1045 /// Returns the name of this graph (usually the name of the original
1046 /// underlying MemoryBuffer).
1047 const std::string &getName() const { return Name; }
1048
1049 /// Returns the target triple for this Graph.
1050 const Triple &getTargetTriple() const { return TT; }
1051
1052 /// Return the subtarget features for this Graph.
1053 const SubtargetFeatures &getFeatures() const { return Features; }
1054
1055 /// Returns the pointer size for use in this graph.
1056 unsigned getPointerSize() const { return TT.getArchPointerBitWidth() / 8; }
1057
1058 /// Returns the endianness of content in this graph.
1061 }
1062
1063 const char *getEdgeKindName(Edge::Kind K) const { return GetEdgeKindName(K); }
1064
1065 std::shared_ptr<orc::SymbolStringPool> getSymbolStringPool() { return SSP; }
1066
1067 /// Allocate a mutable buffer of the given size using the LinkGraph's
1068 /// allocator.
1070 return {Allocator.Allocate<char>(Size), Size};
1071 }
1072
1073 /// Allocate a copy of the given string using the LinkGraph's allocator.
1074 /// This can be useful when renaming symbols or adding new content to the
1075 /// graph.
1077 auto *AllocatedBuffer = Allocator.Allocate<char>(Source.size());
1078 llvm::copy(Source, AllocatedBuffer);
1079 return MutableArrayRef<char>(AllocatedBuffer, Source.size());
1080 }
1081
1082 /// Allocate a copy of the given string using the LinkGraph's allocator.
1083 /// This can be useful when renaming symbols or adding new content to the
1084 /// graph.
1085 ///
1086 /// Note: This Twine-based overload requires an extra string copy and an
1087 /// extra heap allocation for large strings. The ArrayRef<char> overload
1088 /// should be preferred where possible.
1090 SmallString<256> TmpBuffer;
1091 auto SourceStr = Source.toStringRef(TmpBuffer);
1092 auto *AllocatedBuffer = Allocator.Allocate<char>(SourceStr.size());
1093 llvm::copy(SourceStr, AllocatedBuffer);
1094 return MutableArrayRef<char>(AllocatedBuffer, SourceStr.size());
1095 }
1096
1097 /// Allocate a copy of the given string using the LinkGraph's allocator
1098 /// and return it as a StringRef.
1099 ///
1100 /// This is a convenience wrapper around allocateContent(Twine) that is
1101 /// handy when creating new symbol names within the graph.
1103 auto Buf = allocateContent(Source);
1104 return {Buf.data(), Buf.size()};
1105 }
1106
1107 /// Allocate a copy of the given string using the LinkGraph's allocator.
1108 ///
1109 /// The allocated string will be terminated with a null character, and the
1110 /// returned MutableArrayRef will include this null character in the last
1111 /// position.
1113 char *AllocatedBuffer = Allocator.Allocate<char>(Source.size() + 1);
1114 llvm::copy(Source, AllocatedBuffer);
1115 AllocatedBuffer[Source.size()] = '\0';
1116 return MutableArrayRef<char>(AllocatedBuffer, Source.size() + 1);
1117 }
1118
1119 /// Allocate a copy of the given string using the LinkGraph's allocator.
1120 ///
1121 /// The allocated string will be terminated with a null character, and the
1122 /// returned MutableArrayRef will include this null character in the last
1123 /// position.
1124 ///
1125 /// Note: This Twine-based overload requires an extra string copy and an
1126 /// extra heap allocation for large strings. The ArrayRef<char> overload
1127 /// should be preferred where possible.
1129 SmallString<256> TmpBuffer;
1130 auto SourceStr = Source.toStringRef(TmpBuffer);
1131 auto *AllocatedBuffer = Allocator.Allocate<char>(SourceStr.size() + 1);
1132 llvm::copy(SourceStr, AllocatedBuffer);
1133 AllocatedBuffer[SourceStr.size()] = '\0';
1134 return MutableArrayRef<char>(AllocatedBuffer, SourceStr.size() + 1);
1135 }
1136
1137 /// Create a section with the given name, protection flags.
1139 assert(!Sections.count(Name) && "Duplicate section name");
1140 std::unique_ptr<Section> Sec(new Section(Name, Prot, Sections.size()));
1141 return *Sections.insert(std::make_pair(Name, std::move(Sec))).first->second;
1142 }
1143
1144 /// Create a content block.
1147 uint64_t AlignmentOffset) {
1148 return createBlock(Parent, Content, Address, Alignment, AlignmentOffset);
1149 }
1150
1151 /// Create a content block with initially mutable data.
1153 MutableArrayRef<char> MutableContent,
1155 uint64_t Alignment,
1156 uint64_t AlignmentOffset) {
1157 return createBlock(Parent, MutableContent, Address, Alignment,
1158 AlignmentOffset);
1159 }
1160
1161 /// Create a content block with initially mutable data of the given size.
1162 /// Content will be allocated via the LinkGraph's allocateBuffer method.
1163 /// By default the memory will be zero-initialized. Passing false for
1164 /// ZeroInitialize will prevent this.
1165 Block &createMutableContentBlock(Section &Parent, size_t ContentSize,
1167 uint64_t Alignment, uint64_t AlignmentOffset,
1168 bool ZeroInitialize = true) {
1169 auto Content = allocateBuffer(ContentSize);
1170 if (ZeroInitialize)
1171 memset(Content.data(), 0, Content.size());
1172 return createBlock(Parent, Content, Address, Alignment, AlignmentOffset);
1173 }
1174
1175 /// Create a zero-fill block.
1178 uint64_t AlignmentOffset) {
1179 return createBlock(Parent, Size, Address, Alignment, AlignmentOffset);
1180 }
1181
1182 /// Returns a BinaryStreamReader for the given block.
1185 reinterpret_cast<const uint8_t *>(B.getContent().data()), B.getSize());
1187 }
1188
1189 /// Returns a BinaryStreamWriter for the given block.
1190 /// This will call getMutableContent to obtain mutable content for the block.
1193 reinterpret_cast<uint8_t *>(B.getMutableContent(*this).data()),
1194 B.getSize());
1196 }
1197
1198 /// Cache type for the splitBlock function.
1199 using SplitBlockCache = std::optional<SmallVector<Symbol *, 8>>;
1200
1201 /// Splits block B into a sequence of smaller blocks.
1202 ///
1203 /// SplitOffsets should be a sequence of ascending offsets in B. The starting
1204 /// offset should be greater than zero, and the final offset less than
1205 /// B.getSize() - 1.
1206 ///
1207 /// The resulting seqeunce of blocks will start with the original block B
1208 /// (truncated to end at the first split offset) followed by newly introduced
1209 /// blocks starting at the subsequent split points.
1210 ///
1211 /// The optional Cache parameter can be used to speed up repeated calls to
1212 /// splitBlock for blocks within a single Section. If the value is None then
1213 /// the cache will be treated as uninitialized and splitBlock will populate
1214 /// it. Otherwise it is assumed to contain the list of Symbols pointing at B,
1215 /// sorted in descending order of offset.
1216 ///
1217 ///
1218 /// Notes:
1219 ///
1220 /// 1. splitBlock must be used with care. Splitting a block may cause
1221 /// incoming edges to become invalid if the edge target subexpression
1222 /// points outside the bounds of the newly split target block (E.g. an
1223 /// edge 'S + 10 : Pointer64' where S points to a newly split block
1224 /// whose size is less than 10). No attempt is made to detect invalidation
1225 /// of incoming edges, as in general this requires context that the
1226 /// LinkGraph does not have. Clients are responsible for ensuring that
1227 /// splitBlock is not used in a way that invalidates edges.
1228 ///
1229 /// 2. The newly introduced blocks will have new ordinals that will be higher
1230 /// than any other ordinals in the section. Clients are responsible for
1231 /// re-assigning block ordinals to restore a compatible order if needed.
1232 ///
1233 /// 3. The cache is not automatically updated if new symbols are introduced
1234 /// between calls to splitBlock. Any newly introduced symbols may be
1235 /// added to the cache manually (descending offset order must be
1236 /// preserved), or the cache can be set to None and rebuilt by
1237 /// splitBlock on the next call.
1238 template <typename SplitOffsetRange>
1239 std::vector<Block *> splitBlock(Block &B, SplitOffsetRange &&SplitOffsets,
1240 LinkGraph::SplitBlockCache *Cache = nullptr) {
1241 std::vector<Block *> Blocks;
1242 Blocks.push_back(&B);
1243
1244 if (std::empty(SplitOffsets))
1245 return Blocks;
1246
1247 // Special case zero-fill:
1248 if (B.isZeroFill()) {
1249 size_t OrigSize = B.getSize();
1250 for (Edge::OffsetT Offset : SplitOffsets) {
1251 assert(Offset > 0 && Offset < B.getSize() &&
1252 "Split offset must be inside block content");
1253 Blocks.back()->setZeroFillSize(
1254 Offset - (Blocks.back()->getAddress() - B.getAddress()));
1255 Blocks.push_back(&createZeroFillBlock(
1256 B.getSection(), B.getSize(), B.getAddress() + Offset,
1257 B.getAlignment(),
1258 (B.getAlignmentOffset() + Offset) % B.getAlignment()));
1259 }
1260 Blocks.back()->setZeroFillSize(
1261 OrigSize - (Blocks.back()->getAddress() - B.getAddress()));
1262 return Blocks;
1263 }
1264
1265 // Handle content blocks. We'll just create the blocks with their starting
1266 // address and no content here. The bulk of the work is deferred to
1267 // splitBlockImpl.
1268 for (Edge::OffsetT Offset : SplitOffsets) {
1269 assert(Offset > 0 && Offset < B.getSize() &&
1270 "Split offset must be inside block content");
1271 Blocks.push_back(&createContentBlock(
1272 B.getSection(), ArrayRef<char>(), B.getAddress() + Offset,
1273 B.getAlignment(),
1274 (B.getAlignmentOffset() + Offset) % B.getAlignment()));
1275 }
1276
1277 return splitBlockImpl(std::move(Blocks), Cache);
1278 }
1279
1280 /// Intern the given string in the LinkGraph's SymbolStringPool.
1282 return SSP->intern(SymbolName);
1283 }
1284
1285 /// Add an external symbol.
1286 /// Some formats (e.g. ELF) allow Symbols to have sizes. For Symbols whose
1287 /// size is not known, you should substitute '0'.
1288 /// The IsWeaklyReferenced argument determines whether the symbol must be
1289 /// present during lookup: Externals that are strongly referenced must be
1290 /// found or an error will be emitted. Externals that are weakly referenced
1291 /// are permitted to be undefined, in which case they are assigned an address
1292 /// of 0.
1295 bool IsWeaklyReferenced) {
1296 assert(!ExternalSymbols.contains(*Name) && "Duplicate external symbol");
1297 auto &Sym = Symbol::constructExternal(
1298 Allocator, createAddressable(orc::ExecutorAddr(), false),
1299 std::move(Name), Size, Linkage::Strong, IsWeaklyReferenced);
1300 ExternalSymbols.insert({*Sym.getName(), &Sym});
1301 return Sym;
1302 }
1303
1305 bool IsWeaklyReferenced) {
1306 return addExternalSymbol(SSP->intern(Name), Size, IsWeaklyReferenced);
1307 }
1308
1309 /// Add an absolute symbol.
1313 bool IsLive) {
1314 assert((S == Scope::Local || llvm::none_of(AbsoluteSymbols,
1315 [&](const Symbol *Sym) {
1316 return Sym->getName() == Name;
1317 })) &&
1318 "Duplicate absolute symbol");
1319 auto &Sym = Symbol::constructAbsolute(Allocator, createAddressable(Address),
1320 std::move(Name), Size, L, S, IsLive);
1321 AbsoluteSymbols.insert(&Sym);
1322 return Sym;
1323 }
1324
1327 bool IsLive) {
1328
1329 return addAbsoluteSymbol(SSP->intern(Name), Address, Size, L, S, IsLive);
1330 }
1331
1332 /// Add an anonymous symbol.
1334 orc::ExecutorAddrDiff Size, bool IsCallable,
1335 bool IsLive) {
1336 auto &Sym = Symbol::constructAnonDef(Allocator, Content, Offset, Size,
1337 IsCallable, IsLive);
1338 Content.getSection().addSymbol(Sym);
1339 return Sym;
1340 }
1341
1342 /// Add a named symbol.
1345 Linkage L, Scope S, bool IsCallable, bool IsLive) {
1346 return addDefinedSymbol(Content, Offset, SSP->intern(Name), Size, L, S,
1347 IsCallable, IsLive);
1348 }
1349
1353 bool IsCallable, bool IsLive) {
1355 [&](const Symbol *Sym) {
1356 return Sym->getName() == Name;
1357 })) &&
1358 "Duplicate defined symbol");
1359 auto &Sym =
1360 Symbol::constructNamedDef(Allocator, Content, Offset, std::move(Name),
1361 Size, L, S, IsLive, IsCallable);
1362 Content.getSection().addSymbol(Sym);
1363 return Sym;
1364 }
1365
1367 return make_range(
1368 section_iterator(Sections.begin(), GetSectionMapEntryValue()),
1369 section_iterator(Sections.end(), GetSectionMapEntryValue()));
1370 }
1371
1373 return make_range(
1374 const_section_iterator(Sections.begin(),
1375 GetSectionMapEntryConstValue()),
1376 const_section_iterator(Sections.end(), GetSectionMapEntryConstValue()));
1377 }
1378
1379 size_t sections_size() const { return Sections.size(); }
1380
1381 /// Returns the section with the given name if it exists, otherwise returns
1382 /// null.
1384 auto I = Sections.find(Name);
1385 if (I == Sections.end())
1386 return nullptr;
1387 return I->second.get();
1388 }
1389
1391 auto Secs = sections();
1392 return make_range(block_iterator(Secs.begin(), Secs.end()),
1393 block_iterator(Secs.end(), Secs.end()));
1394 }
1395
1397 auto Secs = sections();
1398 return make_range(const_block_iterator(Secs.begin(), Secs.end()),
1399 const_block_iterator(Secs.end(), Secs.end()));
1400 }
1401
1403 return make_range(
1404 external_symbol_iterator(ExternalSymbols.begin(),
1405 GetExternalSymbolMapEntryValue()),
1406 external_symbol_iterator(ExternalSymbols.end(),
1407 GetExternalSymbolMapEntryValue()));
1408 }
1409
1410 /// Returns the external symbol with the given name if one exists, otherwise
1411 /// returns nullptr.
1413 for (auto *Sym : external_symbols())
1414 if (Sym->getName() == Name)
1415 return Sym;
1416 return nullptr;
1417 }
1418
1420 return make_range(AbsoluteSymbols.begin(), AbsoluteSymbols.end());
1421 }
1422
1424 for (auto *Sym : absolute_symbols())
1425 if (Sym->getName() == Name)
1426 return Sym;
1427 return nullptr;
1428 }
1429
1431 auto Secs = sections();
1432 return make_range(defined_symbol_iterator(Secs.begin(), Secs.end()),
1433 defined_symbol_iterator(Secs.end(), Secs.end()));
1434 }
1435
1437 auto Secs = sections();
1438 return make_range(const_defined_symbol_iterator(Secs.begin(), Secs.end()),
1439 const_defined_symbol_iterator(Secs.end(), Secs.end()));
1440 }
1441
1442 /// Returns the defined symbol with the given name if one exists, otherwise
1443 /// returns nullptr.
1445 for (auto *Sym : defined_symbols())
1446 if (Sym->hasName() && Sym->getName() == Name)
1447 return Sym;
1448 return nullptr;
1449 }
1450
1451 /// Make the given symbol external (must not already be external).
1452 ///
1453 /// Symbol size, linkage and callability will be left unchanged. Symbol scope
1454 /// will be set to Default, and offset will be reset to 0.
1456 assert(!Sym.isExternal() && "Symbol is already external");
1457 if (Sym.isAbsolute()) {
1458 assert(AbsoluteSymbols.count(&Sym) &&
1459 "Sym is not in the absolute symbols set");
1460 assert(Sym.getOffset() == 0 && "Absolute not at offset 0");
1461 AbsoluteSymbols.erase(&Sym);
1462 auto &A = Sym.getAddressable();
1463 A.setAbsolute(false);
1464 A.setAddress(orc::ExecutorAddr());
1465 } else {
1466 assert(Sym.isDefined() && "Sym is not a defined symbol");
1467 Section &Sec = Sym.getSection();
1468 Sec.removeSymbol(Sym);
1469 Sym.makeExternal(createAddressable(orc::ExecutorAddr(), false));
1470 }
1471 ExternalSymbols.insert({*Sym.getName(), &Sym});
1472 }
1473
1474 /// Make the given symbol an absolute with the given address (must not already
1475 /// be absolute).
1476 ///
1477 /// The symbol's size, linkage, and callability, and liveness will be left
1478 /// unchanged, and its offset will be reset to 0.
1479 ///
1480 /// If the symbol was external then its scope will be set to local, otherwise
1481 /// it will be left unchanged.
1483 assert(!Sym.isAbsolute() && "Symbol is already absolute");
1484 if (Sym.isExternal()) {
1485 assert(ExternalSymbols.contains(*Sym.getName()) &&
1486 "Sym is not in the absolute symbols set");
1487 assert(Sym.getOffset() == 0 && "External is not at offset 0");
1488 ExternalSymbols.erase(*Sym.getName());
1489 auto &A = Sym.getAddressable();
1490 A.setAbsolute(true);
1491 A.setAddress(Address);
1492 Sym.setScope(Scope::Local);
1493 } else {
1494 assert(Sym.isDefined() && "Sym is not a defined symbol");
1495 Section &Sec = Sym.getSection();
1496 Sec.removeSymbol(Sym);
1497 Sym.makeAbsolute(createAddressable(Address));
1498 }
1499 AbsoluteSymbols.insert(&Sym);
1500 }
1501
1502 /// Turn an absolute or external symbol into a defined one by attaching it to
1503 /// a block. Symbol must not already be defined.
1506 bool IsLive) {
1507 assert(!Sym.isDefined() && "Sym is already a defined symbol");
1508 if (Sym.isAbsolute()) {
1509 assert(AbsoluteSymbols.count(&Sym) &&
1510 "Symbol is not in the absolutes set");
1511 AbsoluteSymbols.erase(&Sym);
1512 } else {
1513 assert(ExternalSymbols.contains(*Sym.getName()) &&
1514 "Symbol is not in the externals set");
1515 ExternalSymbols.erase(*Sym.getName());
1516 }
1517 Addressable &OldBase = *Sym.Base;
1518 Sym.setBlock(Content);
1519 Sym.setOffset(Offset);
1520 Sym.setSize(Size);
1521 Sym.setLinkage(L);
1522 Sym.setScope(S);
1523 Sym.setLive(IsLive);
1524 Content.getSection().addSymbol(Sym);
1525 destroyAddressable(OldBase);
1526 }
1527
1528 /// Transfer a defined symbol from one block to another.
1529 ///
1530 /// The symbol's offset within DestBlock is set to NewOffset.
1531 ///
1532 /// If ExplicitNewSize is given as None then the size of the symbol will be
1533 /// checked and auto-truncated to at most the size of the remainder (from the
1534 /// given offset) of the size of the new block.
1535 ///
1536 /// All other symbol attributes are unchanged.
1537 void
1539 orc::ExecutorAddrDiff NewOffset,
1540 std::optional<orc::ExecutorAddrDiff> ExplicitNewSize) {
1541 auto &OldSection = Sym.getSection();
1542 Sym.setBlock(DestBlock);
1543 Sym.setOffset(NewOffset);
1544 if (ExplicitNewSize)
1545 Sym.setSize(*ExplicitNewSize);
1546 else {
1547 auto RemainingBlockSize = DestBlock.getSize() - NewOffset;
1548 if (Sym.getSize() > RemainingBlockSize)
1549 Sym.setSize(RemainingBlockSize);
1550 }
1551 if (&DestBlock.getSection() != &OldSection) {
1552 OldSection.removeSymbol(Sym);
1553 DestBlock.getSection().addSymbol(Sym);
1554 }
1555 }
1556
1557 /// Transfers the given Block and all Symbols pointing to it to the given
1558 /// Section.
1559 ///
1560 /// No attempt is made to check compatibility of the source and destination
1561 /// sections. Blocks may be moved between sections with incompatible
1562 /// permissions (e.g. from data to text). The client is responsible for
1563 /// ensuring that this is safe.
1564 void transferBlock(Block &B, Section &NewSection) {
1565 auto &OldSection = B.getSection();
1566 if (&OldSection == &NewSection)
1567 return;
1568 SmallVector<Symbol *> AttachedSymbols;
1569 for (auto *S : OldSection.symbols())
1570 if (&S->getBlock() == &B)
1571 AttachedSymbols.push_back(S);
1572 for (auto *S : AttachedSymbols) {
1573 OldSection.removeSymbol(*S);
1574 NewSection.addSymbol(*S);
1575 }
1576 OldSection.removeBlock(B);
1577 NewSection.addBlock(B);
1578 }
1579
1580 /// Move all blocks and symbols from the source section to the destination
1581 /// section.
1582 ///
1583 /// If PreserveSrcSection is true (or SrcSection and DstSection are the same)
1584 /// then SrcSection is preserved, otherwise it is removed (the default).
1585 void mergeSections(Section &DstSection, Section &SrcSection,
1586 bool PreserveSrcSection = false) {
1587 if (&DstSection == &SrcSection)
1588 return;
1589 for (auto *B : SrcSection.blocks())
1590 B->setSection(DstSection);
1591 SrcSection.transferContentTo(DstSection);
1592 if (!PreserveSrcSection)
1593 removeSection(SrcSection);
1594 }
1595
1596 /// Removes an external symbol. Also removes the underlying Addressable.
1598 assert(!Sym.isDefined() && !Sym.isAbsolute() &&
1599 "Sym is not an external symbol");
1600 assert(ExternalSymbols.contains(*Sym.getName()) &&
1601 "Symbol is not in the externals set");
1602 ExternalSymbols.erase(*Sym.getName());
1603 Addressable &Base = *Sym.Base;
1605 [&](Symbol *AS) { return AS->Base == &Base; }) &&
1606 "Base addressable still in use");
1607 destroySymbol(Sym);
1608 destroyAddressable(Base);
1609 }
1610
1611 /// Remove an absolute symbol. Also removes the underlying Addressable.
1613 assert(!Sym.isDefined() && Sym.isAbsolute() &&
1614 "Sym is not an absolute symbol");
1615 assert(AbsoluteSymbols.count(&Sym) &&
1616 "Symbol is not in the absolute symbols set");
1617 AbsoluteSymbols.erase(&Sym);
1618 Addressable &Base = *Sym.Base;
1620 [&](Symbol *AS) { return AS->Base == &Base; }) &&
1621 "Base addressable still in use");
1622 destroySymbol(Sym);
1623 destroyAddressable(Base);
1624 }
1625
1626 /// Removes defined symbols. Does not remove the underlying block.
1628 assert(Sym.isDefined() && "Sym is not a defined symbol");
1629 Sym.getSection().removeSymbol(Sym);
1630 destroySymbol(Sym);
1631 }
1632
1633 /// Remove a block. The block reference is defunct after calling this
1634 /// function and should no longer be used.
1636 assert(llvm::none_of(B.getSection().symbols(),
1637 [&](const Symbol *Sym) {
1638 return &Sym->getBlock() == &B;
1639 }) &&
1640 "Block still has symbols attached");
1641 B.getSection().removeBlock(B);
1642 destroyBlock(B);
1643 }
1644
1645 /// Remove a section. The section reference is defunct after calling this
1646 /// function and should no longer be used.
1648 assert(Sections.count(Sec.getName()) && "Section not found");
1649 assert(Sections.find(Sec.getName())->second.get() == &Sec &&
1650 "Section map entry invalid");
1651 Sections.erase(Sec.getName());
1652 }
1653
1654 /// Accessor for the AllocActions object for this graph. This can be used to
1655 /// register allocation action calls prior to finalization.
1656 ///
1657 /// Accessing this object after finalization will result in undefined
1658 /// behavior.
1660
1661 /// Dump the graph.
1662 LLVM_ABI void dump(raw_ostream &OS);
1663
1664private:
1665 LLVM_ABI std::vector<Block *> splitBlockImpl(std::vector<Block *> Blocks,
1666 SplitBlockCache *Cache);
1667
1668 // Put the BumpPtrAllocator first so that we don't free any of the underlying
1669 // memory until the Symbol/Addressable destructors have been run.
1671
1672 std::string Name;
1673 std::shared_ptr<orc::SymbolStringPool> SSP;
1674 Triple TT;
1675 SubtargetFeatures Features;
1676 GetEdgeKindNameFunction GetEdgeKindName = nullptr;
1678 // FIXME(jared): these should become dense maps
1679 ExternalSymbolMap ExternalSymbols;
1680 AbsoluteSymbolSet AbsoluteSymbols;
1682};
1683
1685 if (!ContentMutable)
1686 setMutableContent(G.allocateContent({Data, Size}));
1687 return MutableArrayRef<char>(const_cast<char *>(Data), Size);
1688}
1689
1690/// Enables easy lookup of blocks by addresses.
1692public:
1693 using AddrToBlockMap = std::map<orc::ExecutorAddr, Block *>;
1694 using const_iterator = AddrToBlockMap::const_iterator;
1695
1696 /// A block predicate that always adds all blocks.
1697 static bool includeAllBlocks(const Block &B) { return true; }
1698
1699 /// A block predicate that always includes blocks with non-null addresses.
1700 static bool includeNonNull(const Block &B) { return !!B.getAddress(); }
1701
1702 BlockAddressMap() = default;
1703
1704 /// Add a block to the map. Returns an error if the block overlaps with any
1705 /// existing block.
1706 template <typename PredFn = decltype(includeAllBlocks)>
1708 if (!Pred(B))
1709 return Error::success();
1710
1711 auto I = AddrToBlock.upper_bound(B.getAddress());
1712
1713 // If we're not at the end of the map, check for overlap with the next
1714 // element.
1715 if (I != AddrToBlock.end()) {
1716 if (B.getAddress() + B.getSize() > I->second->getAddress())
1717 return overlapError(B, *I->second);
1718 }
1719
1720 // If we're not at the start of the map, check for overlap with the previous
1721 // element.
1722 if (I != AddrToBlock.begin()) {
1723 auto &PrevBlock = *std::prev(I)->second;
1724 if (PrevBlock.getAddress() + PrevBlock.getSize() > B.getAddress())
1725 return overlapError(B, PrevBlock);
1726 }
1727
1728 AddrToBlock.insert(I, std::make_pair(B.getAddress(), &B));
1729 return Error::success();
1730 }
1731
1732 /// Add a block to the map without checking for overlap with existing blocks.
1733 /// The client is responsible for ensuring that the block added does not
1734 /// overlap with any existing block.
1735 void addBlockWithoutChecking(Block &B) { AddrToBlock[B.getAddress()] = &B; }
1736
1737 /// Add a range of blocks to the map. Returns an error if any block in the
1738 /// range overlaps with any other block in the range, or with any existing
1739 /// block in the map.
1740 template <typename BlockPtrRange,
1741 typename PredFn = decltype(includeAllBlocks)>
1742 Error addBlocks(BlockPtrRange &&Blocks, PredFn Pred = includeAllBlocks) {
1743 for (auto *B : Blocks)
1744 if (auto Err = addBlock(*B, Pred))
1745 return Err;
1746 return Error::success();
1747 }
1748
1749 /// Add a range of blocks to the map without checking for overlap with
1750 /// existing blocks. The client is responsible for ensuring that the block
1751 /// added does not overlap with any existing block.
1752 template <typename BlockPtrRange>
1753 void addBlocksWithoutChecking(BlockPtrRange &&Blocks) {
1754 for (auto *B : Blocks)
1756 }
1757
1758 /// Iterates over (Address, Block*) pairs in ascending order of address.
1759 const_iterator begin() const { return AddrToBlock.begin(); }
1760 const_iterator end() const { return AddrToBlock.end(); }
1761
1762 /// Returns the block starting at the given address, or nullptr if no such
1763 /// block exists.
1765 auto I = AddrToBlock.find(Addr);
1766 if (I == AddrToBlock.end())
1767 return nullptr;
1768 return I->second;
1769 }
1770
1771 /// Returns the block covering the given address, or nullptr if no such block
1772 /// exists.
1774 auto I = AddrToBlock.upper_bound(Addr);
1775 if (I == AddrToBlock.begin())
1776 return nullptr;
1777 auto *B = std::prev(I)->second;
1778 if (Addr < B->getAddress() + B->getSize())
1779 return B;
1780 return nullptr;
1781 }
1782
1783private:
1784 Error overlapError(Block &NewBlock, Block &ExistingBlock) {
1785 auto NewBlockEnd = NewBlock.getAddress() + NewBlock.getSize();
1786 auto ExistingBlockEnd =
1787 ExistingBlock.getAddress() + ExistingBlock.getSize();
1788 return make_error<JITLinkError>(
1789 "Block at " +
1790 formatv("{0:x16} -- {1:x16}", NewBlock.getAddress().getValue(),
1791 NewBlockEnd.getValue()) +
1792 " overlaps " +
1793 formatv("{0:x16} -- {1:x16}", ExistingBlock.getAddress().getValue(),
1794 ExistingBlockEnd.getValue()));
1795 }
1796
1797 AddrToBlockMap AddrToBlock;
1798};
1799
1800/// A map of addresses to Symbols.
1802public:
1804
1805 /// Add a symbol to the SymbolAddressMap.
1807 AddrToSymbols[Sym.getAddress()].push_back(&Sym);
1808 }
1809
1810 /// Add all symbols in a given range to the SymbolAddressMap.
1811 template <typename SymbolPtrCollection>
1812 void addSymbols(SymbolPtrCollection &&Symbols) {
1813 for (auto *Sym : Symbols)
1814 addSymbol(*Sym);
1815 }
1816
1817 /// Returns the list of symbols that start at the given address, or nullptr if
1818 /// no such symbols exist.
1820 auto I = AddrToSymbols.find(Addr);
1821 if (I == AddrToSymbols.end())
1822 return nullptr;
1823 return &I->second;
1824 }
1825
1826private:
1827 std::map<orc::ExecutorAddr, SymbolVector> AddrToSymbols;
1828};
1829
1830/// A function for mutating LinkGraphs.
1832
1833/// A list of LinkGraph passes.
1834using LinkGraphPassList = std::vector<LinkGraphPassFunction>;
1835
1836/// An LinkGraph pass configuration, consisting of a list of pre-prune,
1837/// post-prune, and post-fixup passes.
1839
1840 /// Pre-prune passes.
1841 ///
1842 /// These passes are called on the graph after it is built, and before any
1843 /// symbols have been pruned. Graph nodes still have their original vmaddrs.
1844 ///
1845 /// Notable use cases: Marking symbols live or should-discard.
1847
1848 /// Post-prune passes.
1849 ///
1850 /// These passes are called on the graph after dead stripping, but before
1851 /// memory is allocated or nodes assigned their final addresses.
1852 ///
1853 /// Notable use cases: Building GOT, stub, and TLV symbols.
1855
1856 /// Post-allocation passes.
1857 ///
1858 /// These passes are called on the graph after memory has been allocated and
1859 /// defined nodes have been assigned their final addresses, but before the
1860 /// context has been notified of these addresses. At this point externals
1861 /// have not been resolved, and symbol content has not yet been copied into
1862 /// working memory.
1863 ///
1864 /// Notable use cases: Setting up data structures associated with addresses
1865 /// of defined symbols (e.g. a mapping of __dso_handle to JITDylib* for the
1866 /// JIT runtime) -- using a PostAllocationPass for this ensures that the
1867 /// data structures are in-place before any query for resolved symbols
1868 /// can complete.
1870
1871 /// Pre-fixup passes.
1872 ///
1873 /// These passes are called on the graph after memory has been allocated,
1874 /// content copied into working memory, and all nodes (including externals)
1875 /// have been assigned their final addresses, but before any fixups have been
1876 /// applied.
1877 ///
1878 /// Notable use cases: Late link-time optimizations like GOT and stub
1879 /// elimination.
1881
1882 /// Post-fixup passes.
1883 ///
1884 /// These passes are called on the graph after block contents has been copied
1885 /// to working memory, and fixups applied. Blocks have been updated to point
1886 /// to their fixed up content.
1887 ///
1888 /// Notable use cases: Testing and validation.
1890};
1891
1892/// Flags for symbol lookup.
1893///
1894/// FIXME: These basically duplicate orc::SymbolLookupFlags -- We should merge
1895/// the two types once we have an OrcSupport library.
1897
1899
1900/// A map of symbol names to resolved addresses.
1903
1904/// A function object to call with a resolved symbol map (See AsyncLookupResult)
1905/// or an error if resolution failed.
1907public:
1909 virtual void run(Expected<AsyncLookupResult> LR) = 0;
1910
1911private:
1912 virtual void anchor();
1913};
1914
1915/// Create a lookup continuation from a function object.
1916template <typename Continuation>
1917std::unique_ptr<JITLinkAsyncLookupContinuation>
1918createLookupContinuation(Continuation Cont) {
1919
1920 class Impl final : public JITLinkAsyncLookupContinuation {
1921 public:
1922 Impl(Continuation C) : C(std::move(C)) {}
1923 void run(Expected<AsyncLookupResult> LR) override { C(std::move(LR)); }
1924
1925 private:
1926 Continuation C;
1927 };
1928
1929 return std::make_unique<Impl>(std::move(Cont));
1930}
1931
1932/// Holds context for a single jitLink invocation.
1934public:
1936
1937 /// Create a JITLinkContext.
1938 JITLinkContext(const JITLinkDylib *JD) : JD(JD) {}
1939
1940 /// Destroy a JITLinkContext.
1942
1943 /// Return the JITLinkDylib that this link is targeting, if any.
1944 const JITLinkDylib *getJITLinkDylib() const { return JD; }
1945
1946 /// Return the MemoryManager to be used for this link.
1948
1949 /// Notify this context that linking failed.
1950 /// Called by JITLink if linking cannot be completed.
1951 virtual void notifyFailed(Error Err) = 0;
1952
1953 /// Called by JITLink to resolve external symbols. This method is passed a
1954 /// lookup continutation which it must call with a result to continue the
1955 /// linking process.
1956 virtual void lookup(const LookupMap &Symbols,
1957 std::unique_ptr<JITLinkAsyncLookupContinuation> LC) = 0;
1958
1959 /// Called by JITLink once all defined symbols in the graph have been assigned
1960 /// their final memory locations in the target process. At this point the
1961 /// LinkGraph can be inspected to build a symbol table, however the block
1962 /// content will not generally have been copied to the target location yet.
1963 ///
1964 /// If the client detects an error in the LinkGraph state (e.g. unexpected or
1965 /// missing symbols) they may return an error here. The error will be
1966 /// propagated to notifyFailed and the linker will bail out.
1968
1969 /// Called by JITLink to notify the context that the object has been
1970 /// finalized (i.e. emitted to memory and memory permissions set). If all of
1971 /// this objects dependencies have also been finalized then the code is ready
1972 /// to run.
1974
1975 /// Called by JITLink prior to linking to determine whether default passes for
1976 /// the target should be added. The default implementation returns true.
1977 /// If subclasses override this method to return false for any target then
1978 /// they are required to fully configure the pass pipeline for that target.
1979 virtual bool shouldAddDefaultTargetPasses(const Triple &TT) const;
1980
1981 /// Returns the mark-live pass to be used for this link. If no pass is
1982 /// returned (the default) then the target-specific linker implementation will
1983 /// choose a conservative default (usually marking all symbols live).
1984 /// This function is only called if shouldAddDefaultTargetPasses returns true,
1985 /// otherwise the JITContext is responsible for adding a mark-live pass in
1986 /// modifyPassConfig.
1987 virtual LinkGraphPassFunction getMarkLivePass(const Triple &TT) const;
1988
1989 /// Called by JITLink to modify the pass pipeline prior to linking.
1990 /// The default version performs no modification.
1991 virtual Error modifyPassConfig(LinkGraph &G, PassConfiguration &Config);
1992
1993private:
1994 const JITLinkDylib *JD = nullptr;
1995};
1996
1997/// Marks all symbols in a graph live. This can be used as a default,
1998/// conservative mark-live implementation.
2000
2001/// Create an out of range error for the given edge in the given block.
2003 const Edge &E);
2004
2006 int N, const Edge &E);
2007
2008/// Creates a new pointer block in the given section and returns an
2009/// Anonymous symbol pointing to it.
2010///
2011/// The pointer block will have the following default values:
2012/// alignment: PointerSize
2013/// alignment-offset: 0
2014/// address: highest allowable
2016 unique_function<Symbol &(LinkGraph &G, Section &PointerSection,
2017 Symbol *InitialTarget, uint64_t InitialAddend)>;
2018
2019/// Get target-specific AnonymousPointerCreator
2021
2022/// Create a jump stub that jumps via the pointer at the given symbol and
2023/// an anonymous symbol pointing to it. Return the anonymous symbol.
2024///
2025/// The stub block will be created by createPointerJumpStubBlock.
2027 LinkGraph &G, Section &StubSection, Symbol &PointerSymbol)>;
2028
2029/// Get target-specific PointerJumpStubCreator
2031
2032/// Base case for edge-visitors where the visitor-list is empty.
2033inline void visitEdge(LinkGraph &G, Block *B, Edge &E) {}
2034
2035/// Applies the first visitor in the list to the given edge. If the visitor's
2036/// visitEdge method returns true then we return immediately, otherwise we
2037/// apply the next visitor.
2038template <typename VisitorT, typename... VisitorTs>
2039void visitEdge(LinkGraph &G, Block *B, Edge &E, VisitorT &&V,
2040 VisitorTs &&...Vs) {
2041 if (!V.visitEdge(G, B, E))
2042 visitEdge(G, B, E, std::forward<VisitorTs>(Vs)...);
2043}
2044
2045/// For each edge in the given graph, apply a list of visitors to the edge,
2046/// stopping when the first visitor's visitEdge method returns true.
2047///
2048/// Only visits edges that were in the graph at call time: if any visitor
2049/// adds new edges those will not be visited. Visitors are not allowed to
2050/// remove edges (though they can change their kind, target, and addend).
2051template <typename... VisitorTs>
2052void visitExistingEdges(LinkGraph &G, VisitorTs &&...Vs) {
2053 // We may add new blocks during this process, but we don't want to iterate
2054 // over them, so build a worklist.
2055 std::vector<Block *> Worklist(G.blocks().begin(), G.blocks().end());
2056
2057 for (auto *B : Worklist)
2058 for (auto &E : B->edges())
2059 visitEdge(G, B, E, std::forward<VisitorTs>(Vs)...);
2060}
2061
2062/// Create a LinkGraph from the given object buffer.
2063///
2064/// Note: The graph does not take ownership of the underlying buffer, nor copy
2065/// its contents. The caller is responsible for ensuring that the object buffer
2066/// outlives the graph.
2069 std::shared_ptr<orc::SymbolStringPool> SSP);
2070
2071/// Create a \c LinkGraph defining the given absolute symbols.
2072LLVM_ABI std::unique_ptr<LinkGraph>
2073absoluteSymbolsLinkGraph(Triple TT, std::shared_ptr<orc::SymbolStringPool> SSP,
2074 orc::SymbolMap Symbols);
2075
2076/// Link the given graph.
2077LLVM_ABI void link(std::unique_ptr<LinkGraph> G,
2078 std::unique_ptr<JITLinkContext> Ctx);
2079
2080} // end namespace jitlink
2081} // end namespace llvm
2082
2083#endif // LLVM_EXECUTIONENGINE_JITLINK_JITLINK_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_ABI
Definition: Compiler.h:213
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
T Content
uint64_t Addr
std::string Name
uint64_t Size
static void addSymbol(Object &Obj, const NewSymbolInfo &SymInfo, uint8_t DefaultVisibility)
Definition: ELFObjcopy.cpp:560
RelaxConfig Config
Definition: ELF_riscv.cpp:506
DenseMap< Block *, BlockRelaxAux > Blocks
Definition: ELF_riscv.cpp:507
uint64_t Offset
Definition: ELF_riscv.cpp:478
Symbol * Sym
Definition: ELF_riscv.cpp:479
static void makeAbsolute(SmallVectorImpl< char > &Path)
Make Path absolute.
This file provides a collection of function (or more generally, callable) type erasure utilities supp...
#define I(x, y, z)
Definition: MD5.cpp:58
#define G(x, y, z)
Definition: MD5.cpp:56
#define T
Basic Register Allocator
std::unordered_set< BasicBlock * > BlockSet
This file contains some templates that are useful if you are working with the STL at all.
raw_pwrite_stream & OS
static Split data
Value * RHS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:147
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Definition: ArrayRef.h:191
Provides read only access to a subclass of BinaryStream.
Provides write only access to a subclass of WritableBinaryStream.
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
BucketT value_type
Definition: DenseMap.h:72
Implements a dense probed hash-table based set.
Definition: DenseSet.h:263
Base class for user error types.
Definition: Error.h:354
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
static ErrorSuccess success()
Create a success value.
Definition: Error.h:336
Tagged union holding either a T or a Error.
Definition: Error.h:485
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:303
T * data() const
Definition: ArrayRef.h:345
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
iterator end()
Definition: StringMap.h:224
iterator begin()
Definition: StringMap.h:223
bool contains(StringRef Key) const
contains - Return true if the element is in the map, false otherwise.
Definition: StringMap.h:277
StringMapIterator< Symbol * > iterator
Definition: StringMap.h:221
void erase(iterator I)
Definition: StringMap.h:419
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:312
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Manages the enabling and disabling of subtarget specific features.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:47
unsigned getArchPointerBitWidth() const
Returns the pointer width of this architecture.
Definition: Triple.h:513
LLVM_ABI bool isLittleEndian() const
Tests whether the target triple is little endian.
Definition: Triple.cpp:2062
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition: Triple.h:408
static LLVM_ABI unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch)
Returns the pointer width of this architecture.
Definition: Triple.cpp:1678
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:82
LLVM Value Representation.
Definition: Value.h:75
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:194
DenseSetIterator< false > iterator
Definition: DenseSet.h:154
size_type size() const
Definition: DenseSet.h:87
DenseSetIterator< true > const_iterator
Definition: DenseSet.h:155
bool erase(const ValueT &V)
Definition: DenseSet.h:100
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition: DenseSet.h:174
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition: iterator.h:80
A range adaptor for a pair of iterators.
Represents an address in the executor process.
uint64_t getValue() const
Base class for both owning and non-owning symbol-string ptrs.
Pointer to a pooled string representing a symbol name.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
unique_function is a type-erasing functor similar to std::function.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
std::vector< AllocActionCallPair > AllocActions
A vector of allocation actions to be run for this allocation.
MemProt
Describes Read/Write/Exec permissions for memory.
Definition: MemoryFlags.h:27
uint64_t ExecutorAddrDiff
MemLifetime
Describes a memory lifetime policy for memory to be allocated by a JITLinkMemoryManager.
Definition: MemoryFlags.h:75
@ Standard
Standard memory should be allocated by the allocator and then deallocated when the deallocate method ...
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1702
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
Definition: MathExtras.h:293
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
Definition: bit.h:157
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1758
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Definition: STLExtras.h:581
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition: Allocator.h:383
OutputIt copy(R &&Range, OutputIt Out)
Definition: STLExtras.h:1854
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:1886
endianness
Definition: bit.h:71
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
#define N
Represents an address range in the exceutor process.