diff --git a/0038-kpatch-build-for-clang-use-.strtab-if-no-.shstrtab.patch b/0038-kpatch-build-for-clang-use-.strtab-if-no-.shstrtab.patch new file mode 100644 index 0000000000000000000000000000000000000000..1b0e448e41e0b01bae2ff68b435fc6fee3c975cb --- /dev/null +++ b/0038-kpatch-build-for-clang-use-.strtab-if-no-.shstrtab.patch @@ -0,0 +1,99 @@ +From 5f6c5965f117cb9b2b21749da49b22b23305d114 Mon Sep 17 00:00:00 2001 +From: Pete Swain +Date: Tue, 27 Sep 2022 15:56:06 -0400 +Subject: [PATCH 1/3] kpatch-build: for clang, use .strtab if no .shstrtab + +While gcc puts strings in .strtab and .shstrtab sections, +llvm toolchain just uses .strtab. + +Adapt kpatch to handle both styles. + +Signed-off-by: Pete Swain +Signed-off-by: Joe Lawrence [small changes] +--- + kpatch-build/kpatch-elf.c | 33 +++++++++++++++++++++++++++++---- + 1 file changed, 29 insertions(+), 4 deletions(-) + +diff --git a/kpatch-build/kpatch-elf.c b/kpatch-build/kpatch-elf.c +index 58dbe1a..c7d12ec 100644 +--- a/kpatch-build/kpatch-elf.c ++++ b/kpatch-build/kpatch-elf.c +@@ -607,7 +607,7 @@ void kpatch_create_shstrtab(struct kpatch_elf *kelf) + + shstrtab = find_section_by_name(&kelf->sections, ".shstrtab"); + if (!shstrtab) +- ERROR("find_section_by_name"); ++ return; + + /* determine size of string table */ + size = 1; /* for initial NULL terminator */ +@@ -648,7 +648,7 @@ void kpatch_create_shstrtab(struct kpatch_elf *kelf) + + void kpatch_create_strtab(struct kpatch_elf *kelf) + { +- struct section *strtab; ++ struct section *strtab, *shstrtab; + struct symbol *sym; + size_t size = 0, offset = 0, len; + char *buf; +@@ -657,6 +657,8 @@ void kpatch_create_strtab(struct kpatch_elf *kelf) + if (!strtab) + ERROR("find_section_by_name"); + ++ shstrtab = find_section_by_name(&kelf->sections, ".shstrtab"); ++ + /* determine size of string table */ + list_for_each_entry(sym, &kelf->symbols, list) { + if (sym->type == STT_SECTION) +@@ -664,6 +666,15 @@ void kpatch_create_strtab(struct kpatch_elf *kelf) + size += strlen(sym->name) + 1; /* include NULL terminator */ + } + ++ /* and when covering for missing .shstrtab ... */ ++ if (!shstrtab) { ++ /* factor out into common (sh)strtab feeder */ ++ struct section *sec; ++ ++ list_for_each_entry(sec, &kelf->sections, list) ++ size += strlen(sec->name) + 1; /* include NULL terminator */ ++ } ++ + /* allocate data buffer */ + buf = malloc(size); + if (!buf) +@@ -682,8 +693,20 @@ void kpatch_create_strtab(struct kpatch_elf *kelf) + offset += len; + } + ++ if (!shstrtab) { ++ struct section *sec; ++ ++ /* populate string table and link with section header */ ++ list_for_each_entry(sec, &kelf->sections, list) { ++ len = strlen(sec->name) + 1; ++ sec->sh.sh_name = (unsigned int)offset; ++ memcpy(buf + offset, sec->name, len); ++ offset += len; ++ } ++ } ++ + if (offset != size) +- ERROR("shstrtab size mismatch"); ++ ERROR("strtab size mismatch"); + + strtab->data->d_buf = buf; + strtab->data->d_size = size; +@@ -928,7 +951,9 @@ void kpatch_write_output_elf(struct kpatch_elf *kelf, Elf *elf, char *outfile, + + shstrtab = find_section_by_name(&kelf->sections, ".shstrtab"); + if (!shstrtab) +- ERROR("missing .shstrtab section"); ++ shstrtab = find_section_by_name(&kelf->sections, ".strtab"); ++ if (!shstrtab) ++ ERROR("missing .shstrtab, .strtab sections"); + + ehout.e_shstrndx = (unsigned short)shstrtab->index; + +-- +2.27.0 + diff --git a/0039-create-diff-object-ignore-clang-s-.llvm_addrsig-sect.patch b/0039-create-diff-object-ignore-clang-s-.llvm_addrsig-sect.patch new file mode 100644 index 0000000000000000000000000000000000000000..2f92bf6c20d961b3dd7cf6b25f2c1939054bef68 --- /dev/null +++ b/0039-create-diff-object-ignore-clang-s-.llvm_addrsig-sect.patch @@ -0,0 +1,28 @@ +From 37040572440efb95db9a3193d3b51d7597e1badd Mon Sep 17 00:00:00 2001 +From: Pete Swain +Date: Tue, 27 Sep 2022 15:56:06 -0400 +Subject: [PATCH 2/3] create-diff-object: ignore clang's .llvm_addrsig sections + +Signed-off-by: Pete Swain +Signed-off-by: Joe Lawrence [subject line] +--- + kpatch-build/create-diff-object.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c +index 918d21c..fa7e07f 100644 +--- a/kpatch-build/create-diff-object.c ++++ b/kpatch-build/create-diff-object.c +@@ -2717,7 +2717,8 @@ static void kpatch_mark_ignored_sections(struct kpatch_elf *kelf) + /* Ignore any discarded sections */ + list_for_each_entry(sec, &kelf->sections, list) { + if (!strncmp(sec->name, ".discard", 8) || +- !strncmp(sec->name, ".rela.discard", 13)) ++ !strncmp(sec->name, ".rela.discard", 13) || ++ !strncmp(sec->name, ".llvm_addrsig", 13)) + sec->ignore = 1; + } + +-- +2.27.0 + diff --git a/0040-create-diff-object-ignore-.llvm.-sections.patch b/0040-create-diff-object-ignore-.llvm.-sections.patch new file mode 100644 index 0000000000000000000000000000000000000000..633f19b0d77a633d005a5c21b6d88fe43e961b8f --- /dev/null +++ b/0040-create-diff-object-ignore-.llvm.-sections.patch @@ -0,0 +1,32 @@ +From 85781b7ea79fb4122efbb51f0bf573ed5fab03e1 Mon Sep 17 00:00:00 2001 +From: Pete Swain +Date: Tue, 27 Sep 2022 15:56:06 -0400 +Subject: [PATCH 3/3] create-diff-object: ignore .llvm.* sections + +Clang FDO adds a new, ignorable ELF section, .llvm.call-graph-profile + +Generalize to ignore all .llvm.* + +Signed-off-by: Pete Swain +Signed-off-by: Joe Lawrence [subject line] +--- + kpatch-build/create-diff-object.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c +index fa7e07f..cdcc13b 100644 +--- a/kpatch-build/create-diff-object.c ++++ b/kpatch-build/create-diff-object.c +@@ -2718,7 +2718,8 @@ static void kpatch_mark_ignored_sections(struct kpatch_elf *kelf) + list_for_each_entry(sec, &kelf->sections, list) { + if (!strncmp(sec->name, ".discard", 8) || + !strncmp(sec->name, ".rela.discard", 13) || +- !strncmp(sec->name, ".llvm_addrsig", 13)) ++ !strncmp(sec->name, ".llvm_addrsig", 13) || ++ !strncmp(sec->name, ".llvm.", 6)) + sec->ignore = 1; + } + +-- +2.27.0 + diff --git a/kpatch.spec b/kpatch.spec index ca4756fd0da2d4db27388dfb8158c3ef819a2eba..fb8d09cff5b379e37e9c0f21dc3bc8797665d0e3 100644 --- a/kpatch.spec +++ b/kpatch.spec @@ -1,7 +1,7 @@ Name: kpatch Epoch: 1 Version: 0.9.7 -Release: 1 +Release: 2 Summary: A Linux dynamic kernel patching infrastructure License: GPLv2 @@ -50,6 +50,9 @@ Patch0034:0034-create-diff-object-allow-__jump_table-section-change.patch Patch0035:0035-livepatch-patch-hook-fix-kpatch-build-error-which-do.patch Patch0036:0036-lookup-skip-finding-local-symbols-for-object-with-no.patch Patch0037:0037-create-diff-object-ignore-entsize-change-of-.return_.patch +Patch0038:0038-kpatch-build-for-clang-use-.strtab-if-no-.shstrtab.patch +Patch0039:0039-create-diff-object-ignore-clang-s-.llvm_addrsig-sect.patch +Patch0040:0040-create-diff-object-ignore-.llvm.-sections.patch BuildRequires: gcc elfutils-libelf-devel kernel-devel git Requires: bc make gcc patch bison flex openssl-devel @@ -110,6 +113,12 @@ popd %{_mandir}/man1/*.1.gz %changelog +* Mon May 29 2023 Zhipeng Xie -1:0.9.7-2 +- Type:enhancement +- ID:NA +- SUG:NA +- DESC:backport upsteam patches + * Mon Jan 30 2023 Bin Hu -1:0.9.7-1 - Type:enhancement - ID:NA