@@ -24,6 +24,8 @@ create_native_stack_bound(const AOTCompContext *comp_ctx,
24
24
static bool
25
25
create_native_stack_top_min (const AOTCompContext * comp_ctx ,
26
26
AOTFuncContext * func_ctx );
27
+ static bool
28
+ create_func_ptrs (const AOTCompContext * comp_ctx , AOTFuncContext * func_ctx );
27
29
28
30
LLVMTypeRef
29
31
wasm_type_to_llvm_type (const AOTCompContext * comp_ctx ,
@@ -334,6 +336,9 @@ aot_build_precheck_function(AOTCompContext *comp_ctx, LLVMModuleRef module,
334
336
&& !create_native_stack_top_min (comp_ctx , func_ctx )) {
335
337
goto fail ;
336
338
}
339
+ if (!create_func_ptrs (comp_ctx , func_ctx )) {
340
+ goto fail ;
341
+ }
337
342
338
343
uint32 param_count = LLVMCountParams (precheck_func );
339
344
uint32 sz = param_count * (uint32 )sizeof (LLVMValueRef );
@@ -537,8 +542,46 @@ aot_build_precheck_function(AOTCompContext *comp_ctx, LLVMModuleRef module,
537
542
if (ret_type == VOID_TYPE ) {
538
543
name = "" ;
539
544
}
540
- LLVMValueRef retval =
541
- LLVMBuildCall2 (b , func_type , wrapped_func , params , param_count , name );
545
+
546
+ LLVMValueRef retval ;
547
+ if (comp_ctx -> is_indirect_mode ) {
548
+ /* call wrapped_func indirectly */
549
+ LLVMTypeRef func_ptr_type ;
550
+ LLVMValueRef wrapped_func_indirect ;
551
+ uint32 import_func_count = comp_ctx -> comp_data -> import_func_count ;
552
+ uint32 func_count = comp_ctx -> func_ctx_count ;
553
+
554
+ /* Check function index */
555
+ if (func_index >= import_func_count + func_count ) {
556
+ aot_set_last_error ("Function index out of range." );
557
+ return false;
558
+ }
559
+
560
+ /* Get function type */
561
+ if (!(func_ptr_type = LLVMPointerType (func_type , 0 ))) {
562
+ aot_set_last_error ("create LLVM function type failed." );
563
+ goto fail ;
564
+ }
565
+
566
+ /*
567
+ * func_index layout :
568
+ * aot_func#xxx, range from 0 ~ func_conut - 1;
569
+ * aot_func#internal#xxx, range from func_conut ~ 2 * func_conut - 1;
570
+ */
571
+ if (!(wrapped_func_indirect = aot_get_func_from_table (
572
+ comp_ctx , func_ctx -> func_ptrs , func_ptr_type ,
573
+ func_index + func_count + import_func_count ))) {
574
+ goto fail ;
575
+ }
576
+
577
+ /* Call the function indirectly */
578
+ retval = LLVMBuildCall2 (b , func_type , wrapped_func_indirect , params ,
579
+ param_count , name );
580
+ }
581
+ else
582
+ retval = LLVMBuildCall2 (b , func_type , wrapped_func , params , param_count ,
583
+ name );
584
+
542
585
if (!retval ) {
543
586
goto fail ;
544
587
}
@@ -732,7 +775,7 @@ aot_add_llvm_func(AOTCompContext *comp_ctx, LLVMModuleRef module,
732
775
}
733
776
734
777
if (need_precheck ) {
735
- if (!comp_ctx -> is_jit_mode )
778
+ if (!comp_ctx -> is_jit_mode && ! comp_ctx -> is_indirect_mode )
736
779
LLVMSetLinkage (func , LLVMInternalLinkage );
737
780
unsigned int kind =
738
781
LLVMGetEnumAttributeKindForName ("noinline" , strlen ("noinline" ));
0 commit comments