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