@@ -261,48 +261,34 @@ load_string(uint8 **p_buf, const uint8 *buf_end, AOTModule *module,
261261 char * str ;
262262 uint16 str_len ;
263263
264- CHECK_BUF (p , p_end , 1 );
265- if (* p & 0x80 ) {
266- /* The string has been adjusted */
267- str = (char * )++ p ;
268- /* Ensure the whole string is in range */
269- do {
270- CHECK_BUF (p , p_end , 1 );
271- } while (* p ++ != '\0' );
264+ read_uint16 (p , p_end , str_len );
265+ CHECK_BUF (p , p_end , str_len );
266+
267+ if (str_len == 0 ) {
268+ str = "" ;
269+ }
270+ else if (p [str_len - 1 ] == '\0' ) {
271+ /* The string is terminated with '\0', use it directly */
272+ str = (char * )p ;
273+ }
274+ else if (is_load_from_file_buf ) {
275+ /* As the file buffer can be referred to after loading,
276+ we use the 2 bytes of size to adjust the string:
277+ move string 2 byte backward and then append '\0' */
278+ str = (char * )(p - 2 );
279+ bh_memmove_s (str , (uint32 )(str_len + 1 ), p , (uint32 )str_len );
280+ str [str_len ] = '\0' ;
272281 }
273282 else {
274- /* The string hasn't been adjusted */
275- read_uint16 (p , p_end , str_len );
276- CHECK_BUF (p , p_end , str_len );
277-
278- if (str_len == 0 ) {
279- str = "" ;
280- }
281- else if (p [str_len - 1 ] == '\0' ) {
282- /* The string is terminated with '\0', use it directly */
283- str = (char * )p ;
284- }
285- else if (is_load_from_file_buf ) {
286- /* As the file buffer can be referred to after loading,
287- we use the 2 bytes of size to adjust the string:
288- mark the flag with the highest bit of size[0],
289- move string 1 byte backward and then append '\0' */
290- * (p - 2 ) |= 0x80 ;
291- bh_memmove_s (p - 1 , (uint32 )(str_len + 1 ), p , (uint32 )str_len );
292- p [str_len - 1 ] = '\0' ;
293- str = (char * )(p - 1 );
294- }
295- else {
296- /* Load from sections, the file buffer cannot be reffered to
297- after loading, we must create another string and insert it
298- into const string set */
299- if (!(str = const_str_set_insert ((uint8 * )p , str_len , module ,
300- error_buf , error_buf_size ))) {
301- goto fail ;
302- }
283+ /* Load from sections, the file buffer cannot be reffered to
284+ after loading, we must create another string and insert it
285+ into const string set */
286+ if (!(str = const_str_set_insert ((uint8 * )p , str_len , module , error_buf ,
287+ error_buf_size ))) {
288+ goto fail ;
303289 }
304- p += str_len ;
305290 }
291+ p += str_len ;
306292
307293 * p_buf = p ;
308294 return str ;
@@ -1850,7 +1836,9 @@ do_text_relocation(AOTModule *module, AOTRelocationGroup *group,
18501836 || !strcmp (symbol , ".rdata" )
18511837 || !strcmp (symbol , ".rodata" )
18521838 /* ".rodata.cst4/8/16/.." */
1853- || !strncmp (symbol , ".rodata.cst" , strlen (".rodata.cst" ))) {
1839+ || !strncmp (symbol , ".rodata.cst" , strlen (".rodata.cst" ))
1840+ /* ".rodata.strn.m" */
1841+ || !strncmp (symbol , ".rodata.str" , strlen (".rodata.str" ))) {
18541842 symbol_addr = get_data_section_addr (module , symbol , NULL );
18551843 if (!symbol_addr ) {
18561844 set_error_buf_v (error_buf , error_buf_size ,
@@ -2054,6 +2042,7 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
20542042 uint8 * symbol_buf , * symbol_buf_end ;
20552043 int map_prot , map_flags ;
20562044 bool ret = false;
2045+ char * * symbols = NULL ;
20572046
20582047 read_uint32 (buf , buf_end , symbol_count );
20592048
@@ -2074,6 +2063,14 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
20742063 goto fail ;
20752064 }
20762065
2066+ if (symbol_count > 0 ) {
2067+ symbols = loader_malloc ((uint64 )sizeof (* symbols ) * symbol_count ,
2068+ error_buf , error_buf_size );
2069+ if (symbols == NULL ) {
2070+ goto fail ;
2071+ }
2072+ }
2073+
20772074#if defined(BH_PLATFORM_WINDOWS )
20782075 buf = symbol_buf_end ;
20792076 read_uint32 (buf , buf_end , group_count );
@@ -2208,7 +2205,6 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
22082205 for (i = 0 , group = groups ; i < group_count ; i ++ , group ++ ) {
22092206 AOTRelocation * relocation ;
22102207 uint32 name_index ;
2211- uint8 * name_addr ;
22122208
22132209 /* section name address is 4 bytes aligned. */
22142210 buf = (uint8 * )align_ptr (buf , sizeof (uint32 ));
@@ -2220,8 +2216,12 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
22202216 goto fail ;
22212217 }
22222218
2223- name_addr = symbol_buf + symbol_offsets [name_index ];
2224- read_string (name_addr , buf_end , group -> section_name );
2219+ if (symbols [name_index ] == NULL ) {
2220+ uint8 * name_addr = symbol_buf + symbol_offsets [name_index ];
2221+
2222+ read_string (name_addr , buf_end , symbols [name_index ]);
2223+ }
2224+ group -> section_name = symbols [name_index ];
22252225
22262226 read_uint32 (buf , buf_end , group -> relocation_count );
22272227
@@ -2236,7 +2236,6 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
22362236 /* Load each relocation */
22372237 for (j = 0 ; j < group -> relocation_count ; j ++ , relocation ++ ) {
22382238 uint32 symbol_index ;
2239- uint8 * symbol_addr ;
22402239
22412240 if (sizeof (void * ) == 8 ) {
22422241 read_uint64 (buf , buf_end , relocation -> relocation_offset );
@@ -2258,8 +2257,12 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
22582257 goto fail ;
22592258 }
22602259
2261- symbol_addr = symbol_buf + symbol_offsets [symbol_index ];
2262- read_string (symbol_addr , buf_end , relocation -> symbol_name );
2260+ if (symbols [symbol_index ] == NULL ) {
2261+ uint8 * symbol_addr = symbol_buf + symbol_offsets [symbol_index ];
2262+
2263+ read_string (symbol_addr , buf_end , symbols [symbol_index ]);
2264+ }
2265+ relocation -> symbol_name = symbols [symbol_index ];
22632266 }
22642267
22652268 if (!strcmp (group -> section_name , ".rel.text" )
@@ -2314,14 +2317,20 @@ load_relocation_section(const uint8 *buf, const uint8 *buf_end,
23142317 || !strcmp (data_section -> name , ".rodata" )
23152318 /* ".rodata.cst4/8/16/.." */
23162319 || !strncmp (data_section -> name , ".rodata.cst" ,
2317- strlen (".rodata.cst" ))) {
2320+ strlen (".rodata.cst" ))
2321+ /* ".rodata.strn.m" */
2322+ || !strncmp (data_section -> name , ".rodata.str" ,
2323+ strlen (".rodata.str" ))) {
23182324 os_mprotect (data_section -> data , data_section -> size , map_prot );
23192325 }
23202326 }
23212327
23222328 ret = true;
23232329
23242330fail :
2331+ if (symbols ) {
2332+ wasm_runtime_free (symbols );
2333+ }
23252334 if (groups ) {
23262335 for (i = 0 , group = groups ; i < group_count ; i ++ , group ++ )
23272336 if (group -> relocations )
0 commit comments