Skip to content

Commit a33aec9

Browse files
georgejguogeorge
authored andcommitted
kpatch/LoongArch: change local labels with sections symbols
Here fix error like: "tcp.o: symbol changed sections: .LBB7266. create-diff-object: unreconcilable difference". Due to LoongArch GCC generating local labels such as .LBB7266, it is difficult to compare the modified sections in the corresponding object files of the two files before and after the patch, so change them with sections symbols in rela section, and delete them in other sections. Co-developed-by: zhanghongchen <[email protected]> Signed-off-by: zhanghongchen <[email protected]> Signed-off-by: George Guo <[email protected]>
1 parent daf9377 commit a33aec9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

kpatch-build/kpatch-elf.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,22 @@ static void kpatch_create_rela_list(struct kpatch_elf *kelf,
353353
rela->sym->name, rela->addend);
354354
}
355355

356+
if (kelf->arch == LOONGARCH64) {
357+
/*
358+
* LoongArch GCC creates local labels such as .LBB7266,
359+
* replace them with section symbols.
360+
*/
361+
if (rela->sym->sec && (rela->sym->type == STT_NOTYPE) &&
362+
(rela->sym->bind == STB_LOCAL)) {
363+
log_debug("local label: %s -> ", rela->sym->name);
364+
365+
rela->addend += rela->sym->sym.st_value;
366+
rela->sym = rela->sym->sec->secsym;
367+
log_debug("section symbol: %s\n", rela->sym->name);
368+
}
369+
}
370+
371+
356372
if (skip)
357373
continue;
358374
log_debug("offset %d, type %d, %s %s %ld", rela->offset,
@@ -654,6 +670,18 @@ struct kpatch_elf *kpatch_elf_open(const char *name)
654670
}
655671
}
656672

673+
if (kelf->arch == LOONGARCH64) {
674+
struct symbol *sym, *tmp;
675+
676+
/* Delete local labels created by LoongArch GCC */
677+
list_for_each_entry_safe(sym, tmp, &kelf->symbols, list) {
678+
if (sym->sec && !is_rela_section(sym->sec) &&
679+
(sym->type == STT_NOTYPE) &&
680+
(sym->bind == STB_LOCAL))
681+
list_del(&sym->list);
682+
}
683+
}
684+
657685
return kelf;
658686
}
659687

0 commit comments

Comments
 (0)