From 1f89e446d9f7188061838acbc4e6d63e15125fce Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 4 Jul 2023 17:48:32 +0900 Subject: [PATCH] Avoid switch lowering to lookup tables for XIP (#2339) Because it involves relocations for the table. (.Lswitch.table.XXX) Discussions: https://github.com/bytecodealliance/wasm-micro-runtime/issues/2316 --- core/iwasm/compilation/aot_llvm.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/iwasm/compilation/aot_llvm.c b/core/iwasm/compilation/aot_llvm.c index 5c58eb6b..3e8eeba6 100644 --- a/core/iwasm/compilation/aot_llvm.c +++ b/core/iwasm/compilation/aot_llvm.c @@ -623,6 +623,15 @@ aot_add_llvm_func(AOTCompContext *comp_ctx, LLVMModuleRef module, prefix))) goto fail; + if (comp_ctx->is_indirect_mode) { + /* avoid LUT relocations ("switch-table") */ + LLVMAttributeRef attr_no_jump_tables = LLVMCreateStringAttribute( + comp_ctx->context, "no-jump-tables", strlen("no-jump-tables"), + "true", strlen("true")); + LLVMAddAttributeAtIndex(func, LLVMAttributeFunctionIndex, + attr_no_jump_tables); + } + if (need_precheck) { if (!comp_ctx->is_jit_mode) LLVMSetLinkage(func, LLVMInternalLinkage);