create-diff-object: Check __patchable_function_entries section for aarch64

Add aarch64 support to kpatch_create_ftrace_callsite_sections(). Check
for the 2 required NOP instructions on function entry, which may be
preceded by a BTI C instruction depending on whether the
function is a leaf function. This determines the offset of the
patch site.

Signed-off-by: Pete Swain <swine@google.com>
Signed-off-by: Puranjay Mohan <pjy@amazon.com>
This commit is contained in:
Pete Swain 2025-01-24 14:37:21 +00:00 committed by Puranjay Mohan
parent 18f2aa35eb
commit acd02314e5

View File

@ -3755,6 +3755,30 @@ static void kpatch_create_ftrace_callsite_sections(struct kpatch_elf *kelf, bool
}
switch(kelf->arch) {
case AARCH64: {
unsigned char *insn = sym->sec->data->d_buf;
int i;
/*
* If BTI (Branch Target Identification) is enabled then there
* might be an additional 'BTI C' instruction before the two
* patchable function entry 'NOP's.
* i.e. 0xd503245f (little endian)
*/
if (insn[0] == 0x5f) {
if (insn[1] != 0x24 || insn[2] != 0x03 || insn[3] != 0xd5)
ERROR("%s: unexpected instruction in patch section of function\n", sym->name);
insn_offset += 4;
insn += 4;
}
for (i = 0; i < 8; i += 4) {
/* We expect a NOP i.e. 0xd503201f (little endian) */
if (insn[i] != 0x1f || insn[i + 1] != 0x20 ||
insn[i + 2] != 0x03 || insn [i + 3] != 0xd5)
ERROR("%s: unexpected instruction in patch section of function\n", sym->name);
}
break;
}
case PPC64: {
unsigned char *insn;