Skip to content

Commit 6831020

Browse files
committed
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 3aee4e1 commit 6831020

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
@@ -336,6 +336,22 @@ static void kpatch_create_rela_list(struct kpatch_elf *kelf,
336336
rela->sym->name, rela->addend);
337337
}
338338

339+
if (kelf->arch == LOONGARCH64) {
340+
/*
341+
* LoongArch GCC creates local labels such as .LBB7266,
342+
* replace them with section symbols.
343+
*/
344+
if (rela->sym->sec && (rela->sym->type == STT_NOTYPE) &&
345+
(rela->sym->bind == STB_LOCAL)) {
346+
log_debug("local label: %s -> ", rela->sym->name);
347+
348+
rela->addend += rela->sym->sym.st_value;
349+
rela->sym = rela->sym->sec->secsym;
350+
log_debug("section symbol: %s\n", rela->sym->name);
351+
}
352+
}
353+
354+
339355
if (skip)
340356
continue;
341357
log_debug("offset %d, type %d, %s %s %ld", rela->offset,
@@ -634,6 +650,18 @@ struct kpatch_elf *kpatch_elf_open(const char *name)
634650
}
635651
}
636652

653+
if (kelf->arch == LOONGARCH64) {
654+
struct symbol *sym, *tmp;
655+
656+
/* Delete local labels created by LoongArch GCC */
657+
list_for_each_entry_safe(sym, tmp, &kelf->symbols, list) {
658+
if (sym->sec && !is_rela_section(sym->sec) &&
659+
(sym->type == STT_NOTYPE) &&
660+
(sym->bind == STB_LOCAL))
661+
list_del(&sym->list);
662+
}
663+
}
664+
637665
return kelf;
638666
}
639667

0 commit comments

Comments
 (0)