Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/LLVMJIT/EmitModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void LLVMJIT::emitModule(const IR::Module& irModule,
auto personalityFunction = llvm::Function::Create(
llvm::FunctionType::get(llvmContext.i32Type, {}, false),
llvm::GlobalValue::LinkageTypes::ExternalLinkage,
moduleContext.useWindowsSEH ? "__CxxFrameHandler3" : "__gxx_personality_v0",
moduleContext.useWindowsSEH ? WINDOWS_SEH_HANDLER_NAME : "__gxx_personality_v0",
&outLLVMModule);

// Create LLVM external globals corresponding to the encoded function types for the module's
Expand Down
11 changes: 11 additions & 0 deletions Lib/LLVMJIT/LLVMJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ using namespace WAVM::LLVMJIT;
namespace LLVMRuntimeSymbols {
#ifdef _WIN32
// the LLVM X86 code generator calls __chkstk when allocating more than 4KB of stack space
#ifdef __MINGW32__
extern "C" void ___chkstk_ms();
extern "C" void __gxx_personality_seh0();
#else
extern "C" void __chkstk();
extern "C" void __CxxFrameHandler3();

#endif
#else
#if defined(__APPLE__)
// LLVM's memset intrinsic lowers to calling __bzero on MacOS when writing a constant zero.
Expand All @@ -51,8 +57,13 @@ namespace LLVMRuntimeSymbols {
{"memmove", (void*)&memmove},
{"memset", (void*)&memset},
#ifdef _WIN32
#ifdef __MINGW32__
{"___chkstk_ms", (void*)&___chkstk_ms},
{"__gxx_personality_seh0", (void*)&__gxx_personality_seh0},
#else
{"__chkstk", (void*)&__chkstk},
{"__CxxFrameHandler3", (void*)&__CxxFrameHandler3},
#endif
#else
#if defined(__APPLE__)
{"__bzero", (void*)&__bzero},
Expand Down
6 changes: 6 additions & 0 deletions Lib/LLVMJIT/LLVMJITPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ PUSH_DISABLE_WARNINGS_FOR_LLVM_HEADERS
#include <llvm/Target/TargetMachine.h>
POP_DISABLE_WARNINGS_FOR_LLVM_HEADERS

#ifdef __MINGW32__
#define WINDOWS_SEH_HANDLER_NAME "__gxx_personality_seh0"
#else
#define WINDOWS_SEH_HANDLER_NAME "__CxxFrameHandler3"
#endif

#define LAZY_PARSE_DWARF_LINE_INFO (LLVM_VERSION_MAJOR >= 9)

namespace llvm {
Expand Down
2 changes: 1 addition & 1 deletion Lib/LLVMJIT/LLVMModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ Module::Module(const std::vector<U8>& objectBytes,
if(USE_WINDOWS_SEH && pdataCopy)
{
// Lookup the real address of _CxxFrameHandler3.
const llvm::JITEvaluatedSymbol sehHandlerSymbol = resolveJITImport("__CxxFrameHandler3");
const llvm::JITEvaluatedSymbol sehHandlerSymbol = resolveJITImport(WINDOWS_SEH_HANDLER_NAME);
WAVM_ERROR_UNLESS(sehHandlerSymbol);
const U64 sehHandlerAddress = U64(sehHandlerSymbol.getAddress());

Expand Down
2 changes: 1 addition & 1 deletion Lib/LLVMJIT/Win64EH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static void applyImageRelativeRelocations(const llvm::LoadedObjectInfo& loadedOb
// Resolve __CxxFrameHandler3 to the trampoline previously created in the image's
// 32-bit address space.
const std::string symbolName = cantFail(symbol->getName()).str();
if(symbolName == "__CxxFrameHandler3") { symbolAddress = sehTrampolineAddress; }
if(symbolName == WINDOWS_SEH_HANDLER_NAME) { symbolAddress = sehTrampolineAddress; }
else
{
llvm::JITSymbol resolvedSymbol
Expand Down