mirror of https://github.com/dynup/kpatch
create-diff-object: add is_callback_section() helper
This simplifies the code a bit. Also this helper will be needed for subsequent patches. Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
This commit is contained in:
parent
5665d06853
commit
14cc8a013d
|
@ -1256,6 +1256,28 @@ static void rela_insn(struct section *sec, struct rela *rela, struct insn *insn)
|
|||
}
|
||||
#endif
|
||||
|
||||
static bool is_callback_section(struct section *sec) {
|
||||
|
||||
static char *callback_sections[] = {
|
||||
".kpatch.callbacks.pre_patch",
|
||||
".kpatch.callbacks.post_patch",
|
||||
".kpatch.callbacks.pre_unpatch",
|
||||
".kpatch.callbacks.post_unpatch",
|
||||
".rela.kpatch.callbacks.pre_patch",
|
||||
".rela.kpatch.callbacks.post_patch",
|
||||
".rela.kpatch.callbacks.pre_unpatch",
|
||||
".rela.kpatch.callbacks.post_unpatch",
|
||||
NULL,
|
||||
};
|
||||
char **callback_sec;
|
||||
|
||||
for (callback_sec = callback_sections; *callback_sec; callback_sec++)
|
||||
if (!strcmp(sec->name, *callback_sec))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Mangle the relas a little. The compiler will sometimes use section symbols
|
||||
* to reference local objects and functions rather than the object or function
|
||||
|
@ -1550,33 +1572,16 @@ static int kpatch_include_callback_elements(struct kpatch_elf *kelf)
|
|||
struct rela *rela;
|
||||
int found = 0;
|
||||
|
||||
static char *callback_sections[] = {
|
||||
".kpatch.callbacks.pre_patch",
|
||||
".kpatch.callbacks.post_patch",
|
||||
".kpatch.callbacks.pre_unpatch",
|
||||
".kpatch.callbacks.post_unpatch",
|
||||
".rela.kpatch.callbacks.pre_patch",
|
||||
".rela.kpatch.callbacks.post_patch",
|
||||
".rela.kpatch.callbacks.pre_unpatch",
|
||||
".rela.kpatch.callbacks.post_unpatch",
|
||||
NULL,
|
||||
};
|
||||
char **callback_section;
|
||||
|
||||
/* include load/unload sections */
|
||||
list_for_each_entry(sec, &kelf->sections, list) {
|
||||
|
||||
for (callback_section = callback_sections; *callback_section; callback_section++) {
|
||||
|
||||
if (strcmp(*callback_section, sec->name))
|
||||
if (!is_callback_section(sec))
|
||||
continue;
|
||||
|
||||
sec->include = 1;
|
||||
found = 1;
|
||||
if (is_rela_section(sec)) {
|
||||
/* include callback dependencies */
|
||||
rela = list_entry(sec->relas.next,
|
||||
struct rela, list);
|
||||
rela = list_entry(sec->relas.next, struct rela, list);
|
||||
sym = rela->sym;
|
||||
log_normal("found callback: %s\n",sym->name);
|
||||
kpatch_include_symbol(sym);
|
||||
|
@ -1589,18 +1594,11 @@ static int kpatch_include_callback_elements(struct kpatch_elf *kelf)
|
|||
sec->secsym->include = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Strip temporary global structures used by the callback macros. */
|
||||
list_for_each_entry(sym, &kelf->symbols, list) {
|
||||
if (!sym->sec)
|
||||
continue;
|
||||
for (callback_section = callback_sections; *callback_section; callback_section++) {
|
||||
if (!strcmp(*callback_section, sym->sec->name)) {
|
||||
if (sym->sec && is_callback_section(sym->sec))
|
||||
sym->include = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
|
|
Loading…
Reference in New Issue