Skip to content

Commit b300797

Browse files
authored
wamrc: Add --mllvm= option (#3658)
This allows users to specify llvm command line options, similarly to clang's -mllvm option. My motivations: * -debug and friends * -mtext-section-literals for xtensa
1 parent 5be8f35 commit b300797

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

wamr-compiler/main.c

+28
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "wasm_export.h"
1010
#include "aot_export.h"
1111

12+
#include <llvm-c/Support.h>
13+
1214
#if BH_HAS_DLFCN
1315
#include <dlfcn.h>
1416

@@ -195,6 +197,7 @@ print_help()
195197
#if WASM_ENABLE_LINUX_PERF != 0
196198
printf(" --enable-linux-perf Enable linux perf support\n");
197199
#endif
200+
printf(" --mllvm=<option> Add the LLVM command line option\n");
198201
printf(" -v=n Set log verbose level (0 to 5, default is 2), larger with more log\n");
199202
printf(" --version Show version information\n");
200203
printf("Examples: wamrc -o test.aot test.wasm\n");
@@ -315,6 +318,8 @@ int
315318
main(int argc, char *argv[])
316319
{
317320
char *wasm_file_name = NULL, *out_file_name = NULL;
321+
char **llvm_options = NULL;
322+
size_t llvm_options_count = 0;
318323
uint8 *wasm_file = NULL;
319324
uint32 wasm_file_size;
320325
wasm_module_t wasm_module = NULL;
@@ -550,6 +555,24 @@ main(int argc, char *argv[])
550555
enable_linux_perf = true;
551556
}
552557
#endif
558+
else if (!strncmp(argv[0], "--mllvm=", 8)) {
559+
void *np;
560+
if (argv[0][8] == '\0')
561+
PRINT_HELP_AND_EXIT();
562+
if (llvm_options_count == 0)
563+
llvm_options_count += 2;
564+
else
565+
llvm_options_count++;
566+
np = realloc(llvm_options, llvm_options_count * sizeof(char *));
567+
if (np == NULL) {
568+
printf("Memory allocation failure\n");
569+
goto fail0;
570+
}
571+
llvm_options = np;
572+
if (llvm_options_count == 2)
573+
llvm_options[llvm_options_count - 2] = "wamrc";
574+
llvm_options[llvm_options_count - 1] = argv[0] + 8;
575+
}
553576
else if (!strcmp(argv[0], "--version")) {
554577
uint32 major, minor, patch;
555578
wasm_runtime_get_version(&major, &minor, &patch);
@@ -625,6 +648,10 @@ main(int argc, char *argv[])
625648
native_lib_list, native_lib_count, native_handle_list);
626649
#endif
627650

651+
if (llvm_options_count > 0)
652+
LLVMParseCommandLineOptions(llvm_options_count,
653+
(const char **)llvm_options, "wamrc");
654+
628655
bh_print_time("Begin to load wasm file");
629656

630657
if (use_dummy_wasm) {
@@ -738,6 +765,7 @@ main(int argc, char *argv[])
738765
if (option.custom_sections) {
739766
free(option.custom_sections);
740767
}
768+
free(llvm_options);
741769

742770
bh_print_time("wamrc return");
743771
return exit_status;

0 commit comments

Comments
 (0)