From 0e1ed14de568a56a29cec625470c09bb3d15cc9a Mon Sep 17 00:00:00 2001 From: Mrmaxmeier Date: Sat, 11 Nov 2023 09:16:08 +0100 Subject: [PATCH 1/2] add `memcpy` to LLVMRuntimeSymbols Sancov seems to generate calls to memcpy sometimes (?), so let's make sure the symbol is available --- Lib/LLVMJIT/LLVMJIT.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/LLVMJIT/LLVMJIT.cpp b/Lib/LLVMJIT/LLVMJIT.cpp index 789bfaee0..2c96481c0 100644 --- a/Lib/LLVMJIT/LLVMJIT.cpp +++ b/Lib/LLVMJIT/LLVMJIT.cpp @@ -53,6 +53,7 @@ namespace LLVMRuntimeSymbols { static HashMap map = { {"memmove", (void*)&memmove}, {"memset", (void*)&memset}, + {"memcpy", (void*)&memcpy}, #ifdef _WIN32 {"__chkstk", (void*)&__chkstk}, {"__CxxFrameHandler3", (void*)&__CxxFrameHandler3}, From a95a2bf16689648a5f4301e20b9645280e1a702b Mon Sep 17 00:00:00 2001 From: Mrmaxmeier Date: Sat, 11 Nov 2023 09:17:03 +0100 Subject: [PATCH 2/2] add prefix to wasm symbol names Re-using the module's function names as symbols is nice for debugging, but can be fatal when they overlap with WAVM's runtime. This commonly happens when a WASM module includes functions like `memset` or `memcpy`, and leads to confusing segfaults. --- Lib/LLVMJIT/EmitModule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/LLVMJIT/EmitModule.cpp b/Lib/LLVMJIT/EmitModule.cpp index cf930e01d..2bc215229 100644 --- a/Lib/LLVMJIT/EmitModule.cpp +++ b/Lib/LLVMJIT/EmitModule.cpp @@ -255,7 +255,7 @@ void LLVMJIT::emitModule(const IR::Module& irModule, asLLVMType(llvmContext, functionType), llvm::Function::ExternalLinkage, functionIndex >= irModule.functions.imports.size() - ? names.functions[functionIndex].name /* getExternalName("functionDef", functionIndex - irModule.functions.imports.size()) */ + ? std::string("wasm::") + names.functions[functionIndex].name /* getExternalName("functionDef", functionIndex - irModule.functions.imports.size()) */ : getExternalName("functionImport", functionIndex), &outLLVMModule); function->setCallingConv(asLLVMCallingConv(functionType.callingConvention()));