Skip to content

Commit 95d93a3

Browse files
committed
create-diff-object: don't mangle .rela.__patchable_function_entries
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>
1 parent 197c679 commit 95d93a3

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

kpatch-build/create-diff-object.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,13 @@ static void kpatch_replace_sections_syms(struct kpatch_elf *kelf)
16451645
if (!is_rela_section(relasec) || is_debug_section(relasec))
16461646
continue;
16471647

1648+
/*
1649+
* We regenerate __patchable_function_entries from scratch so
1650+
* don't bother replacing section symbols in its relasec.
1651+
*/
1652+
if (is_patchable_function_entries_section(relasec))
1653+
continue;
1654+
16481655
list_for_each_entry(rela, &relasec->relas, list) {
16491656

16501657
if (rela->sym->type != STT_SECTION || !rela->sym->sec)

kpatch-build/kpatch-elf.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ bool is_text_section(struct section *sec)
6565
(sec->sh.sh_flags & SHF_EXECINSTR));
6666
}
6767

68+
bool is_patchable_function_entries_section(struct section *sec)
69+
{
70+
char *name;
71+
72+
if (is_rela_section(sec))
73+
name = sec->base->name;
74+
else
75+
name = sec->name;
76+
77+
return !strcmp(name, "__patchable_function_entries");
78+
}
79+
6880
bool is_debug_section(struct section *sec)
6981
{
7082
char *name;

kpatch-build/kpatch-elf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ struct kpatch_elf {
139139
char *status_str(enum status status);
140140
bool is_rela_section(struct section *sec);
141141
bool is_text_section(struct section *sec);
142+
bool is_patchable_function_entries_section(struct section *sec);
142143
bool is_debug_section(struct section *sec);
143144

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

0 commit comments

Comments
 (0)