From ec941bb2bc294d6c45ae78722f97a2dac7e39ad0 Mon Sep 17 00:00:00 2001 From: Huang Yang Date: Wed, 24 Apr 2024 01:45:13 +0000 Subject: [PATCH] add loongarch64 support --- ...kpatch-0.9.9-add-loongarch64-support.patch | 118 ++++++++++++++++++ kpatch.spec | 9 +- 2 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 0001-kpatch-0.9.9-add-loongarch64-support.patch diff --git a/0001-kpatch-0.9.9-add-loongarch64-support.patch b/0001-kpatch-0.9.9-add-loongarch64-support.patch new file mode 100644 index 0000000..9afddaa --- /dev/null +++ b/0001-kpatch-0.9.9-add-loongarch64-support.patch @@ -0,0 +1,118 @@ +From d809ddf08df9a9fba209a1361dd03abd2789250b Mon Sep 17 00:00:00 2001 +From: rpm-build +Date: Tue, 23 Apr 2024 11:37:27 +0000 +Subject: [PATCH] kpatch 0.9.9 add loongarch64 support + +--- + kpatch-build/Makefile | 2 +- + kpatch-build/create-diff-object.c | 13 ++++++++++--- + kpatch-build/kpatch-elf.c | 2 ++ + kpatch-build/kpatch-elf.h | 1 + + 4 files changed, 14 insertions(+), 4 deletions(-) + +diff --git a/kpatch-build/Makefile b/kpatch-build/Makefile +index f24165b..a06759e 100644 +--- a/kpatch-build/Makefile ++++ b/kpatch-build/Makefile +@@ -22,7 +22,7 @@ PLUGIN_CFLAGS := $(filter-out -Wconversion, $(CFLAGS)) + PLUGIN_CFLAGS += -shared -I$(GCC_PLUGINS_DIR)/include \ + -Igcc-plugins -fPIC -fno-rtti -O2 -Wall + endif +-ifeq ($(filter $(ARCH),s390x x86_64 ppc64le aarch64 riscv64),) ++ifeq ($(filter $(ARCH),s390x x86_64 ppc64le aarch64 riscv64 loongarch64),) + $(error Unsupported architecture ${ARCH}, check https://github.com/dynup/kpatch/#supported-architectures) + endif + +diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c +index 0d1efcf..17438aa 100644 +--- a/kpatch-build/create-diff-object.c ++++ b/kpatch-build/create-diff-object.c +@@ -182,8 +182,11 @@ static bool is_gcc6_localentry_bundled_sym(struct kpatch_elf *kelf, + case S390: + return false; + case ARM64: ++ return false; + case RISCV64: + return false; ++ case LOONGARCH64: ++ return false; + default: + ERROR("unsupported arch"); + } +@@ -731,6 +734,8 @@ static bool insn_is_load_immediate(struct kpatch_elf *kelf, void *addr) + case RISCV64: + /* Not implemented and I think it has less meaning. */ + break; ++ case LOONGARCH64: ++ break; + + default: + ERROR("unsupported arch"); +@@ -2554,7 +2559,7 @@ static bool static_call_sites_group_filter(struct lookup_table *lookup, + static struct special_section special_sections[] = { + { + .name = "__bug_table", +- .arch = X86_64 | PPC64 | S390 | ARM64 | RISCV64, ++ .arch = X86_64 | PPC64 | S390 | ARM64 | RISCV64 | LOONGARCH64, + .group_size = bug_table_group_size, + }, + { +@@ -2564,12 +2569,12 @@ static struct special_section special_sections[] = { + }, + { + .name = "__ex_table", /* must come after .fixup */ +- .arch = X86_64 | PPC64 | S390 | ARM64 | RISCV64, ++ .arch = X86_64 | PPC64 | S390 | ARM64 | RISCV64 | LOONGARCH64, + .group_size = ex_table_group_size, + }, + { + .name = "__jump_table", +- .arch = X86_64 | PPC64 | S390 | ARM64 | RISCV64, ++ .arch = X86_64 | PPC64 | S390 | ARM64 | RISCV64 | LOONGARCH64, + .group_size = jump_table_group_size, + .group_filter = jump_table_group_filter, + }, +@@ -3947,6 +3952,7 @@ static void kpatch_create_mcount_sections(struct kpatch_elf *kelf) + switch(kelf->arch) { + case PPC64: + case RISCV64: ++ case LOONGARCH64: + case ARM64: { + bool found = false; + +@@ -4191,6 +4197,7 @@ static void kpatch_find_func_profiling_calls(struct kpatch_elf *kelf) + switch(kelf->arch) { + case PPC64: + case RISCV64: ++ case LOONGARCH64: + case ARM64: + list_for_each_entry(rela, &sym->sec->rela->relas, list) { + if (!strcmp(rela->sym->name, "_mcount")) { +diff --git a/kpatch-build/kpatch-elf.c b/kpatch-build/kpatch-elf.c +index d6398b3..bcf6f6a 100644 +--- a/kpatch-build/kpatch-elf.c ++++ b/kpatch-build/kpatch-elf.c +@@ -146,6 +146,8 @@ unsigned int absolute_rela_type(struct kpatch_elf *kelf) + return R_AARCH64_ABS64; + case RISCV64: + return R_RISCV_64; ++ case LOONGARCH64: ++ return R_LARCH_64; + default: + ERROR("unsupported arch"); + } +diff --git a/kpatch-build/kpatch-elf.h b/kpatch-build/kpatch-elf.h +index f2cf60a..79797c1 100644 +--- a/kpatch-build/kpatch-elf.h ++++ b/kpatch-build/kpatch-elf.h +@@ -117,6 +117,7 @@ enum architecture { + S390 = 0x1 << 2, + ARM64 = 0x1 << 3, + RISCV64= 0x1 << 4, ++ LOONGARCH64= 0x1 << 5 + }; + + struct kpatch_elf { +-- +2.43.0 + diff --git a/kpatch.spec b/kpatch.spec index 7604ee0..d1101f3 100644 --- a/kpatch.spec +++ b/kpatch.spec @@ -1,7 +1,7 @@ Name: kpatch Epoch: 1 Version: 0.9.9 -Release: 3 +Release: 4 Summary: A Linux dynamic kernel patching infrastructure License: GPLv2 @@ -52,6 +52,7 @@ Patch0036:0036-create-diff-object-ignore-entsize-change-of-.return_.patch Patch0037:0037-add-initial-riscv64-support.patch Patch0038:0038-Fix-undefined-behavior-problem-when-using-list_forea.patch Patch0039:0039-build-support-for-building-with-clang.patch +Patch0040:0001-kpatch-0.9.9-add-loongarch64-support.patch BuildRequires: gcc elfutils-libelf-devel kernel-devel git %ifarch ppc64le @@ -115,6 +116,12 @@ popd %{_mandir}/man1/*.1.gz %changelog +* Wed Apr 24 2024 Huang Yang - 1:0.9.9-4 +- Type:enhancement +- ID:NA +- SUG:NA +- DESC:add initial loongarch64 support + * Wed Mar 13 2024 luofng - 1:0.9.9-3 - Type: enhencement - CVE:NA -- Gitee