LLVM 20.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"
18#include "llvm/ADT/MapVector.h"
20#include "llvm/ADT/STLExtras.h"
30#include "llvm/Support/Endian.h"
31#include "llvm/Support/Error.h"
37#include <optional>
38
39#include <map>
40#include <string>
41#include <system_error>
42
43namespace llvm {
44namespace jitlink {
45
46class LinkGraph;
47class Symbol;
48class Section;
49
50/// Base class for errors originating in JIT linker, e.g. missing relocation
51/// support.
52class JITLinkError : public ErrorInfo<JITLinkError> {
53public:
54 static char ID;
55
56 JITLinkError(Twine ErrMsg) : ErrMsg(ErrMsg.str()) {}
57
58 void log(raw_ostream &OS) const override;
59 const std::string &getErrorMessage() const { return ErrMsg; }
60 std::error_code convertToErrorCode() const override;
61
62private:
63 std::string ErrMsg;
64};
65
66/// Represents fixups and constraints in the LinkGraph.
67class Edge {
68public:
69 using Kind = uint8_t;
70
72 Invalid, // Invalid edge value.
73 FirstKeepAlive, // Keeps target alive. Offset/addend zero.
74 KeepAlive = FirstKeepAlive, // Tag first edge kind that preserves liveness.
75 FirstRelocation // First architecture specific relocation.
76 };
77
79 using AddendT = int64_t;
80
81 Edge(Kind K, OffsetT Offset, Symbol &Target, AddendT Addend)
82 : Target(&Target), Offset(Offset), Addend(Addend), K(K) {}
83
84 OffsetT getOffset() const { return Offset; }
85 void setOffset(OffsetT Offset) { this->Offset = Offset; }
86 Kind getKind() const { return K; }
87 void setKind(Kind K) { this->K = K; }
88 bool isRelocation() const { return K >= FirstRelocation; }
90 assert(isRelocation() && "Not a relocation edge");
91 return K - FirstRelocation;
92 }
93 bool isKeepAlive() const { return K >= FirstKeepAlive; }
94 Symbol &getTarget() const { return *Target; }
95 void setTarget(Symbol &Target) { this->Target = &Target; }
96 AddendT getAddend() const { return Addend; }
97 void setAddend(AddendT Addend) { this->Addend = Addend; }
98
99private:
100 Symbol *Target = nullptr;
101 OffsetT Offset = 0;
102 AddendT Addend = 0;
103 Kind K = 0;
104};
105
106/// Returns the string name of the given generic edge kind, or "unknown"
107/// otherwise. Useful for debugging.
109
110/// Base class for Addressable entities (externals, absolutes, blocks).
112 friend class LinkGraph;
113
114protected:
115 Addressable(orc::ExecutorAddr Address, bool IsDefined)
116 : Address(Address), IsDefined(IsDefined), IsAbsolute(false) {}
117
119 : Address(Address), IsDefined(false), IsAbsolute(true) {
120 assert(!(IsDefined && IsAbsolute) &&
121 "Block cannot be both defined and absolute");
122 }
123
124public:
125 Addressable(const Addressable &) = delete;
126 Addressable &operator=(const Addressable &) = default;
129
130 orc::ExecutorAddr getAddress() const { return Address; }
131 void setAddress(orc::ExecutorAddr Address) { this->Address = Address; }
132
133 /// Returns true if this is a defined addressable, in which case you
134 /// can downcast this to a Block.
135 bool isDefined() const { return static_cast<bool>(IsDefined); }
136 bool isAbsolute() const { return static_cast<bool>(IsAbsolute); }
137
138private:
139 void setAbsolute(bool IsAbsolute) {
140 assert(!IsDefined && "Cannot change the Absolute flag on a defined block");
141 this->IsAbsolute = IsAbsolute;
142 }
143
144 orc::ExecutorAddr Address;
145 uint64_t IsDefined : 1;
146 uint64_t IsAbsolute : 1;
147
148protected:
149 // bitfields for Block, allocated here to improve packing.
153};
154
156
157/// An Addressable with content and edges.
158class Block : public Addressable {
159 friend class LinkGraph;
160
161private:
162 /// Create a zero-fill defined addressable.
165 : Addressable(Address, true), Parent(&Parent), Size(Size) {
166 assert(isPowerOf2_64(Alignment) && "Alignment must be power of 2");
167 assert(AlignmentOffset < Alignment &&
168 "Alignment offset cannot exceed alignment");
169 assert(AlignmentOffset <= MaxAlignmentOffset &&
170 "Alignment offset exceeds maximum");
171 ContentMutable = false;
172 P2Align = Alignment ? llvm::countr_zero(Alignment) : 0;
173 this->AlignmentOffset = AlignmentOffset;
174 }
175
176 /// Create a defined addressable for the given content.
177 /// The Content is assumed to be non-writable, and will be copied when
178 /// mutations are required.
181 : Addressable(Address, true), Parent(&Parent), Data(Content.data()),
182 Size(Content.size()) {
183 assert(isPowerOf2_64(Alignment) && "Alignment must be power of 2");
184 assert(AlignmentOffset < Alignment &&
185 "Alignment offset cannot exceed alignment");
186 assert(AlignmentOffset <= MaxAlignmentOffset &&
187 "Alignment offset exceeds maximum");
188 ContentMutable = false;
189 P2Align = Alignment ? llvm::countr_zero(Alignment) : 0;
190 this->AlignmentOffset = AlignmentOffset;
191 }
192
193 /// Create a defined addressable for the given content.
194 /// The content is assumed to be writable, and the caller is responsible
195 /// for ensuring that it lives for the duration of the Block's lifetime.
196 /// The standard way to achieve this is to allocate it on the Graph's
197 /// allocator.
198 Block(Section &Parent, MutableArrayRef<char> Content,
200 : Addressable(Address, true), Parent(&Parent), Data(Content.data()),
201 Size(Content.size()) {
202 assert(isPowerOf2_64(Alignment) && "Alignment must be power of 2");
203 assert(AlignmentOffset < Alignment &&
204 "Alignment offset cannot exceed alignment");
205 assert(AlignmentOffset <= MaxAlignmentOffset &&
206 "Alignment offset exceeds maximum");
207 ContentMutable = true;
208 P2Align = Alignment ? llvm::countr_zero(Alignment) : 0;
209 this->AlignmentOffset = AlignmentOffset;
210 }
211
212public:
213 using EdgeVector = std::vector<Edge>;
214 using edge_iterator = EdgeVector::iterator;
215 using const_edge_iterator = EdgeVector::const_iterator;
216
217 Block(const Block &) = delete;
218 Block &operator=(const Block &) = delete;
219 Block(Block &&) = delete;
220 Block &operator=(Block &&) = delete;
221
222 /// Return the parent section for this block.
223 Section &getSection() const { return *Parent; }
224
225 /// Returns true if this is a zero-fill block.
226 ///
227 /// If true, getSize is callable but getContent is not (the content is
228 /// defined to be a sequence of zero bytes of length Size).
229 bool isZeroFill() const { return !Data; }
230
231 /// Returns the size of this defined addressable.
232 size_t getSize() const { return Size; }
233
234 /// Returns the address range of this defined addressable.
237 }
238
239 /// Get the content for this block. Block must not be a zero-fill block.
241 assert(Data && "Block does not contain content");
242 return ArrayRef<char>(Data, Size);
243 }
244
245 /// Set the content for this block.
246 /// Caller is responsible for ensuring the underlying bytes are not
247 /// deallocated while pointed to by this block.
249 assert(Content.data() && "Setting null content");
250 Data = Content.data();
251 Size = Content.size();
252 ContentMutable = false;
253 }
254
255 /// Get mutable content for this block.
256 ///
257 /// If this Block's content is not already mutable this will trigger a copy
258 /// of the existing immutable content to a new, mutable buffer allocated using
259 /// LinkGraph::allocateContent.
261
262 /// Get mutable content for this block.
263 ///
264 /// This block's content must already be mutable. It is a programmatic error
265 /// to call this on a block with immutable content -- consider using
266 /// getMutableContent instead.
268 assert(Data && "Block does not contain content");
269 assert(ContentMutable && "Content is not mutable");
270 return MutableArrayRef<char>(const_cast<char *>(Data), Size);
271 }
272
273 /// Set mutable content for this block.
274 ///
275 /// The caller is responsible for ensuring that the memory pointed to by
276 /// MutableContent is not deallocated while pointed to by this block.
278 assert(MutableContent.data() && "Setting null content");
279 Data = MutableContent.data();
280 Size = MutableContent.size();
281 ContentMutable = true;
282 }
283
284 /// Returns true if this block's content is mutable.
285 ///
286 /// This is primarily useful for asserting that a block is already in a
287 /// mutable state prior to modifying the content. E.g. when applying
288 /// fixups we expect the block to already be mutable as it should have been
289 /// copied to working memory.
290 bool isContentMutable() const { return ContentMutable; }
291
292 /// Get the alignment for this content.
293 uint64_t getAlignment() const { return 1ull << P2Align; }
294
295 /// Set the alignment for this content.
296 void setAlignment(uint64_t Alignment) {
297 assert(isPowerOf2_64(Alignment) && "Alignment must be a power of two");
298 P2Align = Alignment ? llvm::countr_zero(Alignment) : 0;
299 }
300
301 /// Get the alignment offset for this content.
303
304 /// Set the alignment offset for this content.
306 assert(AlignmentOffset < (1ull << P2Align) &&
307 "Alignment offset can't exceed alignment");
308 this->AlignmentOffset = AlignmentOffset;
309 }
310
311 /// Add an edge to this block.
313 Edge::AddendT Addend) {
314 assert((K == Edge::KeepAlive || !isZeroFill()) &&
315 "Adding edge to zero-fill block?");
316 Edges.push_back(Edge(K, Offset, Target, Addend));
317 }
318
319 /// Add an edge by copying an existing one. This is typically used when
320 /// moving edges between blocks.
321 void addEdge(const Edge &E) { Edges.push_back(E); }
322
323 /// Return the list of edges attached to this content.
325 return make_range(Edges.begin(), Edges.end());
326 }
327
328 /// Returns the list of edges attached to this content.
330 return make_range(Edges.begin(), Edges.end());
331 }
332
333 /// Return the size of the edges list.
334 size_t edges_size() const { return Edges.size(); }
335
336 /// Returns true if the list of edges is empty.
337 bool edges_empty() const { return Edges.empty(); }
338
339 /// Remove the edge pointed to by the given iterator.
340 /// Returns an iterator to the new next element.
341 edge_iterator removeEdge(edge_iterator I) { return Edges.erase(I); }
342
343 /// Returns the address of the fixup for the given edge, which is equal to
344 /// this block's address plus the edge's offset.
346 return getAddress() + E.getOffset();
347 }
348
349private:
350 static constexpr uint64_t MaxAlignmentOffset = (1ULL << 56) - 1;
351
352 void setSection(Section &Parent) { this->Parent = &Parent; }
353
354 Section *Parent;
355 const char *Data = nullptr;
356 size_t Size = 0;
357 std::vector<Edge> Edges;
358};
359
360// Align an address to conform with block alignment requirements.
362 uint64_t Delta = (B.getAlignmentOffset() - Addr) % B.getAlignment();
363 return Addr + Delta;
364}
365
366// Align a orc::ExecutorAddr to conform with block alignment requirements.
368 return orc::ExecutorAddr(alignToBlock(Addr.getValue(), B));
369}
370
371// Returns true if the given blocks contains exactly one valid c-string.
372// Zero-fill blocks of size 1 count as valid empty strings. Content blocks
373// must end with a zero, and contain no zeros before the end.
374bool isCStringBlock(Block &B);
375
376/// Describes symbol linkage. This can be used to resolve definition clashes.
377enum class Linkage : uint8_t {
378 Strong,
379 Weak,
380};
381
382/// Holds target-specific properties for a symbol.
383using TargetFlagsType = uint8_t;
384
385/// For errors and debugging output.
386const char *getLinkageName(Linkage L);
387
388/// Defines the scope in which this symbol should be visible:
389/// Default -- Visible in the public interface of the linkage unit.
390/// Hidden -- Visible within the linkage unit, but not exported from it.
391/// Local -- Visible only within the LinkGraph.
392enum class Scope : uint8_t {
393 Default,
394 Hidden,
395 Local
396};
397
398/// For debugging output.
399const char *getScopeName(Scope S);
400
401raw_ostream &operator<<(raw_ostream &OS, const Block &B);
402
403/// Symbol representation.
404///
405/// Symbols represent locations within Addressable objects.
406/// They can be either Named or Anonymous.
407/// Anonymous symbols have neither linkage nor visibility, and must point at
408/// ContentBlocks.
409/// Named symbols may be in one of four states:
410/// - Null: Default initialized. Assignable, but otherwise unusable.
411/// - Defined: Has both linkage and visibility and points to a ContentBlock
412/// - Common: Has both linkage and visibility, points to a null Addressable.
413/// - External: Has neither linkage nor visibility, points to an external
414/// Addressable.
415///
416class Symbol {
417 friend class LinkGraph;
418
419private:
421 orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsLive,
422 bool IsCallable)
423 : Name(Name), Base(&Base), Offset(Offset), WeakRef(0), Size(Size) {
424 assert(Offset <= MaxOffset && "Offset out of range");
425 setLinkage(L);
426 setScope(S);
427 setLive(IsLive);
428 setCallable(IsCallable);
430 }
431
432 static Symbol &constructExternal(BumpPtrAllocator &Allocator,
433 Addressable &Base, StringRef Name,
435 bool WeaklyReferenced) {
436 assert(!Base.isDefined() &&
437 "Cannot create external symbol from defined block");
438 assert(!Name.empty() && "External symbol name cannot be empty");
439 auto *Sym = Allocator.Allocate<Symbol>();
440 new (Sym) Symbol(Base, 0, Name, Size, L, Scope::Default, false, false);
441 Sym->setWeaklyReferenced(WeaklyReferenced);
442 return *Sym;
443 }
444
445 static Symbol &constructAbsolute(BumpPtrAllocator &Allocator,
446 Addressable &Base, StringRef Name,
448 Scope S, bool IsLive) {
449 assert(!Base.isDefined() &&
450 "Cannot create absolute symbol from a defined block");
451 auto *Sym = Allocator.Allocate<Symbol>();
452 new (Sym) Symbol(Base, 0, Name, Size, L, S, IsLive, false);
453 return *Sym;
454 }
455
456 static Symbol &constructAnonDef(BumpPtrAllocator &Allocator, Block &Base,
458 orc::ExecutorAddrDiff Size, bool IsCallable,
459 bool IsLive) {
460 assert((Offset + Size) <= Base.getSize() &&
461 "Symbol extends past end of block");
462 auto *Sym = Allocator.Allocate<Symbol>();
463 new (Sym) Symbol(Base, Offset, StringRef(), Size, Linkage::Strong,
464 Scope::Local, IsLive, IsCallable);
465 return *Sym;
466 }
467
468 static Symbol &constructNamedDef(BumpPtrAllocator &Allocator, Block &Base,
471 Scope S, bool IsLive, bool IsCallable) {
472 assert((Offset + Size) <= Base.getSize() &&
473 "Symbol extends past end of block");
474 assert(!Name.empty() && "Name cannot be empty");
475 auto *Sym = Allocator.Allocate<Symbol>();
476 new (Sym) Symbol(Base, Offset, Name, Size, L, S, IsLive, IsCallable);
477 return *Sym;
478 }
479
480public:
481 /// Create a null Symbol. This allows Symbols to be default initialized for
482 /// use in containers (e.g. as map values). Null symbols are only useful for
483 /// assigning to.
484 Symbol() = default;
485
486 // Symbols are not movable or copyable.
487 Symbol(const Symbol &) = delete;
488 Symbol &operator=(const Symbol &) = delete;
489 Symbol(Symbol &&) = delete;
490 Symbol &operator=(Symbol &&) = delete;
491
492 /// Returns true if this symbol has a name.
493 bool hasName() const { return !Name.empty(); }
494
495 /// Returns the name of this symbol (empty if the symbol is anonymous).
497 assert((!Name.empty() || getScope() == Scope::Local) &&
498 "Anonymous symbol has non-local scope");
499 return Name;
500 }
501
502 /// Rename this symbol. The client is responsible for updating scope and
503 /// linkage if this name-change requires it.
504 void setName(StringRef Name) { this->Name = Name; }
505
506 /// Returns true if this Symbol has content (potentially) defined within this
507 /// object file (i.e. is anything but an external or absolute symbol).
508 bool isDefined() const {
509 assert(Base && "Attempt to access null symbol");
510 return Base->isDefined();
511 }
512
513 /// Returns true if this symbol is live (i.e. should be treated as a root for
514 /// dead stripping).
515 bool isLive() const {
516 assert(Base && "Attempting to access null symbol");
517 return IsLive;
518 }
519
520 /// Set this symbol's live bit.
521 void setLive(bool IsLive) { this->IsLive = IsLive; }
522
523 /// Returns true is this symbol is callable.
524 bool isCallable() const { return IsCallable; }
525
526 /// Set this symbol's callable bit.
527 void setCallable(bool IsCallable) { this->IsCallable = IsCallable; }
528
529 /// Returns true if the underlying addressable is an unresolved external.
530 bool isExternal() const {
531 assert(Base && "Attempt to access null symbol");
532 return !Base->isDefined() && !Base->isAbsolute();
533 }
534
535 /// Returns true if the underlying addressable is an absolute symbol.
536 bool isAbsolute() const {
537 assert(Base && "Attempt to access null symbol");
538 return Base->isAbsolute();
539 }
540
541 /// Return the addressable that this symbol points to.
543 assert(Base && "Cannot get underlying addressable for null symbol");
544 return *Base;
545 }
546
547 /// Return the addressable that this symbol points to.
549 assert(Base && "Cannot get underlying addressable for null symbol");
550 return *Base;
551 }
552
553 /// Return the Block for this Symbol (Symbol must be defined).
555 assert(Base && "Cannot get block for null symbol");
556 assert(Base->isDefined() && "Not a defined symbol");
557 return static_cast<Block &>(*Base);
558 }
559
560 /// Return the Block for this Symbol (Symbol must be defined).
561 const Block &getBlock() const {
562 assert(Base && "Cannot get block for null symbol");
563 assert(Base->isDefined() && "Not a defined symbol");
564 return static_cast<const Block &>(*Base);
565 }
566
567 /// Returns the offset for this symbol within the underlying addressable.
569
571 assert(NewOffset <= getBlock().getSize() && "Offset out of range");
572 Offset = NewOffset;
573 }
574
575 /// Returns the address of this symbol.
576 orc::ExecutorAddr getAddress() const { return Base->getAddress() + Offset; }
577
578 /// Returns the size of this symbol.
580
581 /// Set the size of this symbol.
583 assert(Base && "Cannot set size for null Symbol");
584 assert((Size == 0 || Base->isDefined()) &&
585 "Non-zero size can only be set for defined symbols");
586 assert((Offset + Size <= static_cast<const Block &>(*Base).getSize()) &&
587 "Symbol size cannot extend past the end of its containing block");
588 this->Size = Size;
589 }
590
591 /// Returns the address range of this symbol.
594 }
595
596 /// Returns true if this symbol is backed by a zero-fill block.
597 /// This method may only be called on defined symbols.
598 bool isSymbolZeroFill() const { return getBlock().isZeroFill(); }
599
600 /// Returns the content in the underlying block covered by this symbol.
601 /// This method may only be called on defined non-zero-fill symbols.
603 return getBlock().getContent().slice(Offset, Size);
604 }
605
606 /// Get the linkage for this Symbol.
607 Linkage getLinkage() const { return static_cast<Linkage>(L); }
608
609 /// Set the linkage for this Symbol.
611 assert((L == Linkage::Strong || (!Base->isAbsolute() && !Name.empty())) &&
612 "Linkage can only be applied to defined named symbols");
613 this->L = static_cast<uint8_t>(L);
614 }
615
616 /// Get the visibility for this Symbol.
617 Scope getScope() const { return static_cast<Scope>(S); }
618
619 /// Set the visibility for this Symbol.
620 void setScope(Scope S) {
621 assert((!Name.empty() || S == Scope::Local) &&
622 "Can not set anonymous symbol to non-local scope");
623 assert((S != Scope::Local || Base->isDefined() || Base->isAbsolute()) &&
624 "Invalid visibility for symbol type");
625 this->S = static_cast<uint8_t>(S);
626 }
627
628 /// Get the target flags of this Symbol.
629 TargetFlagsType getTargetFlags() const { return TargetFlags; }
630
631 /// Set the target flags for this Symbol.
633 assert(Flags <= 1 && "Add more bits to store more than single flag");
634 TargetFlags = Flags;
635 }
636
637 /// Returns true if this is a weakly referenced external symbol.
638 /// This method may only be called on external symbols.
639 bool isWeaklyReferenced() const {
640 assert(isExternal() && "isWeaklyReferenced called on non-external");
641 return WeakRef;
642 }
643
644 /// Set the WeaklyReferenced value for this symbol.
645 /// This method may only be called on external symbols.
646 void setWeaklyReferenced(bool WeakRef) {
647 assert(isExternal() && "setWeaklyReferenced called on non-external");
648 this->WeakRef = WeakRef;
649 }
650
651private:
652 void makeExternal(Addressable &A) {
653 assert(!A.isDefined() && !A.isAbsolute() &&
654 "Attempting to make external with defined or absolute block");
655 Base = &A;
656 Offset = 0;
658 IsLive = 0;
659 // note: Size, Linkage and IsCallable fields left unchanged.
660 }
661
662 void makeAbsolute(Addressable &A) {
663 assert(!A.isDefined() && A.isAbsolute() &&
664 "Attempting to make absolute with defined or external block");
665 Base = &A;
666 Offset = 0;
667 }
668
669 void setBlock(Block &B) { Base = &B; }
670
671 static constexpr uint64_t MaxOffset = (1ULL << 59) - 1;
672
673 // FIXME: A char* or SymbolStringPtr may pack better.
674 StringRef Name;
675 Addressable *Base = nullptr;
676 uint64_t Offset : 57;
677 uint64_t L : 1;
678 uint64_t S : 2;
679 uint64_t IsLive : 1;
680 uint64_t IsCallable : 1;
681 uint64_t WeakRef : 1;
682 uint64_t TargetFlags : 1;
683 size_t Size = 0;
684};
685
686raw_ostream &operator<<(raw_ostream &OS, const Symbol &A);
687
688void printEdge(raw_ostream &OS, const Block &B, const Edge &E,
689 StringRef EdgeKindName);
690
691/// Represents an object file section.
692class Section {
693 friend class LinkGraph;
694
695private:
697 : Name(Name), Prot(Prot), SecOrdinal(SecOrdinal) {}
698
699 using SymbolSet = DenseSet<Symbol *>;
700 using BlockSet = DenseSet<Block *>;
701
702public:
705
708
709 ~Section();
710
711 // Sections are not movable or copyable.
712 Section(const Section &) = delete;
713 Section &operator=(const Section &) = delete;
714 Section(Section &&) = delete;
715 Section &operator=(Section &&) = delete;
716
717 /// Returns the name of this section.
718 StringRef getName() const { return Name; }
719
720 /// Returns the protection flags for this section.
721 orc::MemProt getMemProt() const { return Prot; }
722
723 /// Set the protection flags for this section.
724 void setMemProt(orc::MemProt Prot) { this->Prot = Prot; }
725
726 /// Get the memory lifetime policy for this section.
728
729 /// Set the memory lifetime policy for this section.
730 void setMemLifetime(orc::MemLifetime ML) { this->ML = ML; }
731
732 /// Returns the ordinal for this section.
733 SectionOrdinal getOrdinal() const { return SecOrdinal; }
734
735 /// Returns true if this section is empty (contains no blocks or symbols).
736 bool empty() const { return Blocks.empty(); }
737
738 /// Returns an iterator over the blocks defined in this section.
740 return make_range(Blocks.begin(), Blocks.end());
741 }
742
743 /// Returns an iterator over the blocks defined in this section.
745 return make_range(Blocks.begin(), Blocks.end());
746 }
747
748 /// Returns the number of blocks in this section.
749 BlockSet::size_type blocks_size() const { return Blocks.size(); }
750
751 /// Returns an iterator over the symbols defined in this section.
753 return make_range(Symbols.begin(), Symbols.end());
754 }
755
756 /// Returns an iterator over the symbols defined in this section.
758 return make_range(Symbols.begin(), Symbols.end());
759 }
760
761 /// Return the number of symbols in this section.
762 SymbolSet::size_type symbols_size() const { return Symbols.size(); }
763
764private:
765 void addSymbol(Symbol &Sym) {
766 assert(!Symbols.count(&Sym) && "Symbol is already in this section");
767 Symbols.insert(&Sym);
768 }
769
770 void removeSymbol(Symbol &Sym) {
771 assert(Symbols.count(&Sym) && "symbol is not in this section");
772 Symbols.erase(&Sym);
773 }
774
775 void addBlock(Block &B) {
776 assert(!Blocks.count(&B) && "Block is already in this section");
777 Blocks.insert(&B);
778 }
779
780 void removeBlock(Block &B) {
781 assert(Blocks.count(&B) && "Block is not in this section");
782 Blocks.erase(&B);
783 }
784
785 void transferContentTo(Section &DstSection) {
786 if (&DstSection == this)
787 return;
788 for (auto *S : Symbols)
789 DstSection.addSymbol(*S);
790 for (auto *B : Blocks)
791 DstSection.addBlock(*B);
792 Symbols.clear();
793 Blocks.clear();
794 }
795
796 StringRef Name;
797 orc::MemProt Prot;
799 SectionOrdinal SecOrdinal = 0;
800 BlockSet Blocks;
801 SymbolSet Symbols;
802};
803
804/// Represents a section address range via a pair of Block pointers
805/// to the first and last Blocks in the section.
807public:
808 SectionRange() = default;
809 SectionRange(const Section &Sec) {
810 if (Sec.blocks().empty())
811 return;
812 First = Last = *Sec.blocks().begin();
813 for (auto *B : Sec.blocks()) {
814 if (B->getAddress() < First->getAddress())
815 First = B;
816 if (B->getAddress() > Last->getAddress())
817 Last = B;
818 }
819 }
821 assert((!Last || First) && "First can not be null if end is non-null");
822 return First;
823 }
825 assert((First || !Last) && "Last can not be null if start is non-null");
826 return Last;
827 }
828 bool empty() const {
829 assert((First || !Last) && "Last can not be null if start is non-null");
830 return !First;
831 }
833 return First ? First->getAddress() : orc::ExecutorAddr();
834 }
836 return Last ? Last->getAddress() + Last->getSize() : orc::ExecutorAddr();
837 }
839
842 }
843
844private:
845 Block *First = nullptr;
846 Block *Last = nullptr;
847};
848
850private:
855
856 template <typename... ArgTs>
857 Addressable &createAddressable(ArgTs &&... Args) {
858 Addressable *A =
859 reinterpret_cast<Addressable *>(Allocator.Allocate<Addressable>());
860 new (A) Addressable(std::forward<ArgTs>(Args)...);
861 return *A;
862 }
863
864 void destroyAddressable(Addressable &A) {
865 A.~Addressable();
866 Allocator.Deallocate(&A);
867 }
868
869 template <typename... ArgTs> Block &createBlock(ArgTs &&... Args) {
870 Block *B = reinterpret_cast<Block *>(Allocator.Allocate<Block>());
871 new (B) Block(std::forward<ArgTs>(Args)...);
872 B->getSection().addBlock(*B);
873 return *B;
874 }
875
876 void destroyBlock(Block &B) {
877 B.~Block();
878 Allocator.Deallocate(&B);
879 }
880
881 void destroySymbol(Symbol &S) {
882 S.~Symbol();
883 Allocator.Deallocate(&S);
884 }
885
886 static iterator_range<Section::block_iterator> getSectionBlocks(Section &S) {
887 return S.blocks();
888 }
889
891 getSectionConstBlocks(const Section &S) {
892 return S.blocks();
893 }
894
896 getSectionSymbols(Section &S) {
897 return S.symbols();
898 }
899
901 getSectionConstSymbols(const Section &S) {
902 return S.symbols();
903 }
904
905 struct GetExternalSymbolMapEntryValue {
906 Symbol *operator()(ExternalSymbolMap::value_type &KV) const {
907 return KV.second;
908 }
909 };
910
911 struct GetSectionMapEntryValue {
912 Section &operator()(SectionMap::value_type &KV) const { return *KV.second; }
913 };
914
915 struct GetSectionMapEntryConstValue {
916 const Section &operator()(const SectionMap::value_type &KV) const {
917 return *KV.second;
918 }
919 };
920
921public:
924 GetExternalSymbolMapEntryValue>;
926
931
932 template <typename OuterItrT, typename InnerItrT, typename T,
933 iterator_range<InnerItrT> getInnerRange(
934 typename OuterItrT::reference)>
936 : public iterator_facade_base<
937 nested_collection_iterator<OuterItrT, InnerItrT, T, getInnerRange>,
938 std::forward_iterator_tag, T> {
939 public:
941
942 nested_collection_iterator(OuterItrT OuterI, OuterItrT OuterE)
943 : OuterI(OuterI), OuterE(OuterE),
944 InnerI(getInnerBegin(OuterI, OuterE)) {
945 moveToNonEmptyInnerOrEnd();
946 }
947
949 return (OuterI == RHS.OuterI) && (InnerI == RHS.InnerI);
950 }
951
952 T operator*() const {
953 assert(InnerI != getInnerRange(*OuterI).end() && "Dereferencing end?");
954 return *InnerI;
955 }
956
958 ++InnerI;
959 moveToNonEmptyInnerOrEnd();
960 return *this;
961 }
962
963 private:
964 static InnerItrT getInnerBegin(OuterItrT OuterI, OuterItrT OuterE) {
965 return OuterI != OuterE ? getInnerRange(*OuterI).begin() : InnerItrT();
966 }
967
968 void moveToNonEmptyInnerOrEnd() {
969 while (OuterI != OuterE && InnerI == getInnerRange(*OuterI).end()) {
970 ++OuterI;
971 InnerI = getInnerBegin(OuterI, OuterE);
972 }
973 }
974
975 OuterItrT OuterI, OuterE;
976 InnerItrT InnerI;
977 };
978
981 Symbol *, getSectionSymbols>;
982
986 getSectionConstSymbols>;
987
990 Block *, getSectionBlocks>;
991
995 getSectionConstBlocks>;
996
997 using GetEdgeKindNameFunction = const char *(*)(Edge::Kind);
998
999 LinkGraph(std::string Name, const Triple &TT, SubtargetFeatures Features,
1000 unsigned PointerSize, llvm::endianness Endianness,
1001 GetEdgeKindNameFunction GetEdgeKindName)
1002 : Name(std::move(Name)), TT(TT), Features(std::move(Features)),
1003 PointerSize(PointerSize), Endianness(Endianness),
1004 GetEdgeKindName(std::move(GetEdgeKindName)) {}
1005
1006 LinkGraph(std::string Name, const Triple &TT, unsigned PointerSize,
1007 llvm::endianness Endianness,
1008 GetEdgeKindNameFunction GetEdgeKindName)
1009 : LinkGraph(std::move(Name), TT, SubtargetFeatures(), PointerSize,
1010 Endianness, GetEdgeKindName) {}
1011
1012 LinkGraph(std::string Name, const Triple &TT,
1013 GetEdgeKindNameFunction GetEdgeKindName)
1014 : LinkGraph(std::move(Name), TT, SubtargetFeatures(),
1015 Triple::getArchPointerBitWidth(TT.getArch()) / 8,
1016 TT.isLittleEndian() ? endianness::little : endianness::big,
1017 GetEdgeKindName) {
1018 assert(!(Triple::getArchPointerBitWidth(TT.getArch()) % 8) &&
1019 "Arch bitwidth is not a multiple of 8");
1020 }
1021
1022 LinkGraph(const LinkGraph &) = delete;
1023 LinkGraph &operator=(const LinkGraph &) = delete;
1024 LinkGraph(LinkGraph &&) = delete;
1026
1027 /// Returns the name of this graph (usually the name of the original
1028 /// underlying MemoryBuffer).
1029 const std::string &getName() const { return Name; }
1030
1031 /// Returns the target triple for this Graph.
1032 const Triple &getTargetTriple() const { return TT; }
1033
1034 /// Return the subtarget features for this Graph.
1035 const SubtargetFeatures &getFeatures() const { return Features; }
1036
1037 /// Returns the pointer size for use in this graph.
1038 unsigned getPointerSize() const { return PointerSize; }
1039
1040 /// Returns the endianness of content in this graph.
1041 llvm::endianness getEndianness() const { return Endianness; }
1042
1043 const char *getEdgeKindName(Edge::Kind K) const { return GetEdgeKindName(K); }
1044
1045 /// Allocate a mutable buffer of the given size using the LinkGraph's
1046 /// allocator.
1048 return {Allocator.Allocate<char>(Size), Size};
1049 }
1050
1051 /// Allocate a copy of the given string using the LinkGraph's allocator.
1052 /// This can be useful when renaming symbols or adding new content to the
1053 /// graph.
1055 auto *AllocatedBuffer = Allocator.Allocate<char>(Source.size());
1056 llvm::copy(Source, AllocatedBuffer);
1057 return MutableArrayRef<char>(AllocatedBuffer, Source.size());
1058 }
1059
1060 /// Allocate a copy of the given string using the LinkGraph's allocator.
1061 /// This can be useful when renaming symbols or adding new content to the
1062 /// graph.
1063 ///
1064 /// Note: This Twine-based overload requires an extra string copy and an
1065 /// extra heap allocation for large strings. The ArrayRef<char> overload
1066 /// should be preferred where possible.
1068 SmallString<256> TmpBuffer;
1069 auto SourceStr = Source.toStringRef(TmpBuffer);
1070 auto *AllocatedBuffer = Allocator.Allocate<char>(SourceStr.size());
1071 llvm::copy(SourceStr, AllocatedBuffer);
1072 return MutableArrayRef<char>(AllocatedBuffer, SourceStr.size());
1073 }
1074
1075 /// Allocate a copy of the given string using the LinkGraph's allocator.
1076 ///
1077 /// The allocated string will be terminated with a null character, and the
1078 /// returned MutableArrayRef will include this null character in the last
1079 /// position.
1081 char *AllocatedBuffer = Allocator.Allocate<char>(Source.size() + 1);
1082 llvm::copy(Source, AllocatedBuffer);
1083 AllocatedBuffer[Source.size()] = '\0';
1084 return MutableArrayRef<char>(AllocatedBuffer, Source.size() + 1);
1085 }
1086
1087 /// Allocate a copy of the given string using the LinkGraph's allocator.
1088 ///
1089 /// The allocated string will be terminated with a null character, and the
1090 /// returned MutableArrayRef will include this null character in the last
1091 /// position.
1092 ///
1093 /// Note: This Twine-based overload requires an extra string copy and an
1094 /// extra heap allocation for large strings. The ArrayRef<char> overload
1095 /// should be preferred where possible.
1097 SmallString<256> TmpBuffer;
1098 auto SourceStr = Source.toStringRef(TmpBuffer);
1099 auto *AllocatedBuffer = Allocator.Allocate<char>(SourceStr.size() + 1);
1100 llvm::copy(SourceStr, AllocatedBuffer);
1101 AllocatedBuffer[SourceStr.size()] = '\0';
1102 return MutableArrayRef<char>(AllocatedBuffer, SourceStr.size() + 1);
1103 }
1104
1105 /// Create a section with the given name, protection flags, and alignment.
1107 assert(!Sections.count(Name) && "Duplicate section name");
1108 std::unique_ptr<Section> Sec(new Section(Name, Prot, Sections.size()));
1109 return *Sections.insert(std::make_pair(Name, std::move(Sec))).first->second;
1110 }
1111
1112 /// Create a content block.
1115 uint64_t AlignmentOffset) {
1116 return createBlock(Parent, Content, Address, Alignment, AlignmentOffset);
1117 }
1118
1119 /// Create a content block with initially mutable data.
1121 MutableArrayRef<char> MutableContent,
1123 uint64_t Alignment,
1124 uint64_t AlignmentOffset) {
1125 return createBlock(Parent, MutableContent, Address, Alignment,
1126 AlignmentOffset);
1127 }
1128
1129 /// Create a content block with initially mutable data of the given size.
1130 /// Content will be allocated via the LinkGraph's allocateBuffer method.
1131 /// By default the memory will be zero-initialized. Passing false for
1132 /// ZeroInitialize will prevent this.
1133 Block &createMutableContentBlock(Section &Parent, size_t ContentSize,
1135 uint64_t Alignment, uint64_t AlignmentOffset,
1136 bool ZeroInitialize = true) {
1137 auto Content = allocateBuffer(ContentSize);
1138 if (ZeroInitialize)
1139 memset(Content.data(), 0, Content.size());
1140 return createBlock(Parent, Content, Address, Alignment, AlignmentOffset);
1141 }
1142
1143 /// Create a zero-fill block.
1146 uint64_t AlignmentOffset) {
1147 return createBlock(Parent, Size, Address, Alignment, AlignmentOffset);
1148 }
1149
1150 /// Returns a BinaryStreamReader for the given block.
1153 reinterpret_cast<const uint8_t *>(B.getContent().data()), B.getSize());
1155 }
1156
1157 /// Returns a BinaryStreamWriter for the given block.
1158 /// This will call getMutableContent to obtain mutable content for the block.
1161 reinterpret_cast<uint8_t *>(B.getMutableContent(*this).data()),
1162 B.getSize());
1164 }
1165
1166 /// Cache type for the splitBlock function.
1167 using SplitBlockCache = std::optional<SmallVector<Symbol *, 8>>;
1168
1169 /// Splits block B at the given index which must be greater than zero.
1170 /// If SplitIndex == B.getSize() then this function is a no-op and returns B.
1171 /// If SplitIndex < B.getSize() then this function returns a new block
1172 /// covering the range [ 0, SplitIndex ), and B is modified to cover the range
1173 /// [ SplitIndex, B.size() ).
1174 ///
1175 /// The optional Cache parameter can be used to speed up repeated calls to
1176 /// splitBlock for a single block. If the value is None the cache will be
1177 /// treated as uninitialized and splitBlock will populate it. Otherwise it
1178 /// is assumed to contain the list of Symbols pointing at B, sorted in
1179 /// descending order of offset.
1180 ///
1181 /// Notes:
1182 ///
1183 /// 1. splitBlock must be used with care. Splitting a block may cause
1184 /// incoming edges to become invalid if the edge target subexpression
1185 /// points outside the bounds of the newly split target block (E.g. an
1186 /// edge 'S + 10 : Pointer64' where S points to a newly split block
1187 /// whose size is less than 10). No attempt is made to detect invalidation
1188 /// of incoming edges, as in general this requires context that the
1189 /// LinkGraph does not have. Clients are responsible for ensuring that
1190 /// splitBlock is not used in a way that invalidates edges.
1191 ///
1192 /// 2. The newly introduced block will have a new ordinal which will be
1193 /// higher than any other ordinals in the section. Clients are responsible
1194 /// for re-assigning block ordinals to restore a compatible order if
1195 /// needed.
1196 ///
1197 /// 3. The cache is not automatically updated if new symbols are introduced
1198 /// between calls to splitBlock. Any newly introduced symbols may be
1199 /// added to the cache manually (descending offset order must be
1200 /// preserved), or the cache can be set to None and rebuilt by
1201 /// splitBlock on the next call.
1202 Block &splitBlock(Block &B, size_t SplitIndex,
1203 SplitBlockCache *Cache = nullptr);
1204
1205 /// Add an external symbol.
1206 /// Some formats (e.g. ELF) allow Symbols to have sizes. For Symbols whose
1207 /// size is not known, you should substitute '0'.
1208 /// The IsWeaklyReferenced argument determines whether the symbol must be
1209 /// present during lookup: Externals that are strongly referenced must be
1210 /// found or an error will be emitted. Externals that are weakly referenced
1211 /// are permitted to be undefined, in which case they are assigned an address
1212 /// of 0.
1214 bool IsWeaklyReferenced) {
1215 assert(!ExternalSymbols.contains(Name) && "Duplicate external symbol");
1216 auto &Sym = Symbol::constructExternal(
1217 Allocator, createAddressable(orc::ExecutorAddr(), false), Name, Size,
1218 Linkage::Strong, IsWeaklyReferenced);
1219 ExternalSymbols.insert({Sym.getName(), &Sym});
1220 return Sym;
1221 }
1222
1223 /// Add an absolute symbol.
1226 bool IsLive) {
1227 assert((S == Scope::Local || llvm::count_if(AbsoluteSymbols,
1228 [&](const Symbol *Sym) {
1229 return Sym->getName() == Name;
1230 }) == 0) &&
1231 "Duplicate absolute symbol");
1232 auto &Sym = Symbol::constructAbsolute(Allocator, createAddressable(Address),
1233 Name, Size, L, S, IsLive);
1234 AbsoluteSymbols.insert(&Sym);
1235 return Sym;
1236 }
1237
1238 /// Add an anonymous symbol.
1240 orc::ExecutorAddrDiff Size, bool IsCallable,
1241 bool IsLive) {
1242 auto &Sym = Symbol::constructAnonDef(Allocator, Content, Offset, Size,
1243 IsCallable, IsLive);
1244 Content.getSection().addSymbol(Sym);
1245 return Sym;
1246 }
1247
1248 /// Add a named symbol.
1251 Linkage L, Scope S, bool IsCallable, bool IsLive) {
1253 [&](const Symbol *Sym) {
1254 return Sym->getName() == Name;
1255 }) == 0) &&
1256 "Duplicate defined symbol");
1257 auto &Sym = Symbol::constructNamedDef(Allocator, Content, Offset, Name,
1258 Size, L, S, IsLive, IsCallable);
1259 Content.getSection().addSymbol(Sym);
1260 return Sym;
1261 }
1262
1264 return make_range(
1265 section_iterator(Sections.begin(), GetSectionMapEntryValue()),
1266 section_iterator(Sections.end(), GetSectionMapEntryValue()));
1267 }
1268
1270 return make_range(
1271 const_section_iterator(Sections.begin(),
1272 GetSectionMapEntryConstValue()),
1273 const_section_iterator(Sections.end(), GetSectionMapEntryConstValue()));
1274 }
1275
1276 size_t sections_size() const { return Sections.size(); }
1277
1278 /// Returns the section with the given name if it exists, otherwise returns
1279 /// null.
1281 auto I = Sections.find(Name);
1282 if (I == Sections.end())
1283 return nullptr;
1284 return I->second.get();
1285 }
1286
1288 auto Secs = sections();
1289 return make_range(block_iterator(Secs.begin(), Secs.end()),
1290 block_iterator(Secs.end(), Secs.end()));
1291 }
1292
1294 auto Secs = sections();
1295 return make_range(const_block_iterator(Secs.begin(), Secs.end()),
1296 const_block_iterator(Secs.end(), Secs.end()));
1297 }
1298
1300 return make_range(
1301 external_symbol_iterator(ExternalSymbols.begin(),
1302 GetExternalSymbolMapEntryValue()),
1303 external_symbol_iterator(ExternalSymbols.end(),
1304 GetExternalSymbolMapEntryValue()));
1305 }
1306
1308 return make_range(AbsoluteSymbols.begin(), AbsoluteSymbols.end());
1309 }
1310
1312 auto Secs = sections();
1313 return make_range(defined_symbol_iterator(Secs.begin(), Secs.end()),
1314 defined_symbol_iterator(Secs.end(), Secs.end()));
1315 }
1316
1318 auto Secs = sections();
1319 return make_range(const_defined_symbol_iterator(Secs.begin(), Secs.end()),
1320 const_defined_symbol_iterator(Secs.end(), Secs.end()));
1321 }
1322
1323 /// Make the given symbol external (must not already be external).
1324 ///
1325 /// Symbol size, linkage and callability will be left unchanged. Symbol scope
1326 /// will be set to Default, and offset will be reset to 0.
1328 assert(!Sym.isExternal() && "Symbol is already external");
1329 if (Sym.isAbsolute()) {
1330 assert(AbsoluteSymbols.count(&Sym) &&
1331 "Sym is not in the absolute symbols set");
1332 assert(Sym.getOffset() == 0 && "Absolute not at offset 0");
1333 AbsoluteSymbols.erase(&Sym);
1334 auto &A = Sym.getAddressable();
1335 A.setAbsolute(false);
1336 A.setAddress(orc::ExecutorAddr());
1337 } else {
1338 assert(Sym.isDefined() && "Sym is not a defined symbol");
1339 Section &Sec = Sym.getBlock().getSection();
1340 Sec.removeSymbol(Sym);
1341 Sym.makeExternal(createAddressable(orc::ExecutorAddr(), false));
1342 }
1343 ExternalSymbols.insert({Sym.getName(), &Sym});
1344 }
1345
1346 /// Make the given symbol an absolute with the given address (must not already
1347 /// be absolute).
1348 ///
1349 /// The symbol's size, linkage, and callability, and liveness will be left
1350 /// unchanged, and its offset will be reset to 0.
1351 ///
1352 /// If the symbol was external then its scope will be set to local, otherwise
1353 /// it will be left unchanged.
1355 assert(!Sym.isAbsolute() && "Symbol is already absolute");
1356 if (Sym.isExternal()) {
1357 assert(ExternalSymbols.contains(Sym.getName()) &&
1358 "Sym is not in the absolute symbols set");
1359 assert(Sym.getOffset() == 0 && "External is not at offset 0");
1360 ExternalSymbols.erase(Sym.getName());
1361 auto &A = Sym.getAddressable();
1362 A.setAbsolute(true);
1363 A.setAddress(Address);
1364 Sym.setScope(Scope::Local);
1365 } else {
1366 assert(Sym.isDefined() && "Sym is not a defined symbol");
1367 Section &Sec = Sym.getBlock().getSection();
1368 Sec.removeSymbol(Sym);
1369 Sym.makeAbsolute(createAddressable(Address));
1370 }
1371 AbsoluteSymbols.insert(&Sym);
1372 }
1373
1374 /// Turn an absolute or external symbol into a defined one by attaching it to
1375 /// a block. Symbol must not already be defined.
1378 bool IsLive) {
1379 assert(!Sym.isDefined() && "Sym is already a defined symbol");
1380 if (Sym.isAbsolute()) {
1381 assert(AbsoluteSymbols.count(&Sym) &&
1382 "Symbol is not in the absolutes set");
1383 AbsoluteSymbols.erase(&Sym);
1384 } else {
1385 assert(ExternalSymbols.contains(Sym.getName()) &&
1386 "Symbol is not in the externals set");
1387 ExternalSymbols.erase(Sym.getName());
1388 }
1389 Addressable &OldBase = *Sym.Base;
1390 Sym.setBlock(Content);
1391 Sym.setOffset(Offset);
1392 Sym.setSize(Size);
1393 Sym.setLinkage(L);
1394 Sym.setScope(S);
1395 Sym.setLive(IsLive);
1396 Content.getSection().addSymbol(Sym);
1397 destroyAddressable(OldBase);
1398 }
1399
1400 /// Transfer a defined symbol from one block to another.
1401 ///
1402 /// The symbol's offset within DestBlock is set to NewOffset.
1403 ///
1404 /// If ExplicitNewSize is given as None then the size of the symbol will be
1405 /// checked and auto-truncated to at most the size of the remainder (from the
1406 /// given offset) of the size of the new block.
1407 ///
1408 /// All other symbol attributes are unchanged.
1409 void
1411 orc::ExecutorAddrDiff NewOffset,
1412 std::optional<orc::ExecutorAddrDiff> ExplicitNewSize) {
1413 auto &OldSection = Sym.getBlock().getSection();
1414 Sym.setBlock(DestBlock);
1415 Sym.setOffset(NewOffset);
1416 if (ExplicitNewSize)
1417 Sym.setSize(*ExplicitNewSize);
1418 else {
1419 auto RemainingBlockSize = DestBlock.getSize() - NewOffset;
1420 if (Sym.getSize() > RemainingBlockSize)
1421 Sym.setSize(RemainingBlockSize);
1422 }
1423 if (&DestBlock.getSection() != &OldSection) {
1424 OldSection.removeSymbol(Sym);
1425 DestBlock.getSection().addSymbol(Sym);
1426 }
1427 }
1428
1429 /// Transfers the given Block and all Symbols pointing to it to the given
1430 /// Section.
1431 ///
1432 /// No attempt is made to check compatibility of the source and destination
1433 /// sections. Blocks may be moved between sections with incompatible
1434 /// permissions (e.g. from data to text). The client is responsible for
1435 /// ensuring that this is safe.
1436 void transferBlock(Block &B, Section &NewSection) {
1437 auto &OldSection = B.getSection();
1438 if (&OldSection == &NewSection)
1439 return;
1440 SmallVector<Symbol *> AttachedSymbols;
1441 for (auto *S : OldSection.symbols())
1442 if (&S->getBlock() == &B)
1443 AttachedSymbols.push_back(S);
1444 for (auto *S : AttachedSymbols) {
1445 OldSection.removeSymbol(*S);
1446 NewSection.addSymbol(*S);
1447 }
1448 OldSection.removeBlock(B);
1449 NewSection.addBlock(B);
1450 }
1451
1452 /// Move all blocks and symbols from the source section to the destination
1453 /// section.
1454 ///
1455 /// If PreserveSrcSection is true (or SrcSection and DstSection are the same)
1456 /// then SrcSection is preserved, otherwise it is removed (the default).
1457 void mergeSections(Section &DstSection, Section &SrcSection,
1458 bool PreserveSrcSection = false) {
1459 if (&DstSection == &SrcSection)
1460 return;
1461 for (auto *B : SrcSection.blocks())
1462 B->setSection(DstSection);
1463 SrcSection.transferContentTo(DstSection);
1464 if (!PreserveSrcSection)
1465 removeSection(SrcSection);
1466 }
1467
1468 /// Removes an external symbol. Also removes the underlying Addressable.
1470 assert(!Sym.isDefined() && !Sym.isAbsolute() &&
1471 "Sym is not an external symbol");
1472 assert(ExternalSymbols.contains(Sym.getName()) &&
1473 "Symbol is not in the externals set");
1474 ExternalSymbols.erase(Sym.getName());
1475 Addressable &Base = *Sym.Base;
1477 [&](Symbol *AS) { return AS->Base == &Base; }) &&
1478 "Base addressable still in use");
1479 destroySymbol(Sym);
1480 destroyAddressable(Base);
1481 }
1482
1483 /// Remove an absolute symbol. Also removes the underlying Addressable.
1485 assert(!Sym.isDefined() && Sym.isAbsolute() &&
1486 "Sym is not an absolute symbol");
1487 assert(AbsoluteSymbols.count(&Sym) &&
1488 "Symbol is not in the absolute symbols set");
1489 AbsoluteSymbols.erase(&Sym);
1490 Addressable &Base = *Sym.Base;
1492 [&](Symbol *AS) { return AS->Base == &Base; }) &&
1493 "Base addressable still in use");
1494 destroySymbol(Sym);
1495 destroyAddressable(Base);
1496 }
1497
1498 /// Removes defined symbols. Does not remove the underlying block.
1500 assert(Sym.isDefined() && "Sym is not a defined symbol");
1501 Sym.getBlock().getSection().removeSymbol(Sym);
1502 destroySymbol(Sym);
1503 }
1504
1505 /// Remove a block. The block reference is defunct after calling this
1506 /// function and should no longer be used.
1508 assert(llvm::none_of(B.getSection().symbols(),
1509 [&](const Symbol *Sym) {
1510 return &Sym->getBlock() == &B;
1511 }) &&
1512 "Block still has symbols attached");
1513 B.getSection().removeBlock(B);
1514 destroyBlock(B);
1515 }
1516
1517 /// Remove a section. The section reference is defunct after calling this
1518 /// function and should no longer be used.
1520 assert(Sections.count(Sec.getName()) && "Section not found");
1521 assert(Sections.find(Sec.getName())->second.get() == &Sec &&
1522 "Section map entry invalid");
1523 Sections.erase(Sec.getName());
1524 }
1525
1526 /// Accessor for the AllocActions object for this graph. This can be used to
1527 /// register allocation action calls prior to finalization.
1528 ///
1529 /// Accessing this object after finalization will result in undefined
1530 /// behavior.
1532
1533 /// Dump the graph.
1534 void dump(raw_ostream &OS);
1535
1536private:
1537 // Put the BumpPtrAllocator first so that we don't free any of the underlying
1538 // memory until the Symbol/Addressable destructors have been run.
1540
1541 std::string Name;
1542 Triple TT;
1543 SubtargetFeatures Features;
1544 unsigned PointerSize;
1545 llvm::endianness Endianness;
1546 GetEdgeKindNameFunction GetEdgeKindName = nullptr;
1548 ExternalSymbolMap ExternalSymbols;
1549 AbsoluteSymbolSet AbsoluteSymbols;
1551};
1552
1554 if (!ContentMutable)
1555 setMutableContent(G.allocateContent({Data, Size}));
1556 return MutableArrayRef<char>(const_cast<char *>(Data), Size);
1557}
1558
1559/// Enables easy lookup of blocks by addresses.
1561public:
1562 using AddrToBlockMap = std::map<orc::ExecutorAddr, Block *>;
1563 using const_iterator = AddrToBlockMap::const_iterator;
1564
1565 /// A block predicate that always adds all blocks.
1566 static bool includeAllBlocks(const Block &B) { return true; }
1567
1568 /// A block predicate that always includes blocks with non-null addresses.
1569 static bool includeNonNull(const Block &B) { return !!B.getAddress(); }
1570
1571 BlockAddressMap() = default;
1572
1573 /// Add a block to the map. Returns an error if the block overlaps with any
1574 /// existing block.
1575 template <typename PredFn = decltype(includeAllBlocks)>
1577 if (!Pred(B))
1578 return Error::success();
1579
1580 auto I = AddrToBlock.upper_bound(B.getAddress());
1581
1582 // If we're not at the end of the map, check for overlap with the next
1583 // element.
1584 if (I != AddrToBlock.end()) {
1585 if (B.getAddress() + B.getSize() > I->second->getAddress())
1586 return overlapError(B, *I->second);
1587 }
1588
1589 // If we're not at the start of the map, check for overlap with the previous
1590 // element.
1591 if (I != AddrToBlock.begin()) {
1592 auto &PrevBlock = *std::prev(I)->second;
1593 if (PrevBlock.getAddress() + PrevBlock.getSize() > B.getAddress())
1594 return overlapError(B, PrevBlock);
1595 }
1596
1597 AddrToBlock.insert(I, std::make_pair(B.getAddress(), &B));
1598 return Error::success();
1599 }
1600
1601 /// Add a block to the map without checking for overlap with existing blocks.
1602 /// The client is responsible for ensuring that the block added does not
1603 /// overlap with any existing block.
1604 void addBlockWithoutChecking(Block &B) { AddrToBlock[B.getAddress()] = &B; }
1605
1606 /// Add a range of blocks to the map. Returns an error if any block in the
1607 /// range overlaps with any other block in the range, or with any existing
1608 /// block in the map.
1609 template <typename BlockPtrRange,
1610 typename PredFn = decltype(includeAllBlocks)>
1611 Error addBlocks(BlockPtrRange &&Blocks, PredFn Pred = includeAllBlocks) {
1612 for (auto *B : Blocks)
1613 if (auto Err = addBlock(*B, Pred))
1614 return Err;
1615 return Error::success();
1616 }
1617
1618 /// Add a range of blocks to the map without checking for overlap with
1619 /// existing blocks. The client is responsible for ensuring that the block
1620 /// added does not overlap with any existing block.
1621 template <typename BlockPtrRange>
1622 void addBlocksWithoutChecking(BlockPtrRange &&Blocks) {
1623 for (auto *B : Blocks)
1625 }
1626
1627 /// Iterates over (Address, Block*) pairs in ascending order of address.
1628 const_iterator begin() const { return AddrToBlock.begin(); }
1629 const_iterator end() const { return AddrToBlock.end(); }
1630
1631 /// Returns the block starting at the given address, or nullptr if no such
1632 /// block exists.
1634 auto I = AddrToBlock.find(Addr);
1635 if (I == AddrToBlock.end())
1636 return nullptr;
1637 return I->second;
1638 }
1639
1640 /// Returns the block covering the given address, or nullptr if no such block
1641 /// exists.
1643 auto I = AddrToBlock.upper_bound(Addr);
1644 if (I == AddrToBlock.begin())
1645 return nullptr;
1646 auto *B = std::prev(I)->second;
1647 if (Addr < B->getAddress() + B->getSize())
1648 return B;
1649 return nullptr;
1650 }
1651
1652private:
1653 Error overlapError(Block &NewBlock, Block &ExistingBlock) {
1654 auto NewBlockEnd = NewBlock.getAddress() + NewBlock.getSize();
1655 auto ExistingBlockEnd =
1656 ExistingBlock.getAddress() + ExistingBlock.getSize();
1657 return make_error<JITLinkError>(
1658 "Block at " +
1659 formatv("{0:x16} -- {1:x16}", NewBlock.getAddress().getValue(),
1660 NewBlockEnd.getValue()) +
1661 " overlaps " +
1662 formatv("{0:x16} -- {1:x16}", ExistingBlock.getAddress().getValue(),
1663 ExistingBlockEnd.getValue()));
1664 }
1665
1666 AddrToBlockMap AddrToBlock;
1667};
1668
1669/// A map of addresses to Symbols.
1671public:
1673
1674 /// Add a symbol to the SymbolAddressMap.
1676 AddrToSymbols[Sym.getAddress()].push_back(&Sym);
1677 }
1678
1679 /// Add all symbols in a given range to the SymbolAddressMap.
1680 template <typename SymbolPtrCollection>
1681 void addSymbols(SymbolPtrCollection &&Symbols) {
1682 for (auto *Sym : Symbols)
1683 addSymbol(*Sym);
1684 }
1685
1686 /// Returns the list of symbols that start at the given address, or nullptr if
1687 /// no such symbols exist.
1689 auto I = AddrToSymbols.find(Addr);
1690 if (I == AddrToSymbols.end())
1691 return nullptr;
1692 return &I->second;
1693 }
1694
1695private:
1696 std::map<orc::ExecutorAddr, SymbolVector> AddrToSymbols;
1697};
1698
1699/// A function for mutating LinkGraphs.
1701
1702/// A list of LinkGraph passes.
1703using LinkGraphPassList = std::vector<LinkGraphPassFunction>;
1704
1705/// An LinkGraph pass configuration, consisting of a list of pre-prune,
1706/// post-prune, and post-fixup passes.
1708
1709 /// Pre-prune passes.
1710 ///
1711 /// These passes are called on the graph after it is built, and before any
1712 /// symbols have been pruned. Graph nodes still have their original vmaddrs.
1713 ///
1714 /// Notable use cases: Marking symbols live or should-discard.
1716
1717 /// Post-prune passes.
1718 ///
1719 /// These passes are called on the graph after dead stripping, but before
1720 /// memory is allocated or nodes assigned their final addresses.
1721 ///
1722 /// Notable use cases: Building GOT, stub, and TLV symbols.
1724
1725 /// Post-allocation passes.
1726 ///
1727 /// These passes are called on the graph after memory has been allocated and
1728 /// defined nodes have been assigned their final addresses, but before the
1729 /// context has been notified of these addresses. At this point externals
1730 /// have not been resolved, and symbol content has not yet been copied into
1731 /// working memory.
1732 ///
1733 /// Notable use cases: Setting up data structures associated with addresses
1734 /// of defined symbols (e.g. a mapping of __dso_handle to JITDylib* for the
1735 /// JIT runtime) -- using a PostAllocationPass for this ensures that the
1736 /// data structures are in-place before any query for resolved symbols
1737 /// can complete.
1739
1740 /// Pre-fixup passes.
1741 ///
1742 /// These passes are called on the graph after memory has been allocated,
1743 /// content copied into working memory, and all nodes (including externals)
1744 /// have been assigned their final addresses, but before any fixups have been
1745 /// applied.
1746 ///
1747 /// Notable use cases: Late link-time optimizations like GOT and stub
1748 /// elimination.
1750
1751 /// Post-fixup passes.
1752 ///
1753 /// These passes are called on the graph after block contents has been copied
1754 /// to working memory, and fixups applied. Blocks have been updated to point
1755 /// to their fixed up content.
1756 ///
1757 /// Notable use cases: Testing and validation.
1759};
1760
1761/// Flags for symbol lookup.
1762///
1763/// FIXME: These basically duplicate orc::SymbolLookupFlags -- We should merge
1764/// the two types once we have an OrcSupport library.
1766
1768
1769/// A map of symbol names to resolved addresses.
1771
1772/// A function object to call with a resolved symbol map (See AsyncLookupResult)
1773/// or an error if resolution failed.
1775public:
1777 virtual void run(Expected<AsyncLookupResult> LR) = 0;
1778
1779private:
1780 virtual void anchor();
1781};
1782
1783/// Create a lookup continuation from a function object.
1784template <typename Continuation>
1785std::unique_ptr<JITLinkAsyncLookupContinuation>
1786createLookupContinuation(Continuation Cont) {
1787
1788 class Impl final : public JITLinkAsyncLookupContinuation {
1789 public:
1790 Impl(Continuation C) : C(std::move(C)) {}
1791 void run(Expected<AsyncLookupResult> LR) override { C(std::move(LR)); }
1792
1793 private:
1794 Continuation C;
1795 };
1796
1797 return std::make_unique<Impl>(std::move(Cont));
1798}
1799
1800/// Holds context for a single jitLink invocation.
1802public:
1804
1805 /// Create a JITLinkContext.
1806 JITLinkContext(const JITLinkDylib *JD) : JD(JD) {}
1807
1808 /// Destroy a JITLinkContext.
1810
1811 /// Return the JITLinkDylib that this link is targeting, if any.
1812 const JITLinkDylib *getJITLinkDylib() const { return JD; }
1813
1814 /// Return the MemoryManager to be used for this link.
1816
1817 /// Notify this context that linking failed.
1818 /// Called by JITLink if linking cannot be completed.
1819 virtual void notifyFailed(Error Err) = 0;
1820
1821 /// Called by JITLink to resolve external symbols. This method is passed a
1822 /// lookup continutation which it must call with a result to continue the
1823 /// linking process.
1824 virtual void lookup(const LookupMap &Symbols,
1825 std::unique_ptr<JITLinkAsyncLookupContinuation> LC) = 0;
1826
1827 /// Called by JITLink once all defined symbols in the graph have been assigned
1828 /// their final memory locations in the target process. At this point the
1829 /// LinkGraph can be inspected to build a symbol table, however the block
1830 /// content will not generally have been copied to the target location yet.
1831 ///
1832 /// If the client detects an error in the LinkGraph state (e.g. unexpected or
1833 /// missing symbols) they may return an error here. The error will be
1834 /// propagated to notifyFailed and the linker will bail out.
1836
1837 /// Called by JITLink to notify the context that the object has been
1838 /// finalized (i.e. emitted to memory and memory permissions set). If all of
1839 /// this objects dependencies have also been finalized then the code is ready
1840 /// to run.
1842
1843 /// Called by JITLink prior to linking to determine whether default passes for
1844 /// the target should be added. The default implementation returns true.
1845 /// If subclasses override this method to return false for any target then
1846 /// they are required to fully configure the pass pipeline for that target.
1847 virtual bool shouldAddDefaultTargetPasses(const Triple &TT) const;
1848
1849 /// Returns the mark-live pass to be used for this link. If no pass is
1850 /// returned (the default) then the target-specific linker implementation will
1851 /// choose a conservative default (usually marking all symbols live).
1852 /// This function is only called if shouldAddDefaultTargetPasses returns true,
1853 /// otherwise the JITContext is responsible for adding a mark-live pass in
1854 /// modifyPassConfig.
1855 virtual LinkGraphPassFunction getMarkLivePass(const Triple &TT) const;
1856
1857 /// Called by JITLink to modify the pass pipeline prior to linking.
1858 /// The default version performs no modification.
1860
1861private:
1862 const JITLinkDylib *JD = nullptr;
1863};
1864
1865/// Marks all symbols in a graph live. This can be used as a default,
1866/// conservative mark-live implementation.
1868
1869/// Create an out of range error for the given edge in the given block.
1871 const Edge &E);
1872
1874 const Edge &E);
1875
1876/// Creates a new pointer block in the given section and returns an
1877/// Anonymous symbol pointing to it.
1878///
1879/// The pointer block will have the following default values:
1880/// alignment: PointerSize
1881/// alignment-offset: 0
1882/// address: highest allowable
1884 LinkGraph &G, Section &PointerSection, Symbol *InitialTarget,
1885 uint64_t InitialAddend)>;
1886
1887/// Get target-specific AnonymousPointerCreator
1889
1890/// Create a jump stub that jumps via the pointer at the given symbol and
1891/// an anonymous symbol pointing to it. Return the anonymous symbol.
1892///
1893/// The stub block will be created by createPointerJumpStubBlock.
1895 LinkGraph &G, Section &StubSection, Symbol &PointerSymbol)>;
1896
1897/// Get target-specific PointerJumpStubCreator
1899
1900/// Base case for edge-visitors where the visitor-list is empty.
1901inline void visitEdge(LinkGraph &G, Block *B, Edge &E) {}
1902
1903/// Applies the first visitor in the list to the given edge. If the visitor's
1904/// visitEdge method returns true then we return immediately, otherwise we
1905/// apply the next visitor.
1906template <typename VisitorT, typename... VisitorTs>
1907void visitEdge(LinkGraph &G, Block *B, Edge &E, VisitorT &&V,
1908 VisitorTs &&...Vs) {
1909 if (!V.visitEdge(G, B, E))
1910 visitEdge(G, B, E, std::forward<VisitorTs>(Vs)...);
1911}
1912
1913/// For each edge in the given graph, apply a list of visitors to the edge,
1914/// stopping when the first visitor's visitEdge method returns true.
1915///
1916/// Only visits edges that were in the graph at call time: if any visitor
1917/// adds new edges those will not be visited. Visitors are not allowed to
1918/// remove edges (though they can change their kind, target, and addend).
1919template <typename... VisitorTs>
1920void visitExistingEdges(LinkGraph &G, VisitorTs &&...Vs) {
1921 // We may add new blocks during this process, but we don't want to iterate
1922 // over them, so build a worklist.
1923 std::vector<Block *> Worklist(G.blocks().begin(), G.blocks().end());
1924
1925 for (auto *B : Worklist)
1926 for (auto &E : B->edges())
1927 visitEdge(G, B, E, std::forward<VisitorTs>(Vs)...);
1928}
1929
1930/// Create a LinkGraph from the given object buffer.
1931///
1932/// Note: The graph does not take ownership of the underlying buffer, nor copy
1933/// its contents. The caller is responsible for ensuring that the object buffer
1934/// outlives the graph.
1937
1938/// Create a \c LinkGraph defining the given absolute symbols.
1939std::unique_ptr<LinkGraph> absoluteSymbolsLinkGraph(const Triple &TT,
1940 orc::SymbolMap Symbols);
1941
1942/// Link the given graph.
1943void link(std::unique_ptr<LinkGraph> G, std::unique_ptr<JITLinkContext> Ctx);
1944
1945} // end namespace jitlink
1946} // end namespace llvm
1947
1948#endif // LLVM_EXECUTIONENGINE_JITLINK_JITLINK_H
This file defines the BumpPtrAllocator interface.
basic Basic Alias true
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")
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:564
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
This file implements a map that provides insertion order iteration.
#define T
Basic Register Allocator
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const Value * getAddress(const DbgVariableIntrinsic *DVI)
Definition: SROA.cpp:4973
This file contains some templates that are useful if you are working with the STL at all.
raw_pwrite_stream & OS
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:165
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:195
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:66
Implements a dense probed hash-table based set.
Definition: DenseSet.h:271
Base class for user error types.
Definition: Error.h:355
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:337
Tagged union holding either a T or a Error.
Definition: Error.h:481
This class implements a map that also provides access to all stored values in a deterministic order.
Definition: MapVector.h:36
typename VectorType::value_type value_type
Definition: MapVector.h:46
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:307
T * data() const
Definition: ArrayRef.h:354
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:426
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
iterator end()
Definition: StringMap.h:220
iterator begin()
Definition: StringMap.h:219
bool contains(StringRef Key) const
contains - Return true if the element is in the map, false otherwise.
Definition: StringMap.h:273
StringMapIterator< Symbol * > iterator
Definition: StringMap.h:217
void erase(iterator I)
Definition: StringMap.h:416
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:308
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
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:44
unsigned getArchPointerBitWidth() const
Returns the pointer width of this architecture.
Definition: Triple.h:475
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
LLVM Value Representation.
Definition: Value.h:74
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
ConstIterator const_iterator
Definition: DenseSet.h:171
size_type size() const
Definition: DenseSet.h:81
bool erase(const ValueT &V)
Definition: DenseSet.h:101
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:97
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
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
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:480
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:1680
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
auto formatv(const char *Fmt, Ts &&...Vals) -> formatv_object< decltype(std::make_tuple(support::detail::build_format_adapter(std::forward< Ts >(Vals))...))>
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
Definition: MathExtras.h:296
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:215
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:1736
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition: Allocator.h:382
OutputIt copy(R &&Range, OutputIt Out)
Definition: STLExtras.h:1824
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:1856
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
Definition: STLExtras.h:1928
endianness
Definition: bit.h:70
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
#define N
Represents an address range in the exceutor process.