@@ -1178,3 +1178,41 @@ Expected<std::unique_ptr<orc::ExecutorProcessControl>> launchRemote() {
1178
1178
llvm::orc::SimpleRemoteEPC::Setup (), PipeFD[1 ][0 ], PipeFD[0 ][1 ]);
1179
1179
#endif
1180
1180
}
1181
+
1182
+ // For MinGW environments, manually export the __chkstk function from the lli
1183
+ // executable.
1184
+ //
1185
+ // Normally, this function is provided by compiler-rt builtins or libgcc.
1186
+ // It is named "_alloca" on i386, "___chkstk_ms" on x86_64, and "__chkstk" on
1187
+ // arm/aarch64. In MSVC configurations, it's named "__chkstk" in all
1188
+ // configurations.
1189
+ //
1190
+ // When Orc tries to resolve symbols at runtime, this succeeds in MSVC
1191
+ // configurations, somewhat by accident/luck; kernelbase.dll does export a
1192
+ // symbol named "__chkstk" which gets found by Orc, even if regular applications
1193
+ // never link against that function from that DLL (it's linked in statically
1194
+ // from a compiler support library).
1195
+ //
1196
+ // The MinGW specific symbol names aren't available in that DLL though.
1197
+ // Therefore, manually export the relevant symbol from lli, to let it be
1198
+ // found at runtime during tests.
1199
+ //
1200
+ // For real JIT uses, the real compiler support libraries should be linked
1201
+ // in, somehow; this is a workaround to let tests pass.
1202
+ //
1203
+ // TODO: Move this into libORC at some point, see
1204
+ // https://github.com/llvm/llvm-project/issues/56603.
1205
+ #ifdef __MINGW32__
1206
+ // This is a MinGW version of #pragma comment(linker, "...") that doesn't
1207
+ // require compiling with -fms-extensions.
1208
+ #if defined(__i386__)
1209
+ static __attribute__ ((section(" .drectve" ), used)) const char export_chkstk[] =
1210
+ "-export:_alloca";
1211
+ #elif defined(__x86_64__)
1212
+ static __attribute__ ((section(" .drectve" ), used)) const char export_chkstk[] =
1213
+ "-export:___chkstk_ms";
1214
+ #else
1215
+ static __attribute__ ((section(" .drectve" ), used)) const char export_chkstk[] =
1216
+ "-export:__chkstk";
1217
+ #endif
1218
+ #endif
0 commit comments