diff --git a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h --- a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h +++ b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h @@ -540,6 +540,18 @@ auto &GSym = G->addExternalSymbol(*Name, Sym.st_size, Sym.getBinding() == ELF::STB_WEAK); setGraphSymbol(SymIndex, GSym); + } else if (Sym.isUndefined() && Sym.st_value == 0 && Sym.st_size == 0 && + Sym.getType() == ELF::STT_NOTYPE && + Sym.getBinding() == ELF::STB_LOCAL && Name->empty()) { + // Some relocations (e.g., R_RISCV_ALIGN) don't have a target symbol and + // use this kind of null symbol as a placeholder. + LLVM_DEBUG({ + dbgs() << " " << SymIndex << ": Creating null graph symbol\n"; + }); + + auto &GSym = G->addAbsoluteSymbol(*Name, orc::ExecutorAddr(0), 0, + Linkage::Strong, Scope::Local, false); + setGraphSymbol(SymIndex, GSym); } else { LLVM_DEBUG({ dbgs() << " " << SymIndex 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 @@ -133,7 +133,7 @@ auto &TargetSym = E.getTarget(); if (TargetSym.hasName()) OS << TargetSym.getName(); - else { + else if (TargetSym.isDefined()) { auto &TargetBlock = TargetSym.getBlock(); auto &TargetSec = TargetBlock.getSection(); orc::ExecutorAddr SecAddress(~uint64_t(0)); @@ -149,7 +149,8 @@ if (TargetSym.getOffset()) OS << " + " << formatv("{0:x}", TargetSym.getOffset()); OS << ")"; - } + } else + OS << formatv("{0:x}", TargetSym.getAddress()); if (E.getAddend() != 0) OS << " + " << E.getAddend();