Skip to content

Commit ce8ca2c

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 2dc6690 commit ce8ca2c

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
@@ -1639,6 +1639,13 @@ static void kpatch_replace_sections_syms(struct kpatch_elf *kelf)
16391639
if (!is_rela_section(relasec) || is_debug_section(relasec))
16401640
continue;
16411641

1642+
/*
1643+
* We regenerate __patchable_function_entries from scratch so
1644+
* don't bother replacing section symbols in its relasec.
1645+
*/
1646+
if (is_patchable_function_entries_section(relasec))
1647+
continue;
1648+
16421649
list_for_each_entry(rela, &relasec->relas, list) {
16431650

16441651
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 !strncmp(name, "__patchable_function_entries", 28);
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
@@ -136,6 +136,7 @@ struct kpatch_elf {
136136
char *status_str(enum status status);
137137
bool is_rela_section(struct section *sec);
138138
bool is_text_section(struct section *sec);
139+
bool is_patchable_function_entries_section(struct section *sec);
139140
bool is_debug_section(struct section *sec);
140141

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

0 commit comments

Comments
 (0)