@@ -920,9 +920,11 @@ get_relocations_size(AOTObjectData *obj_data,
920920 /* ignore the relocations to aot_func_internal#n in text section
921921 for windows platform since they will be applied in
922922 aot_emit_text_section */
923+
924+ const char * name = relocation -> symbol_name ;
923925 if ((!strcmp (relocation_group -> section_name , ".text" )
924926 || !strcmp (relocation_group -> section_name , ".ltext" ))
925- && !strncmp (relocation -> symbol_name , AOT_FUNC_INTERNAL_PREFIX ,
927+ && !strncmp (name , AOT_FUNC_INTERNAL_PREFIX ,
926928 strlen (AOT_FUNC_INTERNAL_PREFIX ))
927929 && ((!strncmp (obj_data -> comp_ctx -> target_arch , "x86_64" , 6 )
928930 /* Windows AOT_COFF64_BIN_TYPE */
@@ -2489,8 +2491,8 @@ aot_emit_text_section(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
24892491 relocation_count = relocation_group -> relocation_count ;
24902492 for (j = 0 ; j < relocation_count ; j ++ ) {
24912493 /* relocation to aot_func_internal#n */
2492- if ( str_starts_with ( relocation -> symbol_name ,
2493- AOT_FUNC_INTERNAL_PREFIX )
2494+ const char * name = relocation -> symbol_name ;
2495+ if ( str_starts_with ( name , AOT_FUNC_INTERNAL_PREFIX )
24942496 && ((obj_data -> target_info .bin_type
24952497 == 6 /* AOT_COFF64_BIN_TYPE */
24962498 && relocation -> relocation_type
@@ -2500,8 +2502,7 @@ aot_emit_text_section(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
25002502 && relocation -> relocation_type
25012503 == 20 /* IMAGE_REL_I386_REL32 */ ))) {
25022504 uint32 func_idx =
2503- atoi (relocation -> symbol_name
2504- + strlen (AOT_FUNC_INTERNAL_PREFIX ));
2505+ atoi (name + strlen (AOT_FUNC_INTERNAL_PREFIX ));
25052506 uint64 text_offset , reloc_offset , reloc_addend ;
25062507
25072508 bh_assert (func_idx < obj_data -> func_count );
@@ -3052,6 +3053,27 @@ typedef struct elf64_rela {
30523053#define SET_TARGET_INFO_FIELD (f , v , type , little ) \
30533054 SET_TARGET_INFO_VALUE(f, elf_header->v, type, little)
30543055
3056+ /* in windows 32, the symbol name may start with '_' */
3057+ static char *
3058+ LLVMGetSymbolNameAndUnDecorate (LLVMSymbolIteratorRef si ,
3059+ AOTTargetInfo target_info )
3060+ {
3061+ char * original_name = (char * )LLVMGetSymbolName (si );
3062+ if (!original_name ) {
3063+ return NULL ;
3064+ }
3065+
3066+ if (target_info .bin_type != AOT_COFF32_BIN_TYPE ) {
3067+ return original_name ;
3068+ }
3069+
3070+ if (* original_name == '_' ) {
3071+ return ++ original_name ;
3072+ }
3073+
3074+ return original_name ;
3075+ }
3076+
30553077static bool
30563078aot_resolve_target_info (AOTCompContext * comp_ctx , AOTObjectData * obj_data )
30573079{
@@ -3526,12 +3548,9 @@ aot_resolve_stack_sizes(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
35263548 }
35273549
35283550 while (!LLVMObjectFileIsSymbolIteratorAtEnd (obj_data -> binary , sym_itr )) {
3529- if ((name = LLVMGetSymbolName (sym_itr ))
3530- && (!strcmp (name , aot_stack_sizes_alias_name )
3531- /* symbol of COFF32 starts with "_" */
3532- || (obj_data -> target_info .bin_type == AOT_COFF32_BIN_TYPE
3533- && !strncmp (name , "_" , 1 )
3534- && !strcmp (name + 1 , aot_stack_sizes_alias_name )))) {
3551+ if ((name =
3552+ LLVMGetSymbolNameAndUnDecorate (sym_itr , obj_data -> target_info ))
3553+ && (!strcmp (name , aot_stack_sizes_alias_name ))) {
35353554#if 0 /* cf. https://github.com/llvm/llvm-project/issues/67765 */
35363555 uint64 sz = LLVMGetSymbolSize (sym_itr );
35373556 if (sz != sizeof (uint32 ) * obj_data -> func_count
@@ -3695,8 +3714,8 @@ aot_resolve_functions(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
36953714 }
36963715
36973716 while (!LLVMObjectFileIsSymbolIteratorAtEnd (obj_data -> binary , sym_itr )) {
3698- if (( name = ( char * ) LLVMGetSymbolName ( sym_itr ))
3699- && str_starts_with (name , prefix )) {
3717+ name = LLVMGetSymbolNameAndUnDecorate ( sym_itr , obj_data -> target_info );
3718+ if ( name && str_starts_with (name , prefix )) {
37003719 /* symbol aot_func#n */
37013720 func_index = (uint32 )atoi (name + strlen (prefix ));
37023721 if (func_index < obj_data -> func_count ) {
@@ -3734,8 +3753,7 @@ aot_resolve_functions(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
37343753 }
37353754 }
37363755 }
3737- else if ((name = (char * )LLVMGetSymbolName (sym_itr ))
3738- && str_starts_with (name , AOT_FUNC_INTERNAL_PREFIX )) {
3756+ else if (name && str_starts_with (name , AOT_FUNC_INTERNAL_PREFIX )) {
37393757 /* symbol aot_func_internal#n */
37403758 func_index = (uint32 )atoi (name + strlen (AOT_FUNC_INTERNAL_PREFIX ));
37413759 if (func_index < obj_data -> func_count ) {
@@ -3883,7 +3901,8 @@ aot_resolve_object_relocation_group(AOTObjectData *obj_data,
38833901
38843902 /* set relocation fields */
38853903 relocation -> relocation_type = (uint32 )type ;
3886- relocation -> symbol_name = (char * )LLVMGetSymbolName (rel_sym );
3904+ relocation -> symbol_name =
3905+ LLVMGetSymbolNameAndUnDecorate (rel_sym , obj_data -> target_info );
38873906 relocation -> relocation_offset = offset ;
38883907 if (!strcmp (group -> section_name , ".rela.text.unlikely." )
38893908 || !strcmp (group -> section_name , ".rel.text.unlikely." )) {
@@ -3910,12 +3929,7 @@ aot_resolve_object_relocation_group(AOTObjectData *obj_data,
39103929 * Note: aot_stack_sizes_section_name section only contains
39113930 * stack_sizes table.
39123931 */
3913- if (!strcmp (relocation -> symbol_name , aot_stack_sizes_name )
3914- /* in windows 32, the symbol name may start with '_' */
3915- || (strlen (relocation -> symbol_name ) > 0
3916- && relocation -> symbol_name [0 ] == '_'
3917- && !strcmp (relocation -> symbol_name + 1 ,
3918- aot_stack_sizes_name ))) {
3932+ if (!strcmp (relocation -> symbol_name , aot_stack_sizes_name )) {
39193933 /* discard const */
39203934 relocation -> symbol_name = (char * )aot_stack_sizes_section_name ;
39213935 }
0 commit comments