1*700637cbSDimitry Andric //===- resolve.cpp --------------------------------------------------------===// 2*700637cbSDimitry Andric // 3*700637cbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*700637cbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*700637cbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*700637cbSDimitry Andric // 7*700637cbSDimitry Andric //===----------------------------------------------------------------------===// 8*700637cbSDimitry Andric // 9*700637cbSDimitry Andric // This file contains a generic "resolver" function compatible with the 10*700637cbSDimitry Andric // __orc_rt_reenter function. 11*700637cbSDimitry Andric // 12*700637cbSDimitry Andric //===----------------------------------------------------------------------===// 13*700637cbSDimitry Andric 14*700637cbSDimitry Andric #include "executor_symbol_def.h" 15*700637cbSDimitry Andric #include "jit_dispatch.h" 16*700637cbSDimitry Andric #include "wrapper_function_utils.h" 17*700637cbSDimitry Andric 18*700637cbSDimitry Andric #include <stdio.h> 19*700637cbSDimitry Andric 20*700637cbSDimitry Andric #define DEBUG_TYPE "resolve" 21*700637cbSDimitry Andric 22*700637cbSDimitry Andric using namespace orc_rt; 23*700637cbSDimitry Andric 24*700637cbSDimitry Andric // Declare function tags for functions in the JIT process. ORC_RT_JIT_DISPATCH_TAG(__orc_rt_resolve_tag)25*700637cbSDimitry AndricORC_RT_JIT_DISPATCH_TAG(__orc_rt_resolve_tag) 26*700637cbSDimitry Andric 27*700637cbSDimitry Andric // FIXME: Make this configurable via an alias. 28*700637cbSDimitry Andric static void __orc_rt_resolve_fail(void *Caller, const char *ErrMsg) { 29*700637cbSDimitry Andric fprintf(stderr, "error resolving implementation for stub %p: %s\n", Caller, 30*700637cbSDimitry Andric ErrMsg); 31*700637cbSDimitry Andric abort(); 32*700637cbSDimitry Andric } 33*700637cbSDimitry Andric __orc_rt_resolve(void * Caller)34*700637cbSDimitry Andricextern "C" ORC_RT_HIDDEN void *__orc_rt_resolve(void *Caller) { 35*700637cbSDimitry Andric Expected<ExecutorSymbolDef> Result((ExecutorSymbolDef())); 36*700637cbSDimitry Andric if (auto Err = WrapperFunction<SPSExpected<SPSExecutorSymbolDef>( 37*700637cbSDimitry Andric SPSExecutorAddr)>::call(JITDispatch(&__orc_rt_resolve_tag), Result, 38*700637cbSDimitry Andric ExecutorAddr::fromPtr(Caller))) { 39*700637cbSDimitry Andric __orc_rt_resolve_fail(Caller, toString(std::move(Err)).c_str()); 40*700637cbSDimitry Andric return nullptr; // Unreachable. 41*700637cbSDimitry Andric } 42*700637cbSDimitry Andric 43*700637cbSDimitry Andric if (!Result) { 44*700637cbSDimitry Andric __orc_rt_resolve_fail(Caller, toString(Result.takeError()).c_str()); 45*700637cbSDimitry Andric return nullptr; // Unreachable. 46*700637cbSDimitry Andric } 47*700637cbSDimitry Andric 48*700637cbSDimitry Andric return Result->getAddress().toPtr<void *>(); 49*700637cbSDimitry Andric } 50