diff options
author | Lang Hames <lhames@gmail.com> | 2019-12-02 01:45:49 -0800 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2019-12-02 01:52:52 -0800 |
commit | ece8fed609061638bc867ecb74e179cb86426d60 (patch) | |
tree | 50eea950e0965b32d2bdb961456c88c580f81c2d /llvm/tools/llvm-jitlink | |
parent | 0e7ecc651a47f818abafdfe5f928923f789fe0bc (diff) | |
download | bcm5719-llvm-ece8fed609061638bc867ecb74e179cb86426d60.tar.gz bcm5719-llvm-ece8fed609061638bc867ecb74e179cb86426d60.zip |
[ORC] Add a runAsMain utility function to ExecutionUtils.
The runAsMain function takes a pointer to a function with a standard C main
signature, int(*)(int, char*[]), and invokes it using the given arguments and
program name. The arguments are copied into writable temporary storage as
required by the C and C++ specifications, so runAsMain safe to use when calling
main functions that modify their arguments in-place.
This patch also uses the new runAsMain function to replace hand-rolled versions
in lli, llvm-jitlink, and the SpeculativeJIT example.
Diffstat (limited to 'llvm/tools/llvm-jitlink')
-rw-r--r-- | llvm/tools/llvm-jitlink/llvm-jitlink.cpp | 23 |
1 files changed, 3 insertions, 20 deletions
diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp index 003a333d956..0e0953d37b6 100644 --- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp @@ -769,25 +769,6 @@ static Expected<JITEvaluatedSymbol> getMainEntryPoint(Session &S) { return S.ES.lookup(S.JDSearchOrder, EntryPointName); } -Expected<int> runEntryPoint(Session &S, JITEvaluatedSymbol EntryPoint) { - assert(EntryPoint.getAddress() && "Entry point address should not be null"); - - constexpr const char *JITProgramName = "<llvm-jitlink jit'd code>"; - auto PNStorage = std::make_unique<char[]>(strlen(JITProgramName) + 1); - strcpy(PNStorage.get(), JITProgramName); - - std::vector<const char *> EntryPointArgs; - EntryPointArgs.push_back(PNStorage.get()); - for (auto &InputArg : InputArgv) - EntryPointArgs.push_back(InputArg.data()); - EntryPointArgs.push_back(nullptr); - - using MainTy = int (*)(int, const char *[]); - MainTy EntryPointPtr = reinterpret_cast<MainTy>(EntryPoint.getAddress()); - - return EntryPointPtr(EntryPointArgs.size() - 1, EntryPointArgs.data()); -} - struct JITLinkTimers { TimerGroup JITLinkTG{"llvm-jitlink timers", "timers for llvm-jitlink phases"}; Timer LoadObjectsTimer{"load", "time to load/add object files", JITLinkTG}; @@ -841,8 +822,10 @@ int main(int argc, char *argv[]) { int Result = 0; { + using MainTy = int (*)(int, char *[]); + auto EntryFn = jitTargetAddressToFunction<MainTy>(EntryPoint.getAddress()); TimeRegion TR(Timers ? &Timers->RunTimer : nullptr); - Result = ExitOnErr(runEntryPoint(S, EntryPoint)); + Result = runAsMain(EntryFn, InputArgv, StringRef(InputFiles.front())); } return Result; |