[PATCH] D150555: [lli] Export the MinGW chkstk function from the lli executable

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 15 03:22:20 PDT 2023


mstorsjo created this revision.
mstorsjo added a reviewer: lhames.
Herald added a project: All.
mstorsjo requested review of this revision.
Herald added a project: LLVM.

This allows all ExecutionEngine tests pass in MinGW build configurations.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150555

Files:
  llvm/tools/lli/lli.cpp


Index: llvm/tools/lli/lli.cpp
===================================================================
--- llvm/tools/lli/lli.cpp
+++ llvm/tools/lli/lli.cpp
@@ -1178,3 +1178,38 @@
       llvm::orc::SimpleRemoteEPC::Setup(), PipeFD[1][0], PipeFD[0][1]);
 #endif
 }
+
+// For MinGW environments, manually export the __chkstk function from the lli
+// executable.
+//
+// Normally, this function is provided by compiler-rt builtins or libgcc.
+// It is named "_alloca" on i386, "___chkstk_ms" on x86_64, and "__chkstk" on
+// arm/aarch64. In MSVC configurations, it's named "__chkstk" in all
+// configurations.
+//
+// When Orc tries to resolve symbols at runtime, this succeeds in MSVC
+// configurations, somewhat by accident/luck; kernelbase.dll does export a
+// symbol named "__chkstk" which gets found by Orc, even if regular applications
+// never link against that function from that DLL (it's linked in statically
+// from a compiler support library).
+//
+// The MinGW specific symbol names aren't available in that DLL though.
+// Therefore, manually export the relevant symbol from lli, to let it be
+// found at runtime during tests.
+//
+// For real JIT uses, the real compiler support libraries should be linked
+// in, somehow; this is a workaround to let tests pass.
+#ifdef __MINGW32__
+// This is a MinGW version of #pragma comment(linker, "...") that doesn't
+// require compiling with -fms-extensions.
+#if defined(__i386__)
+static __attribute__((section(".drectve"), used)) const char export_chkstk[] =
+    "-export:_alloca";
+#elif defined(__x86_64__)
+static __attribute__((section(".drectve"), used)) const char export_chkstk[] =
+    "-export:___chkstk_ms";
+#else
+static __attribute__((section(".drectve"), used)) const char export_chkstk[] =
+    "-export:__chkstk";
+#endif
+#endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150555.522107.patch
Type: text/x-patch
Size: 1807 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230515/587c1505/attachment.bin>


More information about the llvm-commits mailing list