22 #define DEBUG_TYPE "jitlink" 33 const char *
name()
const noexcept
override {
return "runtimedyld"; }
35 std::string message(
int Condition)
const override {
36 switch (static_cast<JITLinkErrorCode>(Condition)) {
37 case GenericJITLinkError:
38 return "Generic JITLink error";
53 void JITLinkError::log(
raw_ostream &OS)
const { OS << ErrMsg <<
"\n"; }
55 std::error_code JITLinkError::convertToErrorCode()
const {
56 return std::error_code(GenericJITLinkError, *JITLinkerErrorCategory);
62 return "INVALID RELOCATION";
109 case Linkage::Strong:
127 OS << (Sym.
isLive() ?
'+' :
'-')
145 Section::~Section() {
146 for (
auto *Sym : Symbols)
148 for (
auto *
B : Blocks)
155 assert(SplitIndex > 0 &&
"splitBlock can not be called with SplitIndex == 0");
161 assert(SplitIndex < B.
getSize() &&
"SplitIndex out of range");
168 : createContentBlock(
182 std::vector<Block::edge_iterator> EdgesToRemove;
184 if (
I->getOffset() < SplitIndex) {
185 NewBlock.addEdge(*
I);
186 EdgesToRemove.push_back(
I);
188 I->setOffset(
I->getOffset() - SplitIndex);
192 while (!EdgesToRemove.empty()) {
194 EdgesToRemove.pop_back();
203 Cache = &LocalBlockSymbolsCache;
204 if (*Cache ==
None) {
207 if (&Sym->getBlock() == &
B)
208 (*Cache)->push_back(Sym);
214 auto &BlockSymbols = **Cache;
217 while (!BlockSymbols.empty() &&
218 BlockSymbols.back()->getOffset() < SplitIndex) {
219 BlockSymbols.back()->setBlock(NewBlock);
220 BlockSymbols.pop_back();
224 for (
auto *Sym : BlockSymbols)
225 Sym->setOffset(Sym->getOffset() - SplitIndex);
237 for (
auto *Sym : defined_symbols()) {
238 OS <<
" " <<
format(
"0x%016" PRIx64, Sym->getAddress()) <<
": " << *Sym
240 if (Sym->isDefined()) {
241 for (
auto &
E : Sym->getBlock().edges()) {
243 StringRef EdgeName = (
E.getKind() < Edge::FirstRelocation
245 : EdgeKindToName(
E.getKind()));
247 if (!EdgeName.
empty())
251 printEdge(OS, Sym->getBlock(),
E, EdgeNumberString);
258 OS <<
"Absolute symbols:\n";
259 for (
auto *Sym : absolute_symbols())
260 OS <<
" " <<
format(
"0x%016" PRIx64, Sym->getAddress()) <<
": " << *Sym
263 OS <<
"External symbols:\n";
264 for (
auto *Sym : external_symbols())
265 OS <<
" " <<
format(
"0x%016" PRIx64, Sym->getAddress()) <<
": " << *Sym
271 case SymbolLookupFlags::RequiredSymbol:
272 return OS <<
"RequiredSymbol";
273 case SymbolLookupFlags::WeaklyReferencedSymbol:
274 return OS <<
"WeaklyReferencedSymbol";
279 void JITLinkAsyncLookupContinuation::anchor() {}
281 JITLinkContext::~JITLinkContext() {}
283 bool JITLinkContext::shouldAddDefaultTargetPasses(
const Triple &
TT)
const {
302 void jitLink(std::unique_ptr<JITLinkContext> Ctx) {
308 Ctx->notifyFailed(make_error<JITLinkError>(
"Unsupported file format"));
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface ...
raw_ostream & operator<<(raw_ostream &OS, const SectionedAddress &Addr)
static std::string getLinkageName(GlobalValue::LinkageTypes LT)
Linkage getLinkage() const
Get the linkage for this Symbol.
Error markAllSymbolsLive(LinkGraph &G)
Marks all symbols in a graph live.
This class represents lattice values for constants.
const char * getGenericEdgeKindName(Edge::Kind K)
Returns the string name of the given generic edge kind, or "unknown" otherwise.
SymbolLookupFlags
Flags for symbol lookup.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
uint64_t getAlignment() const
Get the alignment for this content.
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
static void dump(StringRef Title, SpillInfo const &Spills)
OffsetT getOffset() const
void jitLink_MachO(std::unique_ptr< JITLinkContext > Ctx)
jit-link the given ObjBuffer, which must be a MachO object file.
An Addressable with content and edges.
void jitLink(std::unique_ptr< JITLinkContext > Ctx)
Basic JITLink implementation.
StringRef getContent() const
Get the content for this block. Block must not be a zero-fill block.
JITTargetAddress getAddress() const
file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
void removeEdge(const_edge_iterator I)
Remove the edge pointed to by the given iterator.
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Symbol & getTarget() const
std::function< Error(LinkGraph &)> LinkGraphPassFunction
A function for mutating LinkGraphs.
bool isZeroFill() const
Returns true if this is a zero-fill block.
StringRef getName() const
Returns the name of this symbol (empty if the symbol is anonymous).
Addressable & getAddressable()
Return the addressable that this symbol points to.
bool isLive() const
Returns true if this symbol is live (i.e.
iterator_range< symbol_iterator > symbols()
Returns an iterator over the symbols defined in this section.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void setAddress(JITTargetAddress Address)
static ManagedStatic< _object_error_category > error_category
StringRef getName() const
Returns the name of this section.
Section & getSection() const
Return the parent section for this block.
void setAlignmentOffset(uint64_t AlignmentOffset)
Set the alignment offset for this content.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Triple - Helper class for working with autoconf configuration names.
void sort(IteratorTy Start, IteratorTy End)
static const char *const Magic
static ErrorSuccess success()
Create a success value.
iterator_range< edge_iterator > edges()
Return the list of edges attached to this content.
JITTargetAddress getOffset() const
Returns the offset for this symbol within the underlying addressable.
JITTargetAddress getSize() const
Returns the size of this symbol.
AddendT getAddend() const
JITTargetAddress getAddress() const
Returns the address of this symbol.
Block & getBlock()
Return the Block for this Symbol (Symbol must be defined).
Represents fixups and constraints in the LinkGraph.
void printEdge(raw_ostream &OS, const Block &B, const Edge &E, StringRef EdgeKindName)
static MachineBasicBlock & splitBlock(MachineBasicBlock &MBB, MachineInstr &SplitI, const X86InstrInfo &TII)
Linkage
Describes symbol linkage.
void setContent(StringRef Content)
Set the content for this block.
const std::string to_string(const T &Value)
An LinkGraph pass configuration, consisting of a list of pre-prune, post-prune, and post-fixup passes...
uint64_t getAlignmentOffset() const
Get the alignment offset for this content.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const char * getScopeName(Scope S)
For debugging output.
Lightweight error class with error context and mandatory checking.
This class implements an extremely fast bulk output stream that can only output to a stream...
size_t getSize() const
Returns the size of this defined addressable.
print Print MemDeps of function
bool isDefined() const
Returns true if this Symbol has content (potentially) defined within this object file (i...
StringRef - Represent a constant reference to a string, i.e.
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
iterator_range< defined_symbol_iterator > defined_symbols()
Scope getScope() const
Get the visibility for this Symbol.