Skip to content

Commit ee97618

Browse files
authored
Fix llvm target vendor-sys-abi not correctly set issue on windows platform (#606)
1 parent 09eb858 commit ee97618

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

core/iwasm/compilation/aot_llvm.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,8 @@ static ArchItem valid_archs[] = {
11071107
static const char *valid_abis[] = {
11081108
"gnu",
11091109
"eabi",
1110-
"gnueabihf"
1110+
"gnueabihf",
1111+
"msvc"
11111112
};
11121113

11131114
static void
@@ -1335,9 +1336,32 @@ aot_create_comp_context(AOTCompData *comp_data,
13351336

13361337
if (arch) {
13371338
/* Construct target triple: <arch>-<vendor>-<sys>-<abi> */
1338-
const char *vendor_sys = "-pc-linux-";
1339-
if (!abi)
1340-
abi = "gnu";
1339+
const char *vendor_sys;
1340+
char *default_triple = LLVMGetDefaultTargetTriple();
1341+
1342+
if (!default_triple) {
1343+
aot_set_last_error("llvm get default target triple failed.");
1344+
goto fail;
1345+
}
1346+
1347+
if (strstr(default_triple, "windows")) {
1348+
vendor_sys = "-pc-windows-";
1349+
if (!abi)
1350+
abi = "msvc";
1351+
}
1352+
else if (strstr(default_triple, "win32")) {
1353+
vendor_sys = "-pc-win32-";
1354+
if (!abi)
1355+
abi = "msvc";
1356+
}
1357+
else {
1358+
vendor_sys = "-pc-linux-";
1359+
if (!abi)
1360+
abi = "gnu";
1361+
}
1362+
1363+
LLVMDisposeMessage(default_triple);
1364+
13411365
bh_assert(strlen(arch) + strlen(vendor_sys) + strlen(abi) < sizeof(triple_buf));
13421366
memcpy(triple_buf, arch, strlen(arch));
13431367
memcpy(triple_buf + strlen(arch), vendor_sys, strlen(vendor_sys));

0 commit comments

Comments
 (0)