@@ -920,9 +920,11 @@ get_relocations_size(AOTObjectData *obj_data,
920
920
/* ignore the relocations to aot_func_internal#n in text section
921
921
for windows platform since they will be applied in
922
922
aot_emit_text_section */
923
+
924
+ const char * name = relocation -> symbol_name ;
923
925
if ((!strcmp (relocation_group -> section_name , ".text" )
924
926
|| !strcmp (relocation_group -> section_name , ".ltext" ))
925
- && !strncmp (relocation -> symbol_name , AOT_FUNC_INTERNAL_PREFIX ,
927
+ && !strncmp (name , AOT_FUNC_INTERNAL_PREFIX ,
926
928
strlen (AOT_FUNC_INTERNAL_PREFIX ))
927
929
&& ((!strncmp (obj_data -> comp_ctx -> target_arch , "x86_64" , 6 )
928
930
/* Windows AOT_COFF64_BIN_TYPE */
@@ -2489,8 +2491,8 @@ aot_emit_text_section(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
2489
2491
relocation_count = relocation_group -> relocation_count ;
2490
2492
for (j = 0 ; j < relocation_count ; j ++ ) {
2491
2493
/* 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 )
2494
2496
&& ((obj_data -> target_info .bin_type
2495
2497
== 6 /* AOT_COFF64_BIN_TYPE */
2496
2498
&& relocation -> relocation_type
@@ -2500,8 +2502,7 @@ aot_emit_text_section(uint8 *buf, uint8 *buf_end, uint32 *p_offset,
2500
2502
&& relocation -> relocation_type
2501
2503
== 20 /* IMAGE_REL_I386_REL32 */ ))) {
2502
2504
uint32 func_idx =
2503
- atoi (relocation -> symbol_name
2504
- + strlen (AOT_FUNC_INTERNAL_PREFIX ));
2505
+ atoi (name + strlen (AOT_FUNC_INTERNAL_PREFIX ));
2505
2506
uint64 text_offset , reloc_offset , reloc_addend ;
2506
2507
2507
2508
bh_assert (func_idx < obj_data -> func_count );
@@ -3052,6 +3053,27 @@ typedef struct elf64_rela {
3052
3053
#define SET_TARGET_INFO_FIELD (f , v , type , little ) \
3053
3054
SET_TARGET_INFO_VALUE(f, elf_header->v, type, little)
3054
3055
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
+
3055
3077
static bool
3056
3078
aot_resolve_target_info (AOTCompContext * comp_ctx , AOTObjectData * obj_data )
3057
3079
{
@@ -3526,12 +3548,9 @@ aot_resolve_stack_sizes(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
3526
3548
}
3527
3549
3528
3550
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 ))) {
3535
3554
#if 0 /* cf. https://github.com/llvm/llvm-project/issues/67765 */
3536
3555
uint64 sz = LLVMGetSymbolSize (sym_itr );
3537
3556
if (sz != sizeof (uint32 ) * obj_data -> func_count
@@ -3695,8 +3714,8 @@ aot_resolve_functions(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
3695
3714
}
3696
3715
3697
3716
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 )) {
3700
3719
/* symbol aot_func#n */
3701
3720
func_index = (uint32 )atoi (name + strlen (prefix ));
3702
3721
if (func_index < obj_data -> func_count ) {
@@ -3734,8 +3753,7 @@ aot_resolve_functions(AOTCompContext *comp_ctx, AOTObjectData *obj_data)
3734
3753
}
3735
3754
}
3736
3755
}
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 )) {
3739
3757
/* symbol aot_func_internal#n */
3740
3758
func_index = (uint32 )atoi (name + strlen (AOT_FUNC_INTERNAL_PREFIX ));
3741
3759
if (func_index < obj_data -> func_count ) {
@@ -3883,7 +3901,8 @@ aot_resolve_object_relocation_group(AOTObjectData *obj_data,
3883
3901
3884
3902
/* set relocation fields */
3885
3903
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 );
3887
3906
relocation -> relocation_offset = offset ;
3888
3907
if (!strcmp (group -> section_name , ".rela.text.unlikely." )
3889
3908
|| !strcmp (group -> section_name , ".rel.text.unlikely." )) {
@@ -3910,12 +3929,7 @@ aot_resolve_object_relocation_group(AOTObjectData *obj_data,
3910
3929
* Note: aot_stack_sizes_section_name section only contains
3911
3930
* stack_sizes table.
3912
3931
*/
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 )) {
3919
3933
/* discard const */
3920
3934
relocation -> symbol_name = (char * )aot_stack_sizes_section_name ;
3921
3935
}
0 commit comments