[PATCH] D149996: [test] [ExecutionEngine] Skip the ExecutionEngine tests on mingw targets

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 7 23:51:49 PDT 2023

mstorsjo added a comment.

In D149996#4325617 <https://reviews.llvm.org/D149996#4325617>, @lhames wrote:

> @mstorsjo I think I see the underlying issue here: https://github.com/llvm/llvm-project/blob/79702f7f593dece7afb67fec03df884d50525b96/llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp#L268
> Could you please try this fix instead:
>   diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp
>   index bc1c9cecbb77..fade24c57898 100644
>   --- a/llvm/tools/lli/lli.cpp
>   +++ b/llvm/tools/lli/lli.cpp
>   @@ -824,6 +824,16 @@ 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 to __main from the generated main. The
>   +  // __main function is usually defined in a standard library and responsible
>   +  // for setting up main's environment (e.g. running static ctors), but in our
>   +  // case the host executor will have taken care of non-JIT ctors, and ORC will
>   +  // take care of JIT'd ones. To avoid a missing symbol error we can just
>   +  // point __main at this noop function.
>   +  return 0;
>   +}
>   +
>    int runOrcJIT(const char *ProgName) {
>      // Start setting up the JIT environment.
>   @@ -989,6 +999,16 @@ 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
> If that works then I'll commit it.

Thanks, that does indeed solve most of the issue!

In a handful of tests, I'm still seeing failures - I get undefined references to `__chkstk_ms`. Whenever a function allocates more than 4 KB of stack, the compiler generates a call to this function in the prologue. However this does happen in MSVC mode too (the function just is called `__chkstk` instead of `__chkstk_ms`), and as these tests do run successfully in MSVC mode, I'm not quite sure what differs here. I also tried to change the `-mtriple=` parameter as passed to `lli` in the test, to the same as in the MSVC case where the test passes, and it still fails in the same way then. Conversely, an MSVC-built `lli.exe` runs the test just fine even if I set the `-mtriple=` parameter to that in the mingw case. Any hints on how to look closer into what's going on here? (E.g. any options for just spitting out what code it generated instead of trying to link it, to see if it's a matter of generating the wrong code, or failing to handle some case in the runtime linking?)

  rG LLVM Github Monorepo



More information about the llvm-commits mailing list