Skip to content

Commit 1c85437

Browse files
committed
kpatch/LoongArch: process section __patchable_function_entries
Generate 2 NOPs right at the beginning of each function with -fpatchable-function-entry=2 in LoongArch. Here process the situation. Co-developed-by: zhanghongchen <[email protected]> Signed-off-by: George Guo <[email protected]>
1 parent 4b4ed51 commit 1c85437

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

kpatch-build/create-diff-object.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3838,6 +3838,20 @@ static void kpatch_create_ftrace_callsite_sections(struct kpatch_elf *kelf, bool
38383838
insn_offset = sym->sym.st_value;
38393839
break;
38403840
}
3841+
case LOONGARCH64: {
3842+
#define LOONGARCH_NOP 0x03400000
3843+
bool found = false;
3844+
unsigned int *insn = sym->sec->data->d_buf + sym->sym.st_value;
3845+
3846+
if (*insn == LOONGARCH_NOP && *(insn + 1) == LOONGARCH_NOP)
3847+
found = true;
3848+
3849+
if (!found)
3850+
ERROR("%s: unexpected instruction at the start of the function", sym->name);
3851+
3852+
insn_offset = 0;
3853+
break;
3854+
}
38413855
default:
38423856
ERROR("unsupported arch");
38433857
}
@@ -4088,6 +4102,23 @@ static void kpatch_find_func_profiling_calls(struct kpatch_elf *kelf)
40884102
insn[4] == 0x00 && insn[5] == 0x00)
40894103
sym->has_func_profiling = 1;
40904104
break;
4105+
case LOONGARCH64:
4106+
struct section *sec;
4107+
4108+
sec = find_section_by_name(&kelf->sections,
4109+
"__patchable_function_entries");
4110+
if (sec) {
4111+
list_for_each_entry(rela, &sec->rela->relas, list) {
4112+
if (rela->sym->sec == sym->sec &&
4113+
(rela->sym->sym.st_value +
4114+
rela->addend) == sym->sym.st_value) {
4115+
sym->has_func_profiling = 1;
4116+
break;
4117+
}
4118+
}
4119+
}
4120+
break;
4121+
40914122
default:
40924123
ERROR("unsupported arch");
40934124
}

0 commit comments

Comments
 (0)