Skip to content

Commit 99542e8

Browse files
committed
create-diff-object: rename arguments in most correlate/compare functions
While theoretically most of these functions can work both ways right now all calls follow the same pattern: first argument is orig element and second is patched element. Rename the arguments so that these functions are used in the same fashion going forward. This allows us to cut some corners such as removing the elseif statement in kpatch_correlate_symbol(). Signed-off-by: Artem Savkov <asavkov@redhat.com>
1 parent 22e1661 commit 99542e8

1 file changed

Lines changed: 73 additions & 68 deletions

File tree

kpatch-build/create-diff-object.c

Lines changed: 73 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -918,91 +918,95 @@ do { \
918918
elem->twin = NULL; \
919919
} while (0)
920920

921-
static void __kpatch_correlate_section(struct section *sec1, struct section *sec2)
921+
static void __kpatch_correlate_section(struct section *sec_orig,
922+
struct section *sec_patched)
922923
{
923-
CORRELATE_ELEMENT(sec1, sec2, "section");
924+
CORRELATE_ELEMENT(sec_orig, sec_patched, "section");
924925
}
925926

926-
static void kpatch_correlate_symbol(struct symbol *sym1, struct symbol *sym2)
927+
static void kpatch_correlate_symbol(struct symbol *sym_orig,
928+
struct symbol *sym_patched)
927929
{
928-
CORRELATE_ELEMENT(sym1, sym2, "symbol");
929-
if (sym1->lookup_table_file_sym && !sym2->lookup_table_file_sym)
930-
sym2->lookup_table_file_sym = sym1->lookup_table_file_sym;
931-
else if (!sym1->lookup_table_file_sym && sym2->lookup_table_file_sym)
932-
sym1->lookup_table_file_sym = sym2->lookup_table_file_sym;
930+
CORRELATE_ELEMENT(sym_orig, sym_patched, "symbol");
931+
if (sym_orig->lookup_table_file_sym && !sym_patched->lookup_table_file_sym)
932+
sym_patched->lookup_table_file_sym = sym_orig->lookup_table_file_sym;
933933
}
934934

935-
static void kpatch_correlate_static_local(struct symbol *sym1, struct symbol *sym2)
935+
static void kpatch_correlate_static_local(struct symbol *sym_orig,
936+
struct symbol *sym_patched)
936937
{
937-
CORRELATE_ELEMENT(sym1, sym2, "static local");
938+
CORRELATE_ELEMENT(sym_orig, sym_patched, "static local");
938939
}
939940

940-
static void kpatch_correlate_section(struct section *sec1, struct section *sec2)
941+
static void kpatch_correlate_section(struct section *sec_orig,
942+
struct section *sec_patched)
941943
{
942-
__kpatch_correlate_section(sec1, sec2);
944+
__kpatch_correlate_section(sec_orig, sec_patched);
943945

944-
if (is_rela_section(sec1)) {
945-
__kpatch_correlate_section(sec1->base, sec2->base);
946-
sec1 = sec1->base;
947-
sec2 = sec2->base;
948-
} else if (sec1->rela) {
949-
__kpatch_correlate_section(sec1->rela, sec2->rela);
946+
if (is_rela_section(sec_orig)) {
947+
__kpatch_correlate_section(sec_orig->base, sec_patched->base);
948+
sec_orig = sec_orig->base;
949+
sec_patched = sec_patched->base;
950+
} else if (sec_orig->rela) {
951+
__kpatch_correlate_section(sec_orig->rela, sec_patched->rela);
950952
}
951953

952-
if (sec1->secsym)
953-
kpatch_correlate_symbol(sec1->secsym, sec2->secsym);
954-
if (sec1->sym)
955-
kpatch_correlate_symbol(sec1->sym, sec2->sym);
954+
if (sec_orig->secsym)
955+
kpatch_correlate_symbol(sec_orig->secsym, sec_patched->secsym);
956+
if (sec_orig->sym)
957+
kpatch_correlate_symbol(sec_orig->sym, sec_patched->sym);
956958
}
957959

958-
static void kpatch_correlate_sections(struct list_head *seclist1, struct list_head *seclist2)
960+
static void kpatch_correlate_sections(struct list_head *seclist_orig,
961+
struct list_head *seclist_patched)
959962
{
960-
struct section *sec1, *sec2;
963+
struct section *sec_orig, *sec_patched;
961964

962-
list_for_each_entry(sec1, seclist1, list) {
963-
if (sec1->twin)
965+
list_for_each_entry(sec_orig, seclist_orig, list) {
966+
if (sec_orig->twin)
964967
continue;
965-
list_for_each_entry(sec2, seclist2, list) {
966-
if (kpatch_mangled_strcmp(sec1->name, sec2->name) ||
967-
sec2->twin)
968+
list_for_each_entry(sec_patched, seclist_patched, list) {
969+
if (kpatch_mangled_strcmp(sec_orig->name, sec_patched->name) ||
970+
sec_patched->twin)
968971
continue;
969972

970-
if (is_special_static(is_rela_section(sec1) ?
971-
sec1->base->secsym :
972-
sec1->secsym))
973+
if (is_special_static(is_rela_section(sec_orig) ?
974+
sec_orig->base->secsym :
975+
sec_orig->secsym))
973976
continue;
974977

975978
/*
976979
* Group sections must match exactly to be correlated.
977980
* Changed group sections are currently not supported.
978981
*/
979-
if (sec1->sh.sh_type == SHT_GROUP) {
980-
if (sec1->data->d_size != sec2->data->d_size)
982+
if (sec_orig->sh.sh_type == SHT_GROUP) {
983+
if (sec_orig->data->d_size != sec_patched->data->d_size)
981984
continue;
982-
if (memcmp(sec1->data->d_buf, sec2->data->d_buf,
983-
sec1->data->d_size))
985+
if (memcmp(sec_orig->data->d_buf, sec_patched->data->d_buf,
986+
sec_orig->data->d_size))
984987
continue;
985988
}
986989

987-
kpatch_correlate_section(sec1, sec2);
990+
kpatch_correlate_section(sec_orig, sec_patched);
988991
break;
989992
}
990993
}
991994
}
992995

993-
static void kpatch_correlate_symbols(struct list_head *symlist1, struct list_head *symlist2)
996+
static void kpatch_correlate_symbols(struct list_head *symlist_orig,
997+
struct list_head *symlist_patched)
994998
{
995-
struct symbol *sym1, *sym2;
999+
struct symbol *sym_orig, *sym_patched;
9961000

997-
list_for_each_entry(sym1, symlist1, list) {
998-
if (sym1->twin)
1001+
list_for_each_entry(sym_orig, symlist_orig, list) {
1002+
if (sym_orig->twin)
9991003
continue;
1000-
list_for_each_entry(sym2, symlist2, list) {
1001-
if (kpatch_mangled_strcmp(sym1->name, sym2->name) ||
1002-
sym1->type != sym2->type || sym2->twin)
1004+
list_for_each_entry(sym_patched, symlist_patched, list) {
1005+
if (kpatch_mangled_strcmp(sym_orig->name, sym_patched->name) ||
1006+
sym_orig->type != sym_patched->type || sym_patched->twin)
10031007
continue;
10041008

1005-
if (is_special_static(sym1))
1009+
if (is_special_static(sym_orig))
10061010
continue;
10071011

10081012
/*
@@ -1019,42 +1023,42 @@ static void kpatch_correlate_symbols(struct list_head *symlist1, struct list_hea
10191023
* sure if this actually happens anywhere), any string
10201024
* changes will be detected elsewhere in rela_equal().
10211025
*/
1022-
if (sym1->type == STT_NOTYPE &&
1023-
!strncmp(sym1->name, ".LC", 3))
1026+
if (sym_orig->type == STT_NOTYPE &&
1027+
!strncmp(sym_orig->name, ".LC", 3))
10241028
continue;
10251029

10261030
/* group section symbols must have correlated sections */
1027-
if (sym1->sec &&
1028-
sym1->sec->sh.sh_type == SHT_GROUP &&
1029-
sym1->sec->twin != sym2->sec)
1031+
if (sym_orig->sec &&
1032+
sym_orig->sec->sh.sh_type == SHT_GROUP &&
1033+
sym_orig->sec->twin != sym_patched->sec)
10301034
continue;
10311035

1032-
kpatch_correlate_symbol(sym1, sym2);
1036+
kpatch_correlate_symbol(sym_orig, sym_patched);
10331037
break;
10341038
}
10351039
}
10361040
}
10371041

1038-
static void kpatch_compare_elf_headers(Elf *elf1, Elf *elf2)
1042+
static void kpatch_compare_elf_headers(Elf *elf_orig, Elf *elf_patched)
10391043
{
1040-
GElf_Ehdr eh1, eh2;
1044+
GElf_Ehdr ehdr_orig, ehdr_patched;
10411045

1042-
if (!gelf_getehdr(elf1, &eh1))
1046+
if (!gelf_getehdr(elf_orig, &ehdr_orig))
10431047
ERROR("gelf_getehdr");
10441048

1045-
if (!gelf_getehdr(elf2, &eh2))
1049+
if (!gelf_getehdr(elf_patched, &ehdr_patched))
10461050
ERROR("gelf_getehdr");
10471051

1048-
if (memcmp(eh1.e_ident, eh2.e_ident, EI_NIDENT) ||
1049-
eh1.e_type != eh2.e_type ||
1050-
eh1.e_machine != eh2.e_machine ||
1051-
eh1.e_version != eh2.e_version ||
1052-
eh1.e_entry != eh2.e_entry ||
1053-
eh1.e_phoff != eh2.e_phoff ||
1054-
eh1.e_flags != eh2.e_flags ||
1055-
eh1.e_ehsize != eh2.e_ehsize ||
1056-
eh1.e_phentsize != eh2.e_phentsize ||
1057-
eh1.e_shentsize != eh2.e_shentsize)
1052+
if (memcmp(ehdr_orig.e_ident, ehdr_patched.e_ident, EI_NIDENT) ||
1053+
ehdr_orig.e_type != ehdr_patched.e_type ||
1054+
ehdr_orig.e_machine != ehdr_patched.e_machine ||
1055+
ehdr_orig.e_version != ehdr_patched.e_version ||
1056+
ehdr_orig.e_entry != ehdr_patched.e_entry ||
1057+
ehdr_orig.e_phoff != ehdr_patched.e_phoff ||
1058+
ehdr_orig.e_flags != ehdr_patched.e_flags ||
1059+
ehdr_orig.e_ehsize != ehdr_patched.e_ehsize ||
1060+
ehdr_orig.e_phentsize != ehdr_patched.e_phentsize ||
1061+
ehdr_orig.e_shentsize != ehdr_patched.e_shentsize)
10581062
DIFF_FATAL("ELF headers differ");
10591063
}
10601064

@@ -1423,10 +1427,11 @@ static void kpatch_correlate_static_local_variables(struct kpatch_elf *orig,
14231427
}
14241428
}
14251429

1426-
static void kpatch_correlate_elfs(struct kpatch_elf *kelf1, struct kpatch_elf *kelf2)
1430+
static void kpatch_correlate_elfs(struct kpatch_elf *kelf_orig,
1431+
struct kpatch_elf *kelf_patched)
14271432
{
1428-
kpatch_correlate_sections(&kelf1->sections, &kelf2->sections);
1429-
kpatch_correlate_symbols(&kelf1->symbols, &kelf2->symbols);
1433+
kpatch_correlate_sections(&kelf_orig->sections, &kelf_patched->sections);
1434+
kpatch_correlate_symbols(&kelf_orig->symbols, &kelf_patched->symbols);
14301435
}
14311436

14321437
static void kpatch_compare_correlated_elements(struct kpatch_elf *kelf)

0 commit comments

Comments
 (0)