Skip to content

Commit

Permalink
create-diff-object: don't mangle .rela.__patchable_function_entries
Browse files Browse the repository at this point in the history
kpatch_replace_sections_syms() substitutes the object/function symbols
for the section symbol in the relocation sections. But relocations in
.rela.__patchable_function_entries can point to an instruction ouside
the function. This is because with CALL_OPS enabled, two NOPs are added
before the function entry. __patchable_function_entries needs the
address of the first NOP above the function.

We anyway generate __patchable_function_entries again in
kpatch_create_ftrace_callsite_sections() so we can skip mangling these
relocations

Signed-off-by: Puranjay Mohan <pjy@amazon.com>
  • Loading branch information
puranjaymohan committed Feb 7, 2025
1 parent 2dc6690 commit ce8ca2c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions kpatch-build/create-diff-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,13 @@ static void kpatch_replace_sections_syms(struct kpatch_elf *kelf)
if (!is_rela_section(relasec) || is_debug_section(relasec))
continue;

/*
* We regenerate __patchable_function_entries from scratch so
* don't bother replacing section symbols in its relasec.
*/
if (is_patchable_function_entries_section(relasec))
continue;

list_for_each_entry(rela, &relasec->relas, list) {

if (rela->sym->type != STT_SECTION || !rela->sym->sec)
Expand Down
12 changes: 12 additions & 0 deletions kpatch-build/kpatch-elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ bool is_text_section(struct section *sec)
(sec->sh.sh_flags & SHF_EXECINSTR));
}

bool is_patchable_function_entries_section(struct section *sec)
{
char *name;

if (is_rela_section(sec))
name = sec->base->name;
else
name = sec->name;

return !strncmp(name, "__patchable_function_entries", 28);
}

bool is_debug_section(struct section *sec)
{
char *name;
Expand Down
1 change: 1 addition & 0 deletions kpatch-build/kpatch-elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ struct kpatch_elf {
char *status_str(enum status status);
bool is_rela_section(struct section *sec);
bool is_text_section(struct section *sec);
bool is_patchable_function_entries_section(struct section *sec);
bool is_debug_section(struct section *sec);

struct section *find_section_by_index(struct list_head *list, unsigned int index);
Expand Down

0 comments on commit ce8ca2c

Please sign in to comment.