@@ -2784,22 +2784,6 @@ static void load_elf_image(const char *image_name, int image_fd,
2784
2784
info -> brk = 0 ;
2785
2785
info -> elf_flags = ehdr -> e_flags ;
2786
2786
2787
- if (!afl_entry_point ) {
2788
- char * ptr ;
2789
- if ((ptr = getenv ("AFL_ENTRYPOINT" )) != NULL ) {
2790
- afl_entry_point = strtoul (ptr , NULL , 16 );
2791
- } else {
2792
- afl_entry_point = info -> entry ;
2793
- }
2794
- #ifdef TARGET_ARM
2795
- /* The least significant bit indicates Thumb mode. */
2796
- afl_entry_point = afl_entry_point & ~(target_ulong )1 ;
2797
- #endif
2798
- }
2799
- if (getenv ("AFL_DEBUG" ) != NULL )
2800
- fprintf (stderr , "AFL forkserver entrypoint: 0x%lx\n" ,
2801
- (unsigned long )afl_entry_point );
2802
-
2803
2787
prot_exec = PROT_EXEC ;
2804
2788
#ifdef TARGET_AARCH64
2805
2789
/*
@@ -2928,6 +2912,38 @@ static void load_elf_image(const char *image_name, int image_fd,
2928
2912
load_symbols (ehdr , image_fd , load_bias );
2929
2913
}
2930
2914
2915
+ if (!afl_entry_point ) {
2916
+ char * ptr ;
2917
+ if ((ptr = getenv ("AFL_ENTRYPOINT" )) != NULL ) {
2918
+ afl_entry_point = strtoul (ptr , NULL , 16 );
2919
+ } else {
2920
+ // On PowerPC64 the entry point is the _function descriptor_
2921
+ // of the entry function. For AFL to properly initialize,
2922
+ // afl_entry_point needs to be set to the actual first instruction
2923
+ // as opposed executed by the target program. This as opposed to
2924
+ // where the function's descriptor sits in memory.
2925
+ // copied from PPC init_thread
2926
+ #if defined(TARGET_PPC64 ) && !defined(TARGET_ABI32 )
2927
+ if (get_ppc64_abi (info ) < 2 ) {
2928
+ uint64_t val ;
2929
+ get_user_u64 (val , info -> entry );
2930
+ afl_entry_point = val + info -> load_bias ;
2931
+ } else {
2932
+ afl_entry_point = info -> entry ;
2933
+ }
2934
+ #else
2935
+ afl_entry_point = info -> entry ;
2936
+ #endif
2937
+ }
2938
+ #ifdef TARGET_ARM
2939
+ /* The least significant bit indicates Thumb mode. */
2940
+ afl_entry_point = afl_entry_point & ~(target_ulong )1 ;
2941
+ #endif
2942
+ }
2943
+ if (getenv ("AFL_DEBUG" ) != NULL )
2944
+ fprintf (stderr , "AFL forkserver entrypoint: 0x%lx\n" ,
2945
+ (unsigned long )afl_entry_point );
2946
+
2931
2947
mmap_unlock ();
2932
2948
2933
2949
close (image_fd );
@@ -3188,22 +3204,6 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
3188
3204
change some of these later */
3189
3205
bprm -> p = setup_arg_pages (bprm , info );
3190
3206
3191
- // On PowerPC64 the entry point is the _function descriptor_
3192
- // of the entry function. For AFL to properly initialize,
3193
- // afl_entry_point needs to be set to the actual first instruction
3194
- // as opposed executed by the target program. This as opposed to
3195
- // where the function's descriptor sits in memory.
3196
- // copied from PPC init_thread
3197
- #if defined(TARGET_PPC64 ) && !defined(TARGET_ABI32 )
3198
- if (get_ppc64_abi (infop ) < 2 ) {
3199
- uint64_t val ;
3200
- get_user_u64 (val , infop -> entry + 8 );
3201
- _regs -> gpr [2 ] = val + infop -> load_bias ;
3202
- get_user_u64 (val , infop -> entry );
3203
- infop -> entry = val + infop -> load_bias ;
3204
- }
3205
- #endif
3206
-
3207
3207
scratch = g_new0 (char , TARGET_PAGE_SIZE );
3208
3208
if (STACK_GROWS_DOWN ) {
3209
3209
bprm -> p = copy_elf_strings (1 , & bprm -> filename , scratch ,
0 commit comments