@@ -922,10 +922,6 @@ get_relocations_size(AOTObjectData *obj_data,
922922 aot_emit_text_section */
923923
924924 const char * name = relocation -> symbol_name ;
925- if (name && obj_data -> target_info .bin_type == AOT_COFF32_BIN_TYPE
926- && * name == '_' ) {
927- name ++ ;
928- }
929925 if ((!strcmp (relocation_group -> section_name , ".text" )
930926 || !strcmp (relocation_group -> section_name , ".ltext" ))
931927 && !strncmp (name , AOT_FUNC_INTERNAL_PREFIX ,
@@ -2496,11 +2492,6 @@ aot_emit_text_section(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
24962492 for (j = 0 ; j < relocation_count ; j ++ ) {
24972493 /* relocation to aot_func_internal#n */
24982494 const char * name = relocation -> symbol_name ;
2499- if (name
2500- && obj_data -> target_info .bin_type == AOT_COFF32_BIN_TYPE
2501- && * name == '_' ) {
2502- name ++ ;
2503- }
25042495 if (str_starts_with (name , AOT_FUNC_INTERNAL_PREFIX )
25052496 && ((obj_data -> target_info .bin_type
25062497 == 6 /* AOT_COFF64_BIN_TYPE */
@@ -3062,6 +3053,27 @@ typedef struct elf64_rela {
30623053#define SET_TARGET_INFO_FIELD (f , v , type , little ) \
30633054 SET_TARGET_INFO_VALUE(f, elf_header->v, type, little)
30643055
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+
30653077static bool
30663078aot_resolve_target_info (AOTCompContext * comp_ctx , AOTObjectData * obj_data )
30673079{
@@ -3536,12 +3548,9 @@ aot_resolve_stack_sizes(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
35363548 }
35373549
35383550 while (!LLVMObjectFileIsSymbolIteratorAtEnd (obj_data -> binary , sym_itr )) {
3539- if ((name = LLVMGetSymbolName (sym_itr ))
3540- && (!strcmp (name , aot_stack_sizes_alias_name )
3541- /* symbol of COFF32 starts with "_" */
3542- || (obj_data -> target_info .bin_type == AOT_COFF32_BIN_TYPE
3543- && !strncmp (name , "_" , 1 )
3544- && !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 ))) {
35453554#if 0 /* cf. https://github.com/llvm/llvm-project/issues/67765 */
35463555 uint64 sz = LLVMGetSymbolSize (sym_itr );
35473556 if (sz != sizeof (uint32 ) * obj_data -> func_count
@@ -3705,11 +3714,7 @@ aot_resolve_functions(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
37053714 }
37063715
37073716 while (!LLVMObjectFileIsSymbolIteratorAtEnd (obj_data -> binary , sym_itr )) {
3708- name = (char * )LLVMGetSymbolName (sym_itr );
3709- if (name && obj_data -> target_info .bin_type == AOT_COFF32_BIN_TYPE
3710- && * name == '_' ) {
3711- name ++ ;
3712- }
3717+ name = LLVMGetSymbolNameAndUnDecorate (sym_itr , obj_data -> target_info );
37133718 if (name && str_starts_with (name , prefix )) {
37143719 /* symbol aot_func#n */
37153720 func_index = (uint32 )atoi (name + strlen (prefix ));
@@ -3896,7 +3901,8 @@ aot_resolve_object_relocation_group(AOTObjectData *obj_data,
38963901
38973902 /* set relocation fields */
38983903 relocation -> relocation_type = (uint32 )type ;
3899- relocation -> symbol_name = (char * )LLVMGetSymbolName (rel_sym );
3904+ relocation -> symbol_name =
3905+ LLVMGetSymbolNameAndUnDecorate (rel_sym , obj_data -> target_info );
39003906 relocation -> relocation_offset = offset ;
39013907 if (!strcmp (group -> section_name , ".rela.text.unlikely." )
39023908 || !strcmp (group -> section_name , ".rel.text.unlikely." )) {
@@ -3923,12 +3929,7 @@ aot_resolve_object_relocation_group(AOTObjectData *obj_data,
39233929 * Note: aot_stack_sizes_section_name section only contains
39243930 * stack_sizes table.
39253931 */
3926- if (!strcmp (relocation -> symbol_name , aot_stack_sizes_name )
3927- /* in windows 32, the symbol name may start with '_' */
3928- || (strlen (relocation -> symbol_name ) > 0
3929- && relocation -> symbol_name [0 ] == '_'
3930- && !strcmp (relocation -> symbol_name + 1 ,
3931- aot_stack_sizes_name ))) {
3932+ if (!strcmp (relocation -> symbol_name , aot_stack_sizes_name )) {
39323933 /* discard const */
39333934 relocation -> symbol_name = (char * )aot_stack_sizes_section_name ;
39343935 }
0 commit comments