@@ -174,6 +174,7 @@ GET_U64_FROM_ADDR(uint32 *addr)
174174#define E_TYPE_REL 1 /* Relocatable file */
175175#define E_TYPE_EXEC 2 /* Executable file */
176176#define E_TYPE_DYN 3 /* Shared object file */
177+ #define E_TYPE_XIP 4 /* eXecute In Place file */
177178
178179/* Legal values for e_machine (architecture). */
179180#define E_MACHINE_386 3 /* Intel 80386 */
@@ -422,7 +423,7 @@ load_target_info_section(const uint8 *buf, const uint8 *buf_end,
422423 }
423424
424425 /* Check target elf file type */
425- if (target_info .e_type != E_TYPE_REL ) {
426+ if (target_info .e_type != E_TYPE_REL && target_info . e_type != E_TYPE_XIP ) {
426427 set_error_buf (error_buf , error_buf_size ,
427428 "invalid object file type, "
428429 "expected relocatable file type but got others" );
@@ -2492,33 +2493,36 @@ destroy_sections(AOTSection *section_list, bool destroy_aot_text)
24922493}
24932494
24942495static bool
2495- resolve_native_symbols (const uint8 * buf , uint32 size , uint32 * p_count ,
2496- char * error_buf , uint32 error_buf_size )
2496+ resolve_execute_mode (const uint8 * buf , uint32 size , bool * p_mode ,
2497+ char * error_buf , uint32 error_buf_size )
24972498{
24982499 const uint8 * p = buf , * p_end = buf + size ;
24992500 uint32 section_type ;
25002501 uint32 section_size = 0 ;
2502+ uint16_t e_type = 0 ;
25012503
25022504 p += 8 ;
25032505 while (p < p_end ) {
25042506 read_uint32 (p , p_end , section_type );
25052507 if (section_type <= AOT_SECTION_TYPE_SIGANATURE
2506- || section_type == AOT_SECTION_TYPE_CUSTOM ) {
2508+ || section_type == AOT_SECTION_TYPE_TARGET_INFO ) {
25072509 read_uint32 (p , p_end , section_size );
25082510 CHECK_BUF (p , p_end , section_size );
2509- if (section_type == AOT_SECTION_TYPE_CUSTOM ) {
2510- read_uint32 (p , p_end , section_type );
2511- if (section_type == AOT_CUSTOM_SECTION_NATIVE_SYMBOL ) {
2512- /* Read the count of native symbol */
2513- read_uint32 (p , p_end , * p_count );
2514- return true;
2511+ if (section_type == AOT_SECTION_TYPE_TARGET_INFO ) {
2512+ p += 4 ;
2513+ read_uint16 (p , p_end , e_type );
2514+ if (e_type == E_TYPE_XIP ) {
2515+ * p_mode = true;
25152516 }
2516- p -= sizeof (uint32 );
2517+ else {
2518+ * p_mode = false;
2519+ }
2520+ break ;
25172521 }
25182522 }
25192523 else if (section_type > AOT_SECTION_TYPE_SIGANATURE ) {
25202524 set_error_buf (error_buf , error_buf_size ,
2521- "resolve native symbol failed" );
2525+ "resolve execute mode failed" );
25222526 break ;
25232527 }
25242528 p += section_size ;
@@ -2536,18 +2540,18 @@ create_sections(AOTModule *module, const uint8 *buf, uint32 size,
25362540 AOTSection * section_list = NULL , * section_list_end = NULL , * section ;
25372541 const uint8 * p = buf , * p_end = buf + size ;
25382542 bool destroy_aot_text = false;
2539- uint32 native_symbol_count = 0 ;
2543+ bool is_indirect_mode = 0 ;
25402544 uint32 section_type ;
25412545 uint32 section_size ;
25422546 uint64 total_size ;
25432547 uint8 * aot_text ;
25442548
2545- if (!resolve_native_symbols (buf , size , & native_symbol_count , error_buf ,
2546- error_buf_size )) {
2549+ if (!resolve_execute_mode (buf , size , & is_indirect_mode , error_buf ,
2550+ error_buf_size )) {
25472551 goto fail ;
25482552 }
25492553
2550- module -> native_symbol_count = native_symbol_count ;
2554+ module -> is_indirect_mode = is_indirect_mode ;
25512555
25522556 p += 8 ;
25532557 while (p < p_end ) {
@@ -2568,7 +2572,7 @@ create_sections(AOTModule *module, const uint8 *buf, uint32 size,
25682572 section -> section_body_size = section_size ;
25692573
25702574 if (section_type == AOT_SECTION_TYPE_TEXT ) {
2571- if ((section_size > 0 ) && ( native_symbol_count == 0 ) ) {
2575+ if ((section_size > 0 ) && ! module -> is_indirect_mode ) {
25722576 int map_prot =
25732577 MMAP_PROT_READ | MMAP_PROT_WRITE | MMAP_PROT_EXEC ;
25742578#if defined(BUILD_TARGET_X86_64 ) || defined(BUILD_TARGET_AMD_64 ) \
@@ -2671,8 +2675,7 @@ load(const uint8 *buf, uint32 size, AOTModule *module, char *error_buf,
26712675 if (!ret ) {
26722676 /* If load_from_sections() fails, then aot text is destroyed
26732677 in destroy_sections() */
2674- destroy_sections (section_list ,
2675- module -> native_symbol_count == 0 ? true : false);
2678+ destroy_sections (section_list , module -> is_indirect_mode ? false : true);
26762679 /* aot_unload() won't destroy aot text again */
26772680 module -> code = NULL ;
26782681 }
@@ -3039,7 +3042,7 @@ aot_unload(AOTModule *module)
30393042 if (module -> const_str_set )
30403043 bh_hash_map_destroy (module -> const_str_set );
30413044
3042- if (module -> code && ( module -> native_symbol_count == 0 ) ) {
3045+ if (module -> code && ! module -> is_indirect_mode ) {
30433046 /* The layout is: literal size + literal + code (with plt table) */
30443047 uint8 * mmap_addr = module -> literal - sizeof (uint32 );
30453048 uint32 total_size =
0 commit comments