Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions kpatch-build/create-diff-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1992,6 +1992,8 @@ static void kpatch_migrate_included_elements(struct kpatch_elf *kelf, struct kpa
ERROR("malloc");
memset(out, 0, sizeof(*out));
out->arch = kelf->arch;
out->has_pfe = kelf->has_pfe;
out->pfe_ordered = kelf->pfe_ordered;
INIT_LIST_HEAD(&out->sections);
INIT_LIST_HEAD(&out->symbols);
INIT_LIST_HEAD(&out->strings);
Expand Down Expand Up @@ -3729,7 +3731,7 @@ static void kpatch_set_pfe_link(struct kpatch_elf *kelf)
* TODO: Eventually we can modify recordmount so that it recognizes our bundled
* sections as valid and does this work for us.
*/
static void kpatch_create_ftrace_callsite_sections(struct kpatch_elf *kelf, bool has_pfe)
static void kpatch_create_ftrace_callsite_sections(struct kpatch_elf *kelf)
{
int nr, index;
struct section *sec = NULL;
Expand All @@ -3745,13 +3747,7 @@ static void kpatch_create_ftrace_callsite_sections(struct kpatch_elf *kelf, bool
sym->has_func_profiling)
nr++;

if (has_pfe)
/*
* Create separate __patchable_function_entries sections
* for each function in the following loop.
*/
kelf->has_pfe = true;
else
if (!kelf->has_pfe)
/*
* Create a single __mcount_loc section pair for all
* functions.
Expand Down Expand Up @@ -3858,7 +3854,14 @@ static void kpatch_create_ftrace_callsite_sections(struct kpatch_elf *kelf, bool
* - its lone rela is based on the section symbol
*/
sec = create_section_pair(kelf, "__patchable_function_entries", sizeof(void *), 1);
sec->sh.sh_flags |= SHF_WRITE | SHF_ALLOC | SHF_LINK_ORDER;
sec->sh.sh_flags |= SHF_WRITE | SHF_ALLOC;
/*
* Old linkers don't support mixing ordered and unordered sections, so set
* the SHF_LINK_ORDER flag only if it is set in the pfe section generated by
* the compiler.
*/
if (kelf->pfe_ordered)
sec->sh.sh_flags |= SHF_LINK_ORDER;
rela_sym = sym->sec->secsym;
rela_offset = 0;
rela_sym->pfe = sec;
Expand Down Expand Up @@ -4158,7 +4161,6 @@ int main(int argc, char *argv[])
struct section *relasec, *symtab;
char *orig_obj, *patched_obj, *parent_name;
char *parent_symtab, *mod_symvers, *patch_name, *output_obj;
bool has_pfe = false;

memset(&arguments, 0, sizeof(arguments));
argp_parse (&argp, argc, argv, 0, NULL, &arguments);
Expand All @@ -4184,8 +4186,6 @@ int main(int argc, char *argv[])

kpatch_set_pfe_link(kelf_orig);
kpatch_set_pfe_link(kelf_patched);
if (kelf_patched->has_pfe)
has_pfe = true;

kpatch_find_func_profiling_calls(kelf_orig);
kpatch_find_func_profiling_calls(kelf_patched);
Expand Down Expand Up @@ -4266,7 +4266,7 @@ int main(int argc, char *argv[])
kpatch_create_callbacks_objname_rela(kelf_out, parent_name);
kpatch_build_strings_section_data(kelf_out);

kpatch_create_ftrace_callsite_sections(kelf_out, has_pfe);
kpatch_create_ftrace_callsite_sections(kelf_out);

/*
* At this point, the set of output sections and symbols is
Expand Down
13 changes: 11 additions & 2 deletions kpatch-build/kpatch-elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ struct kpatch_elf *kpatch_elf_open(const char *name)
int fd;
struct kpatch_elf *kelf;
struct section *relasec;
struct section *pfesec;
GElf_Ehdr ehdr;

fd = open(name, O_RDONLY);
Expand Down Expand Up @@ -614,9 +615,17 @@ struct kpatch_elf *kpatch_elf_open(const char *name)
* These sections aren't used by ftrace on this arch, so do not
* bother reading/writing them for x86_64.
*/
if (kelf->arch != X86_64)
if (find_section_by_name(&kelf->sections, "__patchable_function_entries"))
if (kelf->arch != X86_64) {
pfesec = find_section_by_name(&kelf->sections, "__patchable_function_entries");
if (pfesec) {
kelf->has_pfe = true;
/*
* Check if the pfe section generated by the toolchain has the SHF_LINK_ORDER
* flag set. This info is used while generating pfe sections in the diff object.
*/
kelf->pfe_ordered = !!(pfesec->sh.sh_flags & SHF_LINK_ORDER);
}
}

return kelf;
}
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 @@ -127,6 +127,7 @@ struct kpatch_elf {
Elf_Data *symtab_shndx;
int fd;
bool has_pfe;
bool pfe_ordered;
};

/*******************
Expand Down