Skip to content

Commit 4bba12f

Browse files
committed
[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
1 parent e5137e7 commit 4bba12f

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
@@ -1206,18 +1206,32 @@ Expected<std::unique_ptr<orc::ExecutorProcessControl>> launchRemote() {
12061206
// For real JIT uses, the real compiler support libraries should be linked
12071207
// in, somehow; this is a workaround to let tests pass.
12081208
//
1209+
// We need to make sure that this symbol actually is linked in when we
1210+
// try to export it; if no functions allocate a large enough stack area,
1211+
// nothing would reference it. Therefore, manually declare it and add a
1212+
// reference to it. (Note, the declarations of _alloca/___chkstk_ms/__chkstk
1213+
// are somewhat bogus, these functions use a different custom calling
1214+
// convention.)
1215+
//
12091216
// TODO: Move this into libORC at some point, see
12101217
// https://github.com/llvm/llvm-project/issues/56603.
12111218
#ifdef __MINGW32__
12121219
// This is a MinGW version of #pragma comment(linker, "...") that doesn't
12131220
// require compiling with -fms-extensions.
12141221
#if defined(__i386__)
1222+
#undef _alloca
1223+
extern "C" void _alloca(void);
1224+
static __attribute__((used)) void (*const ref_func)(void) = _alloca;
12151225
static __attribute__((section(".drectve"), used)) const char export_chkstk[] =
12161226
"-export:_alloca";
12171227
#elif defined(__x86_64__)
1228+
extern "C" void ___chkstk_ms(void);
1229+
static __attribute__((used)) void (*const ref_func)(void) = ___chkstk_ms;
12181230
static __attribute__((section(".drectve"), used)) const char export_chkstk[] =
12191231
"-export:___chkstk_ms";
12201232
#else
1233+
extern "C" void __chkstk(void);
1234+
static __attribute__((used)) void (*const ref_func)(void) = __chkstk;
12211235
static __attribute__((section(".drectve"), used)) const char export_chkstk[] =
12221236
"-export:__chkstk";
12231237
#endif

0 commit comments

Comments
 (0)