Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions kpatch-build/create-diff-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,10 @@ static void kpatch_replace_sections_syms(struct kpatch_elf *kelf)

target_off = rela_target_offset(kelf, relasec, rela);

if (target_off >= (long)rela->sym->sec->sh.sh_size)
continue;

found = false;
/*
* Attempt to replace references to unbundled sections
* with their symbols.
Expand All @@ -1558,9 +1562,9 @@ static void kpatch_replace_sections_syms(struct kpatch_elf *kelf)
start = sym->sym.st_value;
end = sym->sym.st_value + sym->sym.st_size;

if (is_text_section(relasec->base) &&
if (rela->type == R_X86_64_32S &&
is_text_section(relasec->base) &&
!is_text_section(sym->sec) &&
rela->type == R_X86_64_32S &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this a separate commit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

rela->addend == (long)sym->sec->sh.sh_size &&
end == (long)sym->sec->sh.sh_size) {

Expand Down Expand Up @@ -2705,8 +2709,9 @@ static void kpatch_include_debug_sections(struct kpatch_elf *kelf)
if (!is_rela_section(sec) || !is_debug_section(sec))
continue;
list_for_each_entry_safe(rela, saferela, &sec->relas, list)
if (!rela->sym->sec->include)
if (!rela->sym->include || !rela->sym->sec->include) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, why haven't we seen this problem on x86?

Copy link
Author

@ZhangHongchen1 ZhangHongchen1 Nov 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I checked the compiled c file fs/aio.c of x86_64.It reference to __dyndbg using the __dyndbg + offset,it did not use the symbols in the __dyndbg section ,so it has no problem.
But LoongArch generate relas using the symbols in __dyndbg(or __verbose in old version kernel) and triggers the problem.
I think we should avoid that condition even if there is no problem now for x86_64.

list_del(&rela->list);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions kpatch-build/kpatch-elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,7 @@ void kpatch_write_output_elf(struct kpatch_elf *kelf, Elf *elf, char *outfile,
memset(&ehout, 0, sizeof(ehout));
ehout.e_ident[EI_DATA] = eh.e_ident[EI_DATA];
ehout.e_machine = eh.e_machine;
ehout.e_flags = eh.e_flags;
ehout.e_type = eh.e_type;
ehout.e_version = EV_CURRENT;

Expand Down