[llvm] cf4477d - [lli] Improve support for MinGW by implementing __main as a no-op.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Tue May 9 22:51:52 PDT 2023
Author: Lang Hames
Date: 2023-05-09T22:50:39-07:00
New Revision: cf4477dec11bfda048918d2ec49f04e0794c8030
URL: https://github.com/llvm/llvm-project/commit/cf4477dec11bfda048918d2ec49f04e0794c8030
DIFF: https://github.com/llvm/llvm-project/commit/cf4477dec11bfda048918d2ec49f04e0794c8030.diff
LOG: [lli] Improve support for MinGW by implementing __main as a no-op.
Without this function lli will error out on MinGW with a missing symbol error
for __main.
Cygwin and MinGW insert calls from the main function to the runtime function
__main. The __main function is responsible for setting up main's environment
(e.g. running static constructors), however this is not needed when running
under lli: the executor process will have run non-JIT ctors, and ORC will take
care of running JIT'd ctors. To avoid a missing symbol error we just implement
__main as a no-op.
Added:
Modified:
llvm/tools/lli/lli.cpp
Removed:
################################################################################
diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp
index bc1c9cecbb772..33b2bf869893a 100644
--- a/llvm/tools/lli/lli.cpp
+++ b/llvm/tools/lli/lli.cpp
@@ -824,6 +824,20 @@ loadModule(StringRef Path, orc::ThreadSafeContext TSCtx) {
return orc::ThreadSafeModule(std::move(M), std::move(TSCtx));
}
+int mingw_noop_main(void) {
+ // Cygwin and MinGW insert calls from the main function to the runtime
+ // function __main. The __main function is responsible for setting up main's
+ // environment (e.g. running static constructors), however this is not needed
+ // when running under lli: the executor process will have run non-JIT ctors,
+ // and ORC will take care of running JIT'd ctors. To avoid a missing symbol
+ // error we just implement __main as a no-op.
+ //
+ // FIXME: Move this to ORC-RT (and the ORC-RT substitution library once it
+ // exists). That will allow it to work out-of-process, and for all
+ // ORC tools (the problem isn't lli specific).
+ return 0;
+}
+
int runOrcJIT(const char *ProgName) {
// Start setting up the JIT environment.
@@ -989,6 +1003,14 @@ int runOrcJIT(const char *ProgName) {
Mangle));
}
+ // If this is a Mingw or Cygwin executor then we need to alias __main to
+ // orc_rt_int_void_return_0.
+ if (J->getTargetTriple().isOSCygMing())
+ ExitOnErr(J->getProcessSymbolsJITDylib()->define(
+ orc::absoluteSymbols({{J->mangleAndIntern("__main"),
+ {orc::ExecutorAddr::fromPtr(mingw_noop_main),
+ JITSymbolFlags::Exported}}})));
+
// Regular modules are greedy: They materialize as a whole and trigger
// materialization for all required symbols recursively. Lazy modules go
// through partitioning and they replace outgoing calls with reexport stubs
More information about the llvm-commits
mailing list