/* * Copyright (C) 2019 Intel Corporation. All rights reserved. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ #include #include "bh_platform.h" #include "bh_read_file.h" #include "wasm_export.h" #include "aot_export.h" #include #if BH_HAS_DLFCN #include typedef uint32 (*get_native_lib_func)(char **p_module_name, NativeSymbol **p_native_symbols); static uint32 load_and_register_native_libs(const char **native_lib_list, uint32 native_lib_count, void **native_handle_list) { uint32 i, native_handle_count = 0, n_native_symbols; NativeSymbol *native_symbols; char *module_name; void *handle; for (i = 0; i < native_lib_count; i++) { /* open the native library */ if (!(handle = dlopen(native_lib_list[i], RTLD_NOW | RTLD_GLOBAL)) && !(handle = dlopen(native_lib_list[i], RTLD_LAZY))) { LOG_WARNING("warning: failed to load native library %s", native_lib_list[i]); continue; } /* lookup get_native_lib func */ get_native_lib_func get_native_lib = dlsym(handle, "get_native_lib"); if (!get_native_lib) { LOG_WARNING("warning: failed to lookup `get_native_lib` function " "from native lib %s", native_lib_list[i]); dlclose(handle); continue; } n_native_symbols = get_native_lib(&module_name, &native_symbols); /* register native symbols */ if (!(n_native_symbols > 0 && module_name && native_symbols && wasm_runtime_register_natives(module_name, native_symbols, n_native_symbols))) { LOG_WARNING("warning: failed to register native lib %s", native_lib_list[i]); dlclose(handle); continue; } native_handle_list[native_handle_count++] = handle; } return native_handle_count; } static void unregister_and_unload_native_libs(uint32 native_lib_count, void **native_handle_list) { uint32 i, n_native_symbols; NativeSymbol *native_symbols; char *module_name; void *handle; for (i = 0; i < native_lib_count; i++) { handle = native_handle_list[i]; /* lookup get_native_lib func */ get_native_lib_func get_native_lib = dlsym(handle, "get_native_lib"); if (!get_native_lib) { LOG_WARNING("warning: failed to lookup `get_native_lib` function " "from native lib %p", handle); continue; } n_native_symbols = get_native_lib(&module_name, &native_symbols); if (n_native_symbols == 0 || module_name == NULL || native_symbols == NULL) { LOG_WARNING("warning: get_native_lib returned different values for " "native lib %p", handle); continue; } /* unregister native symbols */ if (!wasm_runtime_unregister_natives(module_name, native_symbols)) { LOG_WARNING("warning: failed to unregister native lib %p", handle); continue; } dlclose(handle); } } #endif /* clang-format off */ static void print_help() { printf("Usage: wamrc [options] -o output_file wasm_file\n"); printf(" --target= Set the target arch, which has the general format: \n"); printf(" = x86_64, i386, aarch64, arm, thumb, xtensa, mips,\n"); printf(" riscv64, riscv32.\n"); 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(" --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"); printf(" Use --target-abi=help to list all the ABI supported\n"); printf(" --cpu= Set the target CPU (default: host CPU, e.g. skylake)\n"); printf(" Use --cpu=help to list all the CPU supported\n"); printf(" --cpu-features= Enable or disable the CPU features\n"); printf(" Use +feature to enable a feature, or -feature to disable it\n"); printf(" For example, --cpu-features=+feature1,-feature2\n"); printf(" Use --cpu-features=+help to list all the features supported\n"); printf(" --opt-level=n Set the optimization level (0 to 3, default is 3)\n"); printf(" --size-level=n Set the code size level (0 to 3, default is 3)\n"); printf(" 0 - Large code model\n"); printf(" 1 - Medium code model\n"); printf(" 2 - Kernel code model\n"); printf(" 3 - Small code model\n"); printf(" -sgx Generate code for SGX platform (Intel Software Guard Extensions)\n"); printf(" --bounds-checks=1/0 Enable or disable the bounds checks for memory access:\n"); printf(" by default it is disabled in all 64-bit platforms except SGX and\n"); printf(" in these platforms runtime does bounds checks with hardware trap,\n"); printf(" and by default it is enabled in all 32-bit platforms\n"); printf(" CAVEAT: --bounds-checks=0 enables some optimizations\n"); printf(" which make the compiled AOT module incompatible\n"); printf(" with a runtime without the hardware bounds checks.\n"); printf(" --stack-bounds-checks=1/0 Enable or disable the bounds checks for native stack:\n"); printf(" if the option isn't set, the status is same as `--bounds-check`,\n"); printf(" if the option is set, the status is same as the option value\n"); printf(" --stack-usage= Generate a stack-usage file.\n"); printf(" Similarly to `clang -fstack-usage`.\n"); printf(" --format= Specifies the format of the output file\n"); printf(" The format supported:\n"); printf(" aot (default) AoT file\n"); printf(" object Native object file\n"); printf(" llvmir-unopt Unoptimized LLVM IR\n"); printf(" llvmir-opt Optimized LLVM IR\n"); printf(" --disable-bulk-memory Disable the MVP bulk memory feature\n"); printf(" --enable-multi-thread Enable multi-thread feature, the dependent features bulk-memory and\n"); printf(" thread-mgr will be enabled automatically\n"); printf(" --enable-tail-call Enable the post-MVP tail call feature\n"); printf(" --disable-simd Disable the post-MVP 128-bit SIMD feature:\n"); printf(" currently 128-bit SIMD is supported for x86-64 and aarch64 targets,\n"); printf(" and by default it is enabled in them and disabled in other targets\n"); printf(" --disable-ref-types Disable the MVP reference types feature, it will be disabled forcibly if\n"); printf(" GC is enabled\n"); printf(" --disable-aux-stack-check Disable auxiliary stack overflow/underflow check\n"); printf(" --enable-dump-call-stack Enable stack trace feature\n"); printf(" --call-stack-features=\n"); printf(" A comma-separated list of features when generating call stacks.\n"); printf(" By default, all features are enabled. To disable all features,\n"); printf(" provide an empty list (i.e. --call-stack-features=). This flag\n"); printf(" only only takes effect when --enable-dump-call-stack is set.\n"); printf(" Available features: bounds-checks, ip, func-idx, trap-ip, values.\n"); printf(" --enable-perf-profiling Enable function performance profiling\n"); printf(" --enable-memory-profiling Enable memory usage profiling\n"); printf(" --xip A shorthand of --enable-indirect-mode --disable-llvm-intrinsics\n"); printf(" --enable-indirect-mode Enable call function through symbol table but not direct call\n"); printf(" --enable-gc Enable GC (Garbage Collection) feature\n"); printf(" --disable-llvm-intrinsics Disable the LLVM built-in intrinsics\n"); printf(" --enable-builtin-intrinsics=\n"); printf(" Enable the specified built-in intrinsics, it will override the default\n"); printf(" settings. It only takes effect when --disable-llvm-intrinsics is set.\n"); printf(" Available flags: all, i32.common, i64.common, f32.common, f64.common,\n"); printf(" i32.clz, i32.ctz, etc, refer to doc/xip.md for full list\n"); printf(" Use comma to separate, please refer to doc/xip.md for full list.\n"); printf(" --disable-llvm-lto Disable the LLVM link time optimization\n"); printf(" --enable-llvm-pgo Enable LLVM PGO (Profile-Guided Optimization)\n"); printf(" --enable-llvm-passes=\n"); printf(" Enable the specified LLVM passes, using comma to separate\n"); printf(" --use-prof-file= Use profile file collected by LLVM PGO (Profile-Guided Optimization)\n"); printf(" --enable-segue[=] Enable using segment register GS as the base address of linear memory,\n"); printf(" only available on linux x86-64, which may improve performance,\n"); printf(" flags can be: i32.load, i64.load, f32.load, f64.load, v128.load,\n"); printf(" i32.store, i64.store, f32.store, f64.store, v128.store\n"); printf(" Use comma to separate, e.g. --enable-segue=i32.load,i64.store\n"); printf(" and --enable-segue means all flags are added.\n"); printf(" --emit-custom-sections=
\n"); printf(" Emit the specified custom sections to AoT file, using comma to separate\n"); printf(" multiple names, e.g.\n"); printf(" --emit-custom-sections=section1,section2,sectionN\n"); #if BH_HAS_DLFCN printf(" --native-lib= Register native libraries to the WASM module, which\n"); printf(" are shared object (.so) files, for example:\n"); printf(" --native-lib=test1.so --native-lib=test2.so\n"); #endif printf(" --invoke-c-api-import Treat unknown import function as wasm-c-api import function and\n"); printf(" quick call it from AOT code\n"); #if WASM_ENABLE_LINUX_PERF != 0 printf(" --enable-linux-perf Enable linux perf support\n"); #endif printf(" --mllvm=