Skip to content

Commit b51021f

Browse files
mstorsjotru
authored andcommitted
[lli] Make sure the exported __chkstk functions are included when exporting them
The trick we use (since cbc2a06) for exporting the __chkstk function (with various per-arch names) that is defined in a different object file, relies on the function already being linked in (by some function referencing it). This function does end up referenced if there's a function that allocates more than 4 KB on the stack. In most cases, it's referenced somewhere, but in the case of builds with LLVM_LINK_LLVM_DYLIB enabled (so most of the code resides in a separate libLLVM-<ver>.dll) the only code in lli.exe is the lli tool specific code and the mingw-w64 crt startup code. In the case of GCC based MinGW i386 builds with LLVM_LINK_LLVM_DYLIB, nothing else references it though. Manually add a reference to the function to make sure it is linked in (from libgcc or compiler-rt builtins) so that it can be exported. This fixes one build issue encountered in msys2/MINGW-packages#18002. Differential Revision: https://reviews.llvm.org/D159085 (cherry picked from commit 4bba12f)
1 parent 6de7b2e commit b51021f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

llvm/tools/lli/lli.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,18 +1200,32 @@ Expected<std::unique_ptr<orc::ExecutorProcessControl>> launchRemote() {
12001200
// For real JIT uses, the real compiler support libraries should be linked
12011201
// in, somehow; this is a workaround to let tests pass.
12021202
//
1203+
// We need to make sure that this symbol actually is linked in when we
1204+
// try to export it; if no functions allocate a large enough stack area,
1205+
// nothing would reference it. Therefore, manually declare it and add a
1206+
// reference to it. (Note, the declarations of _alloca/___chkstk_ms/__chkstk
1207+
// are somewhat bogus, these functions use a different custom calling
1208+
// convention.)
1209+
//
12031210
// TODO: Move this into libORC at some point, see
12041211
// https://github.com/llvm/llvm-project/issues/56603.
12051212
#ifdef __MINGW32__
12061213
// This is a MinGW version of #pragma comment(linker, "...") that doesn't
12071214
// require compiling with -fms-extensions.
12081215
#if defined(__i386__)
1216+
#undef _alloca
1217+
extern "C" void _alloca(void);
1218+
static __attribute__((used)) void (*const ref_func)(void) = _alloca;
12091219
static __attribute__((section(".drectve"), used)) const char export_chkstk[] =
12101220
"-export:_alloca";
12111221
#elif defined(__x86_64__)
1222+
extern "C" void ___chkstk_ms(void);
1223+
static __attribute__((used)) void (*const ref_func)(void) = ___chkstk_ms;
12121224
static __attribute__((section(".drectve"), used)) const char export_chkstk[] =
12131225
"-export:___chkstk_ms";
12141226
#else
1227+
extern "C" void __chkstk(void);
1228+
static __attribute__((used)) void (*const ref_func)(void) = __chkstk;
12151229
static __attribute__((section(".drectve"), used)) const char export_chkstk[] =
12161230
"-export:__chkstk";
12171231
#endif

0 commit comments

Comments
 (0)