diff options
author | Martin Storsjö <martin@martin.st> | 2023-08-29 11:31:53 +0300 |
---|---|---|
committer | Tobias Hieta <tobias@hieta.se> | 2023-09-18 08:45:24 +0200 |
commit | b51021f7b39deae7450fc2f722c1e5ec655fe105 (patch) | |
tree | 9d1a84daf06000f28b15e5fd1ff8a99a9db9eef9 | |
parent | [ARM] Change CRC predicate to just HasCRC (diff) | |
download | llvm-project-b51021f7b39deae7450fc2f722c1e5ec655fe105.tar.gz llvm-project-b51021f7b39deae7450fc2f722c1e5ec655fe105.tar.bz2 llvm-project-b51021f7b39deae7450fc2f722c1e5ec655fe105.zip |
[lli] Make sure the exported __chkstk functions are included when exporting them
The trick we use (since cbc2a0623a39461b56bd9eeb308ca535f03793f8)
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
https://github.com/msys2/MINGW-packages/pull/18002.
Differential Revision: https://reviews.llvm.org/D159085
(cherry picked from commit 4bba12f7226228221d1fa4bad7732e25647ecb87)
-rw-r--r-- | llvm/tools/lli/lli.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp index 3b5250d56707..e2fff69dae20 100644 --- a/llvm/tools/lli/lli.cpp +++ b/llvm/tools/lli/lli.cpp @@ -1200,18 +1200,32 @@ Expected<std::unique_ptr<orc::ExecutorProcessControl>> launchRemote() { // For real JIT uses, the real compiler support libraries should be linked // in, somehow; this is a workaround to let tests pass. // +// We need to make sure that this symbol actually is linked in when we +// try to export it; if no functions allocate a large enough stack area, +// nothing would reference it. Therefore, manually declare it and add a +// reference to it. (Note, the declarations of _alloca/___chkstk_ms/__chkstk +// are somewhat bogus, these functions use a different custom calling +// convention.) +// // TODO: Move this into libORC at some point, see // https://github.com/llvm/llvm-project/issues/56603. #ifdef __MINGW32__ // This is a MinGW version of #pragma comment(linker, "...") that doesn't // require compiling with -fms-extensions. #if defined(__i386__) +#undef _alloca +extern "C" void _alloca(void); +static __attribute__((used)) void (*const ref_func)(void) = _alloca; static __attribute__((section(".drectve"), used)) const char export_chkstk[] = "-export:_alloca"; #elif defined(__x86_64__) +extern "C" void ___chkstk_ms(void); +static __attribute__((used)) void (*const ref_func)(void) = ___chkstk_ms; static __attribute__((section(".drectve"), used)) const char export_chkstk[] = "-export:___chkstk_ms"; #else +extern "C" void __chkstk(void); +static __attribute__((used)) void (*const ref_func)(void) = __chkstk; static __attribute__((section(".drectve"), used)) const char export_chkstk[] = "-export:__chkstk"; #endif |