15#ifndef LLVM_EXECUTIONENGINE_JITLINK_DEFINEEXTERNALSECTIONSTARTANDENDSYMBOLS_H
16#define LLVM_EXECUTIONENGINE_JITLINK_DEFINEEXTERNALSECTIONSTARTANDENDSYMBOLS_H
21#define DEBUG_TYPE "jitlink"
36template <
typename SymbolIdentifierFunction>
46 std::vector<Symbol *> Externals(
G.external_symbols().begin(),
47 G.external_symbols().end());
49 for (
auto *
Sym : Externals) {
52 auto &SR = getSectionRange(*
D.Sec);
63 G.makeDefined(*
Sym, *SR.getLastBlock(),
74 auto I = SectionRanges.find(&Sec);
75 if (
I == SectionRanges.end())
76 I = SectionRanges.insert(std::make_pair(&Sec,
SectionRange(Sec))).first;
81 SymbolIdentifierFunction F;
103template <
typename SymbolIdentifierFunction>
104DefineExternalSectionStartAndEndSymbols<SymbolIdentifierFunction>
106 SymbolIdentifierFunction &&
F) {
108 std::forward<SymbolIdentifierFunction>(
F));
112inline SectionRangeSymbolDesc
114 constexpr StringRef StartSymbolPrefix =
"__start_";
115 constexpr StringRef EndSymbolPrefix =
"__stop_";
118 if (SymName.starts_with(StartSymbolPrefix)) {
120 G.findSectionByName(SymName.drop_front(StartSymbolPrefix.
size())))
122 }
else if (SymName.starts_with(EndSymbolPrefix)) {
124 G.findSectionByName(SymName.drop_front(EndSymbolPrefix.
size())))
125 return {*Sec,
false};
131inline SectionRangeSymbolDesc
133 constexpr StringRef StartSymbolPrefix =
"section$start$";
134 constexpr StringRef EndSymbolPrefix =
"section$end$";
137 if (SymName.starts_with(StartSymbolPrefix)) {
138 auto [SegName, SecName] =
140 std::string
SectionName = (SegName +
"," + SecName).str();
143 }
else if (SymName.starts_with(EndSymbolPrefix)) {
144 auto [SegName, SecName] =
145 SymName.drop_front(EndSymbolPrefix.
size()).
split(
'$');
146 std::string
SectionName = (SegName +
"," + SecName).str();
148 return {*Sec,
false};
static MachineBasicBlock * split(MachineBasicBlock::iterator I)
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
constexpr size_t size() const
size - Get the string size.
Pass implementation for the createDefineExternalSectionStartAndEndSymbols function.
DefineExternalSectionStartAndEndSymbols(SymbolIdentifierFunction F)
Error operator()(LinkGraph &G)
Represents a section address range via a pair of Block pointers to the first and last Blocks in the s...
Represents an object file section.
StringRef getName() const
Returns the name of this symbol (empty if the symbol is anonymous).
Represents an address in the executor process.
SectionRangeSymbolDesc identifyELFSectionStartAndEndSymbols(LinkGraph &G, Symbol &Sym)
ELF section start/end symbol detection.
DefineExternalSectionStartAndEndSymbols< SymbolIdentifierFunction > createDefineExternalSectionStartAndEndSymbolsPass(SymbolIdentifierFunction &&F)
Returns a JITLink pass (as a function class) that uses the given symbol identification function to id...
SectionRangeSymbolDesc identifyMachOSectionStartAndEndSymbols(LinkGraph &G, Symbol &Sym)
MachO section start/end symbol detection.
This is an optimization pass for GlobalISel generic memory operations.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
SectionRangeSymbolDesc()=default
SectionRangeSymbolDesc(Section &Sec, bool IsStart)