diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h --- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h @@ -77,6 +77,8 @@ Edge(Kind K, OffsetT Offset, Symbol &Target, AddendT Addend) : Target(&Target), Offset(Offset), Addend(Addend), K(K) {} + Edge(Kind K, OffsetT Offset, AddendT Addend) + : Offset(Offset), Addend(Addend), K(K) {} OffsetT getOffset() const { return Offset; } void setOffset(OffsetT Offset) { this->Offset = Offset; } @@ -88,7 +90,11 @@ return K - FirstRelocation; } bool isKeepAlive() const { return K >= FirstKeepAlive; } - Symbol &getTarget() const { return *Target; } + bool hasTarget() const { return Target != nullptr; } + Symbol &getTarget() const { + assert(Target && "Not an edge with a target"); + return *Target; + } void setTarget(Symbol &Target) { this->Target = &Target; } AddendT getAddend() const { return Addend; } void setAddend(AddendT Addend) { this->Addend = Addend; } diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp --- a/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/JITLink.cpp @@ -127,8 +127,14 @@ void printEdge(raw_ostream &OS, const Block &B, const Edge &E, StringRef EdgeKindName) { OS << "edge@" << B.getAddress() + E.getOffset() << ": " << B.getAddress() - << " + " << formatv("{0:x}", E.getOffset()) << " -- " << EdgeKindName - << " -> "; + << " + " << formatv("{0:x}", E.getOffset()) << " -- " << EdgeKindName; + + if (!E.hasTarget()) { + OS << " (no target, addend " << E.getAddend() << ")"; + return; + } + + OS << " -> "; auto &TargetSym = E.getTarget(); if (TargetSym.hasName()) @@ -322,13 +328,16 @@ OS << formatv("+{0:x8}", E.getAddend()); else OS << formatv("-{0:x8}", -E.getAddend()); - OS << ", kind = " << getEdgeKindName(E.getKind()) << ", target = "; - if (E.getTarget().hasName()) - OS << E.getTarget().getName(); - else - OS << "addressable@" - << formatv("{0:x16}", E.getTarget().getAddress()) << "+" - << formatv("{0:x8}", E.getTarget().getOffset()); + OS << ", kind = " << getEdgeKindName(E.getKind()); + if (E.hasTarget()) { + OS << ", target = "; + if (E.getTarget().hasName()) + OS << E.getTarget().getName(); + else + OS << "addressable@" + << formatv("{0:x16}", E.getTarget().getAddress()) << "+" + << formatv("{0:x8}", E.getTarget().getOffset()); + } OS << "\n"; } } else diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.h b/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.h --- a/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.h +++ b/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.h @@ -148,7 +148,7 @@ for (auto &E : B->edges()) { // Skip non-relocation edges. - if (!E.isRelocation()) + if (!E.isRelocation() || !E.hasTarget()) continue; // If B is a block in a Standard or Finalize section then make sure diff --git a/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp b/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp --- a/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/JITLinkGeneric.cpp @@ -286,6 +286,9 @@ VisitedBlocks.insert(&B); for (auto &E : Sym->getBlock().edges()) { + if (!E.hasTarget()) + continue; + // If the edge target is a defined symbol that is being newly marked live // then add it to the worklist. if (E.getTarget().isDefined() && !E.getTarget().isLive()) diff --git a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp --- a/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ObjectLinkingLayer.cpp @@ -551,6 +551,8 @@ for (auto *B : G.blocks()) { auto &BI = BlockInfos[B]; for (auto &E : B->edges()) { + if (!E.hasTarget()) + continue; if (E.getTarget().getScope() == Scope::Local && !E.getTarget().isAbsolute()) { auto &TgtB = E.getTarget().getBlock();