Skip to content

Commit bbed982

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: George Guo <[email protected]>
1 parent 1c85437 commit bbed982

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,
@@ -625,6 +641,18 @@ struct kpatch_elf *kpatch_elf_open(const char *name)
625641
if (find_section_by_name(&kelf->sections, "__patchable_function_entries"))
626642
kelf->has_pfe = true;
627643

644+
if (kelf->arch == LOONGARCH64) {
645+
struct symbol *sym, *tmp;
646+
647+
/* Delete local labels created by LoongArch GCC */
648+
list_for_each_entry_safe(sym, tmp, &kelf->symbols, list) {
649+
if (sym->sec && !is_rela_section(sym->sec) &&
650+
(sym->type == STT_NOTYPE) &&
651+
(sym->bind == STB_LOCAL))
652+
list_del(&sym->list);
653+
}
654+
}
655+
628656
return kelf;
629657
}
630658

0 commit comments

Comments
 (0)