From ee97618bdb1ac5b54f6423a921a4741e1a9e4358 Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Fri, 9 Apr 2021 17:24:01 +0800 Subject: [PATCH] Fix llvm target vendor-sys-abi not correctly set issue on windows platform (#606) --- core/iwasm/compilation/aot_llvm.c | 32 +++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/core/iwasm/compilation/aot_llvm.c b/core/iwasm/compilation/aot_llvm.c index 9651ef95..418ded3d 100644 --- a/core/iwasm/compilation/aot_llvm.c +++ b/core/iwasm/compilation/aot_llvm.c @@ -1107,7 +1107,8 @@ static ArchItem valid_archs[] = { static const char *valid_abis[] = { "gnu", "eabi", - "gnueabihf" + "gnueabihf", + "msvc" }; static void @@ -1335,9 +1336,32 @@ aot_create_comp_context(AOTCompData *comp_data, if (arch) { /* Construct target triple: --- */ - const char *vendor_sys = "-pc-linux-"; - if (!abi) - abi = "gnu"; + const char *vendor_sys; + char *default_triple = LLVMGetDefaultTargetTriple(); + + if (!default_triple) { + aot_set_last_error("llvm get default target triple failed."); + goto fail; + } + + if (strstr(default_triple, "windows")) { + vendor_sys = "-pc-windows-"; + if (!abi) + abi = "msvc"; + } + else if (strstr(default_triple, "win32")) { + vendor_sys = "-pc-win32-"; + if (!abi) + abi = "msvc"; + } + else { + vendor_sys = "-pc-linux-"; + if (!abi) + abi = "gnu"; + } + + LLVMDisposeMessage(default_triple); + bh_assert(strlen(arch) + strlen(vendor_sys) + strlen(abi) < sizeof(triple_buf)); memcpy(triple_buf, arch, strlen(arch)); memcpy(triple_buf + strlen(arch), vendor_sys, strlen(vendor_sys));