From 5910e5cd2134b20d7c7a7fb8ff6d360760463148 Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Tue, 6 May 2025 06:56:06 +0800 Subject: [PATCH] Use --target to pass a triple in wamrc (#4199) Provide a triple string in the format of --- via --target. --- core/iwasm/compilation/aot_llvm.c | 22 ++++++++++++++++++---- wamr-compiler/main.c | 3 +++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/core/iwasm/compilation/aot_llvm.c b/core/iwasm/compilation/aot_llvm.c index 9270f0efe..c1708e3f9 100644 --- a/core/iwasm/compilation/aot_llvm.c +++ b/core/iwasm/compilation/aot_llvm.c @@ -2742,10 +2742,23 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) } else { /* Create LLVM target machine */ - arch = option->target_arch; - abi = option->target_abi; - cpu = option->target_cpu; - features = option->cpu_features; + if (!option->target_arch || !strstr(option->target_arch, "-")) { + /* Retrieve the target triple based on user input */ + triple = NULL; + arch = option->target_arch; + abi = option->target_abi; + cpu = option->target_cpu; + features = option->cpu_features; + } + else { + /* Form a target triple */ + triple = option->target_arch; + arch = NULL; + abi = NULL; + cpu = NULL; + features = NULL; + } + opt_level = option->opt_level; size_level = option->size_level; @@ -2986,6 +2999,7 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) aot_set_last_error(buf); goto fail; } + LOG_VERBOSE("triple: %s => normailized: %s", triple, triple_norm); if (!cpu) cpu = ""; } diff --git a/wamr-compiler/main.c b/wamr-compiler/main.c index 312231619..4d1a24b54 100644 --- a/wamr-compiler/main.c +++ b/wamr-compiler/main.c @@ -116,6 +116,9 @@ print_help() printf(" Default is host arch, e.g. x86_64\n"); printf(" = for ex. on arm or thumb: v5, v6m, v7a, v7m, etc.\n"); printf(" Use --target=help to list supported targets\n"); + printf(" Or, provide a triple in the format of ---.\n"); + printf(" By doing this, --target-abi, --cpu, and --cpu-features will be ignored.\n"); + printf(" The triple will only be normalized without any further verification.\n"); printf(" --target-abi= Set the target ABI, e.g. gnu, eabi, gnueabihf, msvc, etc.\n"); printf(" Default is gnu if target isn't riscv64 or riscv32\n"); printf(" For target riscv64 and riscv32, default is lp64d and ilp32d\n");