diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c index 4822893..0efe881 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c @@ -776,6 +776,13 @@ do { \ } \ } while (0) +#define UNCORRELATE_ELEMENT(_elem_) \ +do { \ + typeof(_elem_) elem = (_elem_); \ + elem->twin->twin = NULL; \ + elem->twin = NULL; \ +} while (0) + static void __kpatch_correlate_section(struct section *sec1, struct section *sec2) { CORRELATE_ELEMENT(sec1, sec2, "section"); @@ -786,6 +793,11 @@ static void kpatch_correlate_symbol(struct symbol *sym1, struct symbol *sym2) CORRELATE_ELEMENT(sym1, sym2, "symbol"); } +static void kpatch_correlate_static_local(struct symbol *sym1, struct symbol *sym2) +{ + CORRELATE_ELEMENT(sym1, sym2, "static local"); +} + static void kpatch_correlate_section(struct section *sec1, struct section *sec2) { __kpatch_correlate_section(sec1, sec2); @@ -1036,23 +1048,17 @@ static void kpatch_correlate_static_local_variables(struct kpatch_elf *base, if (!kpatch_is_normal_static_local(sym)) continue; - if (sym->twin) { - sym->twin->twin = NULL; - sym->twin = NULL; - } + if (sym->twin) + UNCORRELATE_ELEMENT(sym); bundled = sym == sym->sec->sym; if (bundled && sym->sec->twin) { - sym->sec->twin->twin = NULL; - sym->sec->twin = NULL; + UNCORRELATE_ELEMENT(sym->sec); - sym->sec->secsym->twin->twin = NULL; - sym->sec->secsym->twin = NULL; + UNCORRELATE_ELEMENT(sym->sec->secsym); - if (sym->sec->rela) { - sym->sec->rela->twin->twin = NULL; - sym->sec->rela->twin = NULL; - } + if (sym->sec->rela) + UNCORRELATE_ELEMENT(sym->sec->rela); } } @@ -1106,28 +1112,10 @@ static void kpatch_correlate_static_local_variables(struct kpatch_elf *base, ERROR("sections %s and %s aren't correlated for symbol %s", sym->sec->name, patched_sym->sec->name, sym->name); - log_debug("renaming and correlating static local %s to %s\n", - patched_sym->name, sym->name); + kpatch_correlate_static_local(sym, patched_sym); - patched_sym->name = strdup(sym->name); - sym->twin = patched_sym; - patched_sym->twin = sym; - - /* set initial status, might change */ - sym->status = patched_sym->status = SAME; - - if (bundled) { - sym->sec->twin = patched_sym->sec; - patched_sym->sec->twin = sym->sec; - - sym->sec->secsym->twin = patched_sym->sec->secsym; - patched_sym->sec->secsym->twin = sym->sec->secsym; - - if (sym->sec->rela && patched_sym->sec->rela) { - sym->sec->rela->twin = patched_sym->sec->rela; - patched_sym->sec->rela->twin = sym->sec->rela; - } - } + if (bundled) + kpatch_correlate_section(sym->sec, patched_sym->sec); } }