From 394a907a3708e9efdcd0c282ca0ba1583398675c Mon Sep 17 00:00:00 2001 From: Joe Lawrence Date: Fri, 21 Jan 2022 12:02:20 -0500 Subject: [PATCH] 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 --- kpatch-build/create-diff-object.c | 31 +++++++++++++++++++++++++++++++ kpatch-build/kpatch-elf.c | 30 ------------------------------ 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c index f0156d9..3d4a6ae 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c @@ -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); diff --git a/kpatch-build/kpatch-elf.c b/kpatch-build/kpatch-elf.c index 7e272e2..bbeec6a 100644 --- a/kpatch-build/kpatch-elf.c +++ b/kpatch-build/kpatch-elf.c @@ -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; }