@@ -264,15 +264,17 @@ static void emit_import_section(EmitWasm *ew) {
264264 data_uleb128 (& imports_section , -1 , 0 ); // size
265265 ++ imports_count ;
266266 }
267- if (indirect_function_table .count > 0 || (compile_unit_flag & CUF_INDIRECT_CALL )) {
268- static const char kTableName [] = "__indirect_function_table" ;
269- data_string (& imports_section , env_module_name , sizeof (env_module_name ) - 1 ); // import module name
270- data_string (& imports_section , kTableName , sizeof (kTableName ) - 1 ); // import name
271- data_push (& imports_section , IMPORT_TABLE ); // import kind
272- data_push (& imports_section , WT_FUNCREF );
273- data_push (& imports_section , 0x00 ); // limits: flags
274- data_leb128 (& imports_section , -1 , INDIRECT_FUNCTION_TABLE_START_INDEX ); // initial
275- ++ imports_count ;
267+ if (tables -> len > 0 ) {
268+ for (int i = 0 ; i < tables -> len ; ++ i ) {
269+ TableInfo * t = tables -> data [i ];
270+ data_string (& imports_section , env_module_name , sizeof (env_module_name ) - 1 ); // import module name
271+ data_string (& imports_section , t -> name -> chars , t -> name -> bytes ); // import name
272+ data_push (& imports_section , IMPORT_TABLE ); // import kind
273+ data_push (& imports_section , t -> type );
274+ data_push (& imports_section , 0x00 ); // limits: flags
275+ data_leb128 (& imports_section , -1 , INDIRECT_FUNCTION_TABLE_START_INDEX ); // initial
276+ ++ imports_count ;
277+ }
276278 }
277279
278280 {
@@ -655,6 +657,16 @@ static void emit_linking_section(EmitWasm *ew) {
655657 ++ count ;
656658 }
657659 }
660+ if (tables -> len > 0 ) { // Table
661+ for (int i = 0 , len = tables -> len ; i < len ; ++ i ) {
662+ TableInfo * ti = tables -> data [i ];
663+ int flags = WASM_SYM_UNDEFINED | WASM_SYM_EXPORTED | WASM_SYM_NO_STRIP ;
664+ data_push (& linking_section , SIK_SYMTAB_TABLE ); // kind
665+ data_uleb128 (& linking_section , -1 , flags );
666+ data_uleb128 (& linking_section , -1 , ti -> index );
667+ ++ count ;
668+ }
669+ }
658670 if (tags -> len > 0 ) { // Tag
659671 for (int i = 0 , len = tags -> len ; i < len ; ++ i ) {
660672 TagInfo * ti = tags -> data [i ];
@@ -739,13 +751,15 @@ static void emit_reloc_section(EmitWasm *ew, int section_index, Vector *relocs,
739751 data_uleb128 (& ds , -1 , reloc -> index );
740752 switch (reloc -> type ) {
741753 case R_WASM_MEMORY_ADDR_LEB :
742- case R_WASM_MEMORY_ADDR_SLEB :
743754 case R_WASM_MEMORY_ADDR_I32 :
744755 case R_WASM_MEMORY_ADDR_LEB64 :
745- case R_WASM_MEMORY_ADDR_SLEB64 :
746756 case R_WASM_MEMORY_ADDR_I64 :
747757 case R_WASM_FUNCTION_OFFSET_I32 :
748758 case R_WASM_SECTION_OFFSET_I32 :
759+ data_uleb128 (& ds , -1 , reloc -> addend );
760+ break ;
761+ case R_WASM_MEMORY_ADDR_SLEB :
762+ case R_WASM_MEMORY_ADDR_SLEB64 :
749763 data_leb128 (& ds , -1 , reloc -> addend );
750764 break ;
751765 default : break ;
0 commit comments