From 19c4b52105dac1a269a3dbc48d2b4ca69a98a4b3 Mon Sep 17 00:00:00 2001 From: Artem Savkov Date: Thu, 26 Jul 2018 11:43:57 +0200 Subject: [PATCH] create-diff-object: -mcount-record support 4.18 adds -mcount-record to KBUILD_FLAGS when supported by the compiler. This results in most of kpatch_create_mcount_sections()'s work being already done, so we can at least skip the last part of it that updates the first instruction in patched functions. Signed-off-by: Artem Savkov --- kpatch-build/create-diff-object.c | 26 +++++++++++++++++--------- kpatch-build/kpatch-elf.c | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c index 84dcc90..3e71609 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c @@ -3056,18 +3056,26 @@ static void kpatch_create_mcount_sections(struct kpatch_elf *kelf) memcpy(newdata, sym->sec->data->d_buf, sym->sec->data->d_size); sym->sec->data->d_buf = newdata; insn = newdata; - if (insn[0] != 0xf) - ERROR("%s: unexpected instruction at the start of the function", - sym->name); - insn[0] = 0xe8; - insn[1] = 0; - insn[2] = 0; - insn[3] = 0; - insn[4] = 0; rela = list_first_entry(&sym->sec->rela->relas, struct rela, list); - rela->type = R_X86_64_PC32; + + /* + * R_X86_64_NONE is only generated by older versions of kernel/gcc + * which use the mcount script. + */ + if (rela->type == R_X86_64_NONE) { + if (insn[0] != 0xf) + ERROR("%s: unexpected instruction at the start of the function", + sym->name); + insn[0] = 0xe8; + insn[1] = 0; + insn[2] = 0; + insn[3] = 0; + insn[4] = 0; + + rela->type = R_X86_64_PC32; + } index++; } diff --git a/kpatch-build/kpatch-elf.c b/kpatch-build/kpatch-elf.c index fcb7161..4f08128 100644 --- a/kpatch-build/kpatch-elf.c +++ b/kpatch-build/kpatch-elf.c @@ -332,7 +332,7 @@ static void kpatch_find_func_profiling_calls(struct kpatch_elf *kelf) #else rela = list_first_entry(&sym->sec->rela->relas, struct rela, list); - if (rela->type != R_X86_64_NONE || + if ((rela->type != R_X86_64_NONE && rela->type != R_X86_64_PC32) || strcmp(rela->sym->name, "__fentry__")) continue;