From e4353b4e1f64f375dbd78d16d51919af0284ee4b Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Mon, 13 Nov 2023 18:01:15 +0800 Subject: [PATCH] Add eabihf ABI support and set vendor-sys of bare-metal targets (#2745) Set the vendor-sys of bare-metal targets to "-unknown-none-", and currently only add "thumbxxx" to the bare-metal target list. Signed-off-by: Huang Qi --- core/iwasm/compilation/aot_llvm.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/core/iwasm/compilation/aot_llvm.c b/core/iwasm/compilation/aot_llvm.c index 6dc3a0f7..f3fd0392 100644 --- a/core/iwasm/compilation/aot_llvm.c +++ b/core/iwasm/compilation/aot_llvm.c @@ -1915,6 +1915,7 @@ static ArchItem valid_archs[] = { static const char *valid_abis[] = { "gnu", "eabi", + "eabihf", "gnueabihf", "msvc", "ilp32", @@ -1992,6 +1993,18 @@ get_target_arch_from_triple(const char *triple, char *arch_buf, uint32 buf_size) bh_assert(*triple == '-' || *triple == '\0'); } +static bool +is_baremetal_target(const char *target, const char *cpu, const char *abi) +{ + /* TODO: support more baremetal targets */ + if (target) { + /* If target is thumbxxx, then it is baremetal target */ + if (!strncmp(target, "thumb", strlen("thumb"))) + return true; + } + return false; +} + void aot_handle_llvm_errmsg(const char *string, LLVMErrorRef err) { @@ -2214,7 +2227,7 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) char *triple_norm_new = NULL, *cpu_new = NULL; char *err = NULL, *fp_round = "round.tonearest", *fp_exce = "fpexcept.strict"; - char triple_buf[32] = { 0 }, features_buf[128] = { 0 }; + char triple_buf[128] = { 0 }, features_buf[128] = { 0 }; uint32 opt_level, size_level, i; LLVMCodeModel code_model; LLVMTargetDataRef target_data_ref; @@ -2510,6 +2523,7 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) * for Windows/MacOS under Linux host, or generating AOT file for * Linux/MacOS under Windows host. */ + if (!strcmp(abi, "msvc")) { if (!strcmp(arch1, "i386")) vendor_sys = "-pc-win32-"; @@ -2517,7 +2531,10 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) vendor_sys = "-pc-windows-"; } else { - vendor_sys = "-pc-linux-"; + if (is_baremetal_target(arch, cpu, abi)) + vendor_sys = "-unknown-none-"; + else + vendor_sys = "-pc-linux-"; } bh_assert(strlen(arch1) + strlen(vendor_sys) + strlen(abi) @@ -2553,6 +2570,9 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) if (!abi) abi = "msvc"; } + else if (is_baremetal_target(arch, cpu, abi)) { + vendor_sys = "-unknown-none-"; + } else { vendor_sys = "-pc-linux-"; if (!abi)