create-diff-object: move kpatch_find_func_profiling_calls definition

The last part of kpatch_elf_open() calls kpatch_find_func_profiling_calls() to
find and set sym->has_func_profiling.  However, only create-diff-object.c
requires sym->has_func_profiling, so remove the call from
kpatch_elf_open() and let the lone user, create-diff-object, provide and
call it as needed.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
This commit is contained in:
Joe Lawrence 2022-01-21 12:02:20 -05:00
parent aa33ee7dff
commit 394a907a37
2 changed files with 31 additions and 30 deletions

View File

@ -3665,6 +3665,35 @@ static void kpatch_no_sibling_calls_ppc64le(struct kpatch_elf *kelf)
#endif
}
/* Check which functions have fentry/mcount calls; save this info for later use. */
static void kpatch_find_func_profiling_calls(struct kpatch_elf *kelf)
{
struct symbol *sym;
struct rela *rela;
list_for_each_entry(sym, &kelf->symbols, list) {
if (sym->type != STT_FUNC || !sym->sec || !sym->sec->rela)
continue;
#ifdef __powerpc64__
list_for_each_entry(rela, &sym->sec->rela->relas, list) {
if (!strcmp(rela->sym->name, "_mcount")) {
sym->has_func_profiling = 1;
break;
}
}
#else
rela = list_first_entry(&sym->sec->rela->relas, struct rela,
list);
if ((rela->type != R_X86_64_NONE &&
rela->type != R_X86_64_PC32 &&
rela->type != R_X86_64_PLT32) ||
strcmp(rela->sym->name, "__fentry__"))
continue;
sym->has_func_profiling = 1;
#endif
}
}
struct arguments {
char *args[7];
bool debug, klp_arch;
@ -3741,7 +3770,9 @@ int main(int argc, char *argv[])
childobj = basename(orig_obj);
kelf_orig = kpatch_elf_open(orig_obj);
kpatch_find_func_profiling_calls(kelf_orig);
kelf_patched = kpatch_elf_open(patched_obj);
kpatch_find_func_profiling_calls(kelf_patched);
kpatch_compare_elf_headers(kelf_orig->elf, kelf_patched->elf);
kpatch_check_program_headers(kelf_orig->elf);

View File

@ -317,35 +317,6 @@ void kpatch_create_symbol_list(struct kpatch_elf *kelf)
}
/* Check which functions have fentry/mcount calls; save this info for later use. */
static void kpatch_find_func_profiling_calls(struct kpatch_elf *kelf)
{
struct symbol *sym;
struct rela *rela;
list_for_each_entry(sym, &kelf->symbols, list) {
if (sym->type != STT_FUNC || !sym->sec || !sym->sec->rela)
continue;
#ifdef __powerpc64__
list_for_each_entry(rela, &sym->sec->rela->relas, list) {
if (!strcmp(rela->sym->name, "_mcount")) {
sym->has_func_profiling = 1;
break;
}
}
#else
rela = list_first_entry(&sym->sec->rela->relas, struct rela,
list);
if ((rela->type != R_X86_64_NONE &&
rela->type != R_X86_64_PC32 &&
rela->type != R_X86_64_PLT32) ||
strcmp(rela->sym->name, "__fentry__"))
continue;
sym->has_func_profiling = 1;
#endif
}
}
struct kpatch_elf *kpatch_elf_open(const char *name)
{
Elf *elf;
@ -383,7 +354,6 @@ struct kpatch_elf *kpatch_elf_open(const char *name)
kpatch_create_rela_list(kelf, sec);
}
kpatch_find_func_profiling_calls(kelf);
return kelf;
}