@@ -880,6 +880,51 @@ static int kexec_calculate_store_digests(struct kimage *image)
880880 return ret ;
881881}
882882
883+ #if defined(CONFIG_ARCH_SUPPORTS_KEXEC_PURGATORY ) || defined(CONFIG_KEXEC_PE_IMAGE )
884+ const Elf_Sym * elf_find_symbol (const Elf_Ehdr * ehdr , const char * name )
885+ {
886+ const Elf_Shdr * sechdrs ;
887+ const Elf_Sym * syms ;
888+ const char * strtab ;
889+ int i , k ;
890+
891+ sechdrs = (void * )ehdr + ehdr -> e_shoff ;
892+
893+ for (i = 0 ; i < ehdr -> e_shnum ; i ++ ) {
894+ if (sechdrs [i ].sh_type != SHT_SYMTAB )
895+ continue ;
896+
897+ if (sechdrs [i ].sh_link >= ehdr -> e_shnum )
898+ /* Invalid strtab section number */
899+ continue ;
900+ strtab = (void * )ehdr + sechdrs [sechdrs [i ].sh_link ].sh_offset ;
901+ syms = (void * )ehdr + sechdrs [i ].sh_offset ;
902+
903+ /* Go through symbols for a match */
904+ for (k = 0 ; k < sechdrs [i ].sh_size /sizeof (Elf_Sym ); k ++ ) {
905+ if (ELF_ST_BIND (syms [k ].st_info ) != STB_GLOBAL )
906+ continue ;
907+
908+ if (strcmp (strtab + syms [k ].st_name , name ) != 0 )
909+ continue ;
910+
911+ if (syms [k ].st_shndx == SHN_UNDEF ||
912+ syms [k ].st_shndx >= ehdr -> e_shnum ) {
913+ pr_debug ("Symbol: %s has bad section index %d.\n" ,
914+ name , syms [k ].st_shndx );
915+ return NULL ;
916+ }
917+
918+ /* Found the symbol we are looking for */
919+ return & syms [k ];
920+ }
921+ }
922+
923+ return NULL ;
924+ }
925+
926+ #endif
927+
883928#ifdef CONFIG_ARCH_SUPPORTS_KEXEC_PURGATORY
884929/*
885930 * kexec_purgatory_setup_kbuf - prepare buffer to load purgatory.
@@ -1137,49 +1182,10 @@ int kexec_load_purgatory(struct kimage *image, struct kexec_buf *kbuf)
11371182static const Elf_Sym * kexec_purgatory_find_symbol (struct purgatory_info * pi ,
11381183 const char * name )
11391184{
1140- const Elf_Shdr * sechdrs ;
1141- const Elf_Ehdr * ehdr ;
1142- const Elf_Sym * syms ;
1143- const char * strtab ;
1144- int i , k ;
1145-
11461185 if (!pi -> ehdr )
11471186 return NULL ;
11481187
1149- ehdr = pi -> ehdr ;
1150- sechdrs = (void * )ehdr + ehdr -> e_shoff ;
1151-
1152- for (i = 0 ; i < ehdr -> e_shnum ; i ++ ) {
1153- if (sechdrs [i ].sh_type != SHT_SYMTAB )
1154- continue ;
1155-
1156- if (sechdrs [i ].sh_link >= ehdr -> e_shnum )
1157- /* Invalid strtab section number */
1158- continue ;
1159- strtab = (void * )ehdr + sechdrs [sechdrs [i ].sh_link ].sh_offset ;
1160- syms = (void * )ehdr + sechdrs [i ].sh_offset ;
1161-
1162- /* Go through symbols for a match */
1163- for (k = 0 ; k < sechdrs [i ].sh_size /sizeof (Elf_Sym ); k ++ ) {
1164- if (ELF_ST_BIND (syms [k ].st_info ) != STB_GLOBAL )
1165- continue ;
1166-
1167- if (strcmp (strtab + syms [k ].st_name , name ) != 0 )
1168- continue ;
1169-
1170- if (syms [k ].st_shndx == SHN_UNDEF ||
1171- syms [k ].st_shndx >= ehdr -> e_shnum ) {
1172- pr_debug ("Symbol: %s has bad section index %d.\n" ,
1173- name , syms [k ].st_shndx );
1174- return NULL ;
1175- }
1176-
1177- /* Found the symbol we are looking for */
1178- return & syms [k ];
1179- }
1180- }
1181-
1182- return NULL ;
1188+ return elf_find_symbol (pi -> ehdr , name );
11831189}
11841190
11851191void * kexec_purgatory_get_symbol_addr (struct kimage * image , const char * name )
0 commit comments