Skip to content

Commit

Permalink
kpatch/LoongArch: change local labels with sections symbols
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
georgejguo committed Dec 11, 2024
1 parent f27619f commit ace5550
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions kpatch-build/kpatch-elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,22 @@ static void kpatch_create_rela_list(struct kpatch_elf *kelf,
rela->sym->name, rela->addend);
}

if (kelf->arch == LOONGARCH64) {
/*
* LoongArch GCC creates local labels such as .LBB7266,
* replace them with section symbols.
*/
if (rela->sym->sec && (rela->sym->type == STT_NOTYPE) &&
(rela->sym->bind == STB_LOCAL)) {
log_debug("local label: %s -> ", rela->sym->name);

rela->addend += rela->sym->sym.st_value;
rela->sym = rela->sym->sec->secsym;
log_debug("section symbol: %s\n", rela->sym->name);
}
}


if (skip)
continue;
log_debug("offset %d, type %d, %s %s %ld", rela->offset,
Expand Down Expand Up @@ -625,6 +641,18 @@ struct kpatch_elf *kpatch_elf_open(const char *name)
if (find_section_by_name(&kelf->sections, "__patchable_function_entries"))
kelf->has_pfe = true;

if (kelf->arch == LOONGARCH64) {
struct symbol *sym, *tmp;

/* Delete local labels created by LoongArch GCC */
list_for_each_entry_safe(sym, tmp, &kelf->symbols, list) {
if (sym->sec && !is_rela_section(sym->sec) &&
(sym->type == STT_NOTYPE) &&
(sym->bind == STB_LOCAL))
list_del(&sym->list);
}
}

return kelf;
}

Expand Down

0 comments on commit ace5550

Please sign in to comment.