Skip to content

Commit

Permalink
kpatch/LoongArch: process section __patchable_function_entries
Browse files Browse the repository at this point in the history
Generate 2 NOPs right at the beginning of each function with
-fpatchable-function-entry=2 in LoongArch. Here process this situation.

Co-developed-by: zhanghongchen <[email protected]>
Signed-off-by: George Guo <[email protected]>
  • Loading branch information
georgejguo committed Dec 11, 2024
1 parent e2ad05f commit f27619f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions kpatch-build/create-diff-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -3838,6 +3838,21 @@ static void kpatch_create_ftrace_callsite_sections(struct kpatch_elf *kelf, bool
insn_offset = sym->sym.st_value;
break;
}
case LOONGARCH64: {
bool found = false;
unsigned char *insn = sym->sec->data->d_buf + sym->sym.st_value;

/* 0x03400000 is NOP instruction for LoongArch. */
if(insn[0] == 0x00 && insn[1] == 0x00 && insn[2] == 0x40 && insn[3] == 0x03 &&
insn[4] == 0x00 && insn[5] == 0x00 && insn[6] == 0x40 && insn[7] == 0x03)
found = true;

if (!found)
ERROR("%s: unexpected instruction at the start of the function", sym->name);

insn_offset = 0;
break;
}
default:
ERROR("unsupported arch");
}
Expand Down Expand Up @@ -4088,6 +4103,12 @@ static void kpatch_find_func_profiling_calls(struct kpatch_elf *kelf)
insn[4] == 0x00 && insn[5] == 0x00)
sym->has_func_profiling = 1;
break;
case LOONGARCH64:

if (kpatch_symbol_has_pfe_entry(kelf, sym))
sym->has_func_profiling = 1;
break;

default:
ERROR("unsupported arch");
}
Expand Down

0 comments on commit f27619f

Please sign in to comment.