code optimization
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
This commit is contained in:
parent
29e99d36a7
commit
a8565c3adf
@ -1,7 +1,7 @@
|
|||||||
From 1281e03a115ee04e8ddea9f88d0e4e16b2e5ce57 Mon Sep 17 00:00:00 2001
|
From 0de9a5da0cc278973caabfb9929dc58514c73639 Mon Sep 17 00:00:00 2001
|
||||||
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
Date: Thu, 20 Dec 2018 04:55:38 +0000
|
Date: Thu, 20 Dec 2018 04:55:38 +0000
|
||||||
Subject: [PATCH 01/21] support compile kpatch on aarch64
|
Subject: [PATCH 01/23] support compile kpatch on aarch64
|
||||||
|
|
||||||
delete __x86_64__ to support compile kpatch on aarch64.
|
delete __x86_64__ to support compile kpatch on aarch64.
|
||||||
|
|
||||||
@ -109,3 +109,4 @@ index aedd07d..2707cdb 100644
|
|||||||
.name = "__ftr_fixup",
|
.name = "__ftr_fixup",
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
From 92bb331ce71cfc33d933ebeabdbe9b5721c0ec75 Mon Sep 17 00:00:00 2001
|
From d3665b019100715e41b75493d31d51d602ca056a Mon Sep 17 00:00:00 2001
|
||||||
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
Date: Wed, 26 Feb 2020 07:09:50 -0500
|
Date: Wed, 26 Feb 2020 07:09:50 -0500
|
||||||
Subject: [PATCH 02/21] kpatch-build: support build patch for aarch64
|
Subject: [PATCH 02/23] kpatch-build: support build patch for aarch64
|
||||||
|
|
||||||
use R_AARCH64_ABS64 for aarch64
|
use R_AARCH64_ABS64 for aarch64
|
||||||
|
|
||||||
@ -16,17 +16,17 @@ support cross compile for aarch64
|
|||||||
|
|
||||||
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
---
|
---
|
||||||
kpatch-build/create-diff-object.c | 191 +++++++++++++++++++++++++---
|
kpatch-build/create-diff-object.c | 276 ++++++++++++++++++++++------
|
||||||
kpatch-build/create-kpatch-module.c | 24 +++-
|
kpatch-build/create-kpatch-module.c | 25 ++-
|
||||||
kpatch-build/kpatch-build | 116 ++++++++++++++++-
|
kpatch-build/kpatch-build | 116 +++++++++++-
|
||||||
kpatch-build/kpatch-gcc | 4 +-
|
kpatch-build/kpatch-gcc | 4 +-
|
||||||
4 files changed, 306 insertions(+), 29 deletions(-)
|
4 files changed, 352 insertions(+), 69 deletions(-)
|
||||||
|
|
||||||
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
||||||
index 2707cdb..7a27b58 100644
|
index 2707cdb..b161fee 100644
|
||||||
--- a/kpatch-build/create-diff-object.c
|
--- a/kpatch-build/create-diff-object.c
|
||||||
+++ b/kpatch-build/create-diff-object.c
|
+++ b/kpatch-build/create-diff-object.c
|
||||||
@@ -76,6 +76,31 @@ enum subsection {
|
@@ -76,6 +76,32 @@ enum subsection {
|
||||||
|
|
||||||
enum loglevel loglevel = NORMAL;
|
enum loglevel loglevel = NORMAL;
|
||||||
|
|
||||||
@ -50,6 +50,7 @@ index 2707cdb..7a27b58 100644
|
|||||||
+static unsigned int arch_of_elf(Elf *elf)
|
+static unsigned int arch_of_elf(Elf *elf)
|
||||||
+{
|
+{
|
||||||
+ GElf_Ehdr eh;
|
+ GElf_Ehdr eh;
|
||||||
|
+
|
||||||
+ if (!gelf_getehdr(elf, &eh))
|
+ if (!gelf_getehdr(elf, &eh))
|
||||||
+ ERROR("gelf_getehdr");
|
+ ERROR("gelf_getehdr");
|
||||||
+ return eh.e_machine;
|
+ return eh.e_machine;
|
||||||
@ -58,7 +59,7 @@ index 2707cdb..7a27b58 100644
|
|||||||
/*******************
|
/*******************
|
||||||
* Data structures
|
* Data structures
|
||||||
* ****************/
|
* ****************/
|
||||||
@@ -652,6 +677,67 @@ static int kpatch_line_macro_change_only(struct section *sec)
|
@@ -652,6 +678,67 @@ static int kpatch_line_macro_change_only(struct section *sec)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -126,7 +127,7 @@ index 2707cdb..7a27b58 100644
|
|||||||
|
|
||||||
static void kpatch_compare_sections(struct list_head *seclist)
|
static void kpatch_compare_sections(struct list_head *seclist)
|
||||||
{
|
{
|
||||||
@@ -667,7 +753,16 @@ static void kpatch_compare_sections(struct list_head *seclist)
|
@@ -667,7 +754,16 @@ static void kpatch_compare_sections(struct list_head *seclist)
|
||||||
|
|
||||||
/* exclude WARN-only, might_sleep changes */
|
/* exclude WARN-only, might_sleep changes */
|
||||||
list_for_each_entry(sec, seclist, list) {
|
list_for_each_entry(sec, seclist, list) {
|
||||||
@ -144,7 +145,7 @@ index 2707cdb..7a27b58 100644
|
|||||||
log_debug("reverting macro / line number section %s status to SAME\n",
|
log_debug("reverting macro / line number section %s status to SAME\n",
|
||||||
sec->name);
|
sec->name);
|
||||||
sec->status = SAME;
|
sec->status = SAME;
|
||||||
@@ -727,6 +822,8 @@ static void kpatch_compare_correlated_symbol(struct symbol *sym)
|
@@ -727,6 +823,8 @@ static void kpatch_compare_correlated_symbol(struct symbol *sym)
|
||||||
if ((sym2->sec->twin && sym2->sec->twin->ignore) ||
|
if ((sym2->sec->twin && sym2->sec->twin->ignore) ||
|
||||||
kpatch_subsection_changed(sym1->sec, sym2->sec))
|
kpatch_subsection_changed(sym1->sec, sym2->sec))
|
||||||
sym->status = CHANGED;
|
sym->status = CHANGED;
|
||||||
@ -153,27 +154,45 @@ index 2707cdb..7a27b58 100644
|
|||||||
else
|
else
|
||||||
DIFF_FATAL("symbol changed sections: %s", sym1->name);
|
DIFF_FATAL("symbol changed sections: %s", sym1->name);
|
||||||
}
|
}
|
||||||
@@ -1302,9 +1399,8 @@ static void kpatch_replace_sections_syms(struct kpatch_elf *kelf)
|
@@ -1302,22 +1400,22 @@ static void kpatch_replace_sections_syms(struct kpatch_elf *kelf)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
-#ifdef __powerpc64__
|
-#ifdef __powerpc64__
|
||||||
add_off = 0;
|
add_off = 0;
|
||||||
-#else
|
-#else
|
||||||
+ if (arch == EM_X86_64) {
|
- if (rela->type == R_X86_64_PC32 ||
|
||||||
if (rela->type == R_X86_64_PC32 ||
|
- rela->type == R_X86_64_PLT32) {
|
||||||
rela->type == R_X86_64_PLT32) {
|
- struct insn insn;
|
||||||
struct insn insn;
|
- rela_insn(sec, rela, &insn);
|
||||||
@@ -1317,7 +1413,7 @@ static void kpatch_replace_sections_syms(struct kpatch_elf *kelf)
|
- add_off = (unsigned int)((long)insn.next_byte -
|
||||||
add_off = 0;
|
- (long)sec->base->data->d_buf -
|
||||||
else
|
- rela->offset);
|
||||||
continue;
|
- } else if (rela->type == R_X86_64_64 ||
|
||||||
|
- rela->type == R_X86_64_32S)
|
||||||
|
- add_off = 0;
|
||||||
|
- else
|
||||||
|
- continue;
|
||||||
-#endif
|
-#endif
|
||||||
|
+ if (arch == EM_X86_64) {
|
||||||
|
+ if (rela->type == R_X86_64_PC32 ||
|
||||||
|
+ rela->type == R_X86_64_PLT32) {
|
||||||
|
+ struct insn insn;
|
||||||
|
+
|
||||||
|
+ rela_insn(sec, rela, &insn);
|
||||||
|
+ add_off = (unsigned int)((long)insn.next_byte -
|
||||||
|
+ (long)sec->base->data->d_buf -
|
||||||
|
+ rela->offset);
|
||||||
|
+ } else if (rela->type == R_X86_64_64 ||
|
||||||
|
+ rela->type == R_X86_64_32S)
|
||||||
|
+ add_off = 0;
|
||||||
|
+ else
|
||||||
|
+ continue;
|
||||||
+ }
|
+ }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Attempt to replace references to unbundled sections
|
* Attempt to replace references to unbundled sections
|
||||||
@@ -2415,7 +2511,7 @@ static void kpatch_create_kpatch_arch_section(struct kpatch_elf *kelf, char *obj
|
@@ -2415,7 +2513,7 @@ static void kpatch_create_kpatch_arch_section(struct kpatch_elf *kelf, char *obj
|
||||||
/* entries[index].sec */
|
/* entries[index].sec */
|
||||||
ALLOC_LINK(rela, &karch_sec->rela->relas);
|
ALLOC_LINK(rela, &karch_sec->rela->relas);
|
||||||
rela->sym = sec->secsym;
|
rela->sym = sec->secsym;
|
||||||
@ -182,7 +201,7 @@ index 2707cdb..7a27b58 100644
|
|||||||
rela->addend = 0;
|
rela->addend = 0;
|
||||||
rela->offset = (unsigned int)(index * sizeof(struct kpatch_arch) + \
|
rela->offset = (unsigned int)(index * sizeof(struct kpatch_arch) + \
|
||||||
offsetof(struct kpatch_arch, sec));
|
offsetof(struct kpatch_arch, sec));
|
||||||
@@ -2423,7 +2519,7 @@ static void kpatch_create_kpatch_arch_section(struct kpatch_elf *kelf, char *obj
|
@@ -2423,7 +2521,7 @@ static void kpatch_create_kpatch_arch_section(struct kpatch_elf *kelf, char *obj
|
||||||
/* entries[index].objname */
|
/* entries[index].objname */
|
||||||
ALLOC_LINK(rela, &karch_sec->rela->relas);
|
ALLOC_LINK(rela, &karch_sec->rela->relas);
|
||||||
rela->sym = strsym;
|
rela->sym = strsym;
|
||||||
@ -191,7 +210,7 @@ index 2707cdb..7a27b58 100644
|
|||||||
rela->addend = offset_of_string(&kelf->strings, objname);
|
rela->addend = offset_of_string(&kelf->strings, objname);
|
||||||
rela->offset = (unsigned int)(index * sizeof(struct kpatch_arch) + \
|
rela->offset = (unsigned int)(index * sizeof(struct kpatch_arch) + \
|
||||||
offsetof(struct kpatch_arch, objname));
|
offsetof(struct kpatch_arch, objname));
|
||||||
@@ -2622,7 +2718,7 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf,
|
@@ -2622,7 +2720,7 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf,
|
||||||
*/
|
*/
|
||||||
ALLOC_LINK(rela, &relasec->relas);
|
ALLOC_LINK(rela, &relasec->relas);
|
||||||
rela->sym = sym;
|
rela->sym = sym;
|
||||||
@ -200,7 +219,7 @@ index 2707cdb..7a27b58 100644
|
|||||||
rela->addend = 0;
|
rela->addend = 0;
|
||||||
rela->offset = (unsigned int)(index * sizeof(*funcs));
|
rela->offset = (unsigned int)(index * sizeof(*funcs));
|
||||||
|
|
||||||
@@ -2632,7 +2728,7 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf,
|
@@ -2632,7 +2730,7 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf,
|
||||||
*/
|
*/
|
||||||
ALLOC_LINK(rela, &relasec->relas);
|
ALLOC_LINK(rela, &relasec->relas);
|
||||||
rela->sym = strsym;
|
rela->sym = strsym;
|
||||||
@ -209,7 +228,7 @@ index 2707cdb..7a27b58 100644
|
|||||||
rela->addend = offset_of_string(&kelf->strings, sym->name);
|
rela->addend = offset_of_string(&kelf->strings, sym->name);
|
||||||
rela->offset = (unsigned int)(index * sizeof(*funcs) +
|
rela->offset = (unsigned int)(index * sizeof(*funcs) +
|
||||||
offsetof(struct kpatch_patch_func, name));
|
offsetof(struct kpatch_patch_func, name));
|
||||||
@@ -2643,7 +2739,7 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf,
|
@@ -2643,7 +2741,7 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf,
|
||||||
*/
|
*/
|
||||||
ALLOC_LINK(rela, &relasec->relas);
|
ALLOC_LINK(rela, &relasec->relas);
|
||||||
rela->sym = strsym;
|
rela->sym = strsym;
|
||||||
@ -218,7 +237,7 @@ index 2707cdb..7a27b58 100644
|
|||||||
rela->addend = objname_offset;
|
rela->addend = objname_offset;
|
||||||
rela->offset = (unsigned int)(index * sizeof(*funcs) +
|
rela->offset = (unsigned int)(index * sizeof(*funcs) +
|
||||||
offsetof(struct kpatch_patch_func,objname));
|
offsetof(struct kpatch_patch_func,objname));
|
||||||
@@ -2701,7 +2797,10 @@ static int function_ptr_rela(const struct rela *rela)
|
@@ -2701,7 +2799,10 @@ static int function_ptr_rela(const struct rela *rela)
|
||||||
rela_toc->addend == (int)rela_toc->sym->sym.st_value &&
|
rela_toc->addend == (int)rela_toc->sym->sym.st_value &&
|
||||||
(rela->type == R_X86_64_32S ||
|
(rela->type == R_X86_64_32S ||
|
||||||
rela->type == R_PPC64_TOC16_HA ||
|
rela->type == R_PPC64_TOC16_HA ||
|
||||||
@ -230,7 +249,7 @@ index 2707cdb..7a27b58 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int may_need_dynrela(const struct rela *rela)
|
static int may_need_dynrela(const struct rela *rela)
|
||||||
@@ -2955,7 +3054,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
@@ -2955,7 +3056,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
||||||
/* add rela to fill in ksyms[index].name field */
|
/* add rela to fill in ksyms[index].name field */
|
||||||
ALLOC_LINK(rela2, &ksym_sec->rela->relas);
|
ALLOC_LINK(rela2, &ksym_sec->rela->relas);
|
||||||
rela2->sym = strsym;
|
rela2->sym = strsym;
|
||||||
@ -239,7 +258,7 @@ index 2707cdb..7a27b58 100644
|
|||||||
rela2->addend = offset_of_string(&kelf->strings, rela->sym->name);
|
rela2->addend = offset_of_string(&kelf->strings, rela->sym->name);
|
||||||
rela2->offset = (unsigned int)(index * sizeof(*ksyms) + \
|
rela2->offset = (unsigned int)(index * sizeof(*ksyms) + \
|
||||||
offsetof(struct kpatch_symbol, name));
|
offsetof(struct kpatch_symbol, name));
|
||||||
@@ -2963,7 +3062,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
@@ -2963,7 +3064,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
||||||
/* add rela to fill in ksyms[index].objname field */
|
/* add rela to fill in ksyms[index].objname field */
|
||||||
ALLOC_LINK(rela2, &ksym_sec->rela->relas);
|
ALLOC_LINK(rela2, &ksym_sec->rela->relas);
|
||||||
rela2->sym = strsym;
|
rela2->sym = strsym;
|
||||||
@ -248,7 +267,7 @@ index 2707cdb..7a27b58 100644
|
|||||||
rela2->addend = offset_of_string(&kelf->strings, sym_objname);
|
rela2->addend = offset_of_string(&kelf->strings, sym_objname);
|
||||||
rela2->offset = (unsigned int)(index * sizeof(*ksyms) + \
|
rela2->offset = (unsigned int)(index * sizeof(*ksyms) + \
|
||||||
offsetof(struct kpatch_symbol, objname));
|
offsetof(struct kpatch_symbol, objname));
|
||||||
@@ -2984,7 +3083,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
@@ -2984,7 +3085,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
||||||
ERROR("can't create dynrela for section %s (symbol %s): no bundled or section symbol",
|
ERROR("can't create dynrela for section %s (symbol %s): no bundled or section symbol",
|
||||||
sec->name, rela->sym->name);
|
sec->name, rela->sym->name);
|
||||||
|
|
||||||
@ -257,7 +276,7 @@ index 2707cdb..7a27b58 100644
|
|||||||
rela2->addend = rela->offset;
|
rela2->addend = rela->offset;
|
||||||
rela2->offset = (unsigned int)(index * sizeof(*krelas) + \
|
rela2->offset = (unsigned int)(index * sizeof(*krelas) + \
|
||||||
offsetof(struct kpatch_relocation, dest));
|
offsetof(struct kpatch_relocation, dest));
|
||||||
@@ -2992,7 +3091,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
@@ -2992,7 +3093,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
||||||
/* add rela to fill in krelas[index].objname field */
|
/* add rela to fill in krelas[index].objname field */
|
||||||
ALLOC_LINK(rela2, &krela_sec->rela->relas);
|
ALLOC_LINK(rela2, &krela_sec->rela->relas);
|
||||||
rela2->sym = strsym;
|
rela2->sym = strsym;
|
||||||
@ -266,7 +285,7 @@ index 2707cdb..7a27b58 100644
|
|||||||
rela2->addend = offset_of_string(&kelf->strings, objname);
|
rela2->addend = offset_of_string(&kelf->strings, objname);
|
||||||
rela2->offset = (unsigned int)(index * sizeof(*krelas) + \
|
rela2->offset = (unsigned int)(index * sizeof(*krelas) + \
|
||||||
offsetof(struct kpatch_relocation, objname));
|
offsetof(struct kpatch_relocation, objname));
|
||||||
@@ -3000,7 +3099,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
@@ -3000,7 +3101,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
||||||
/* add rela to fill in krelas[index].ksym field */
|
/* add rela to fill in krelas[index].ksym field */
|
||||||
ALLOC_LINK(rela2, &krela_sec->rela->relas);
|
ALLOC_LINK(rela2, &krela_sec->rela->relas);
|
||||||
rela2->sym = ksym_sec_sym;
|
rela2->sym = ksym_sec_sym;
|
||||||
@ -275,7 +294,7 @@ index 2707cdb..7a27b58 100644
|
|||||||
rela2->addend = (unsigned int)(index * sizeof(*ksyms));
|
rela2->addend = (unsigned int)(index * sizeof(*ksyms));
|
||||||
rela2->offset = (unsigned int)(index * sizeof(*krelas) + \
|
rela2->offset = (unsigned int)(index * sizeof(*krelas) + \
|
||||||
offsetof(struct kpatch_relocation, ksym));
|
offsetof(struct kpatch_relocation, ksym));
|
||||||
@@ -3063,7 +3162,7 @@ static void kpatch_create_callbacks_objname_rela(struct kpatch_elf *kelf, char *
|
@@ -3063,7 +3164,7 @@ static void kpatch_create_callbacks_objname_rela(struct kpatch_elf *kelf, char *
|
||||||
if (!strcmp(callbackp->name, sec->name)) {
|
if (!strcmp(callbackp->name, sec->name)) {
|
||||||
ALLOC_LINK(rela, &sec->relas);
|
ALLOC_LINK(rela, &sec->relas);
|
||||||
rela->sym = strsym;
|
rela->sym = strsym;
|
||||||
@ -284,24 +303,73 @@ index 2707cdb..7a27b58 100644
|
|||||||
rela->addend = objname_offset;
|
rela->addend = objname_offset;
|
||||||
rela->offset = callbackp->offset;
|
rela->offset = callbackp->offset;
|
||||||
break;
|
break;
|
||||||
@@ -3116,6 +3215,7 @@ static void kpatch_create_mcount_sections(struct kpatch_elf *kelf)
|
@@ -3116,40 +3215,79 @@ static void kpatch_create_mcount_sections(struct kpatch_elf *kelf)
|
||||||
/* add rela in .rela__mcount_loc to fill in function pointer */
|
/* add rela in .rela__mcount_loc to fill in function pointer */
|
||||||
ALLOC_LINK(rela, &relasec->relas);
|
ALLOC_LINK(rela, &relasec->relas);
|
||||||
rela->sym = sym;
|
rela->sym = sym;
|
||||||
|
- rela->type = R_X86_64_64;
|
||||||
|
- rela->addend = 0;
|
||||||
|
- rela->offset = (unsigned int)(index * sizeof(void*));
|
||||||
+ if (arch == EM_X86_64) {
|
+ if (arch == EM_X86_64) {
|
||||||
rela->type = R_X86_64_64;
|
+ rela->type = R_X86_64_64;
|
||||||
rela->addend = 0;
|
+ rela->addend = 0;
|
||||||
rela->offset = (unsigned int)(index * sizeof(void*));
|
+ rela->offset = (unsigned int)(index * sizeof(void *));
|
||||||
@@ -3151,6 +3251,40 @@ static void kpatch_create_mcount_sections(struct kpatch_elf *kelf)
|
|
||||||
|
|
||||||
rela->type = R_X86_64_PC32;
|
- /*
|
||||||
}
|
- * Modify the first instruction of the function to "callq
|
||||||
|
- * __fentry__" so that ftrace will be happy.
|
||||||
|
- */
|
||||||
|
- newdata = malloc(sym->sec->data->d_size);
|
||||||
|
- if (!newdata)
|
||||||
|
- ERROR("malloc");
|
||||||
|
+ /*
|
||||||
|
+ * Modify the first instruction of the function to "callq
|
||||||
|
+ * __fentry__" so that ftrace will be happy.
|
||||||
|
+ */
|
||||||
|
+ newdata = malloc(sym->sec->data->d_size);
|
||||||
|
+ if (!newdata)
|
||||||
|
+ ERROR("malloc");
|
||||||
|
|
||||||
|
- memcpy(newdata, sym->sec->data->d_buf, sym->sec->data->d_size);
|
||||||
|
- sym->sec->data->d_buf = newdata;
|
||||||
|
- insn = newdata;
|
||||||
|
+ memcpy(newdata, sym->sec->data->d_buf, sym->sec->data->d_size);
|
||||||
|
+ sym->sec->data->d_buf = newdata;
|
||||||
|
+ insn = newdata;
|
||||||
|
|
||||||
|
- rela = list_first_entry(&sym->sec->rela->relas, struct rela,
|
||||||
|
+ rela = list_first_entry(&sym->sec->rela->relas, struct rela,
|
||||||
|
list);
|
||||||
|
|
||||||
|
- /*
|
||||||
|
- * R_X86_64_NONE is only generated by older versions of kernel/gcc
|
||||||
|
- * which use the mcount script.
|
||||||
|
- */
|
||||||
|
- if (rela->type == R_X86_64_NONE) {
|
||||||
|
- if (insn[0] != 0xf)
|
||||||
|
+ /*
|
||||||
|
+ * R_X86_64_NONE is only generated by older versions of kernel/gcc
|
||||||
|
+ * which use the mcount script.
|
||||||
|
+ */
|
||||||
|
+ if (rela->type == R_X86_64_NONE) {
|
||||||
|
+ if (insn[0] != 0xf)
|
||||||
|
+ ERROR("%s: unexpected instruction at the start of the function",
|
||||||
|
+ sym->name);
|
||||||
|
+ insn[0] = 0xe8;
|
||||||
|
+ insn[1] = 0;
|
||||||
|
+ insn[2] = 0;
|
||||||
|
+ insn[3] = 0;
|
||||||
|
+ insn[4] = 0;
|
||||||
|
+
|
||||||
|
+ rela->type = R_X86_64_PC32;
|
||||||
|
+ }
|
||||||
+ } else if (arch == EM_AARCH64) {
|
+ } else if (arch == EM_AARCH64) {
|
||||||
+ unsigned int *insnp;
|
+ unsigned int *insnp;
|
||||||
|
+
|
||||||
+ rela->type = R_AARCH64_ABS64;
|
+ rela->type = R_AARCH64_ABS64;
|
||||||
+ /* bl <__fentry__> is the second insn */
|
+ /* bl <__fentry__> is the second insn */
|
||||||
+ rela->addend = 4;
|
+ rela->addend = 4;
|
||||||
+ rela->offset = (unsigned int)(index * sizeof(void*));
|
+ rela->offset = (unsigned int)(index * sizeof(void *));
|
||||||
+
|
+
|
||||||
+ newdata = malloc(sym->sec->data->d_size);
|
+ newdata = malloc(sym->sec->data->d_size);
|
||||||
+ if (!newdata)
|
+ if (!newdata)
|
||||||
@ -313,11 +381,22 @@ index 2707cdb..7a27b58 100644
|
|||||||
+
|
+
|
||||||
+ /*
|
+ /*
|
||||||
+ * mov x9, x30
|
+ * mov x9, x30
|
||||||
+ * nop //function in .text.<func>, so it be replaced with nop by recordmcount
|
+ * nop //function in .text.<func>, so it be replaced with nop by
|
||||||
+ * mov x30, x9
|
+ * recordmcount
|
||||||
|
+ *
|
||||||
|
+ * mov x30, x9
|
||||||
+ */
|
+ */
|
||||||
+ if (insnp[0] != 0xaa1e03e9 || insnp[1] != 0xd503201f || insnp[2] != 0xaa0903fe)
|
+ if (insnp[0] != 0xaa1e03e9 || insnp[1] != 0xd503201f
|
||||||
+ ERROR("%s: unexpected instruction at the start of the function",
|
+ || insnp[2] != 0xaa0903fe)
|
||||||
|
ERROR("%s: unexpected instruction at the start of the function",
|
||||||
|
- sym->name);
|
||||||
|
- insn[0] = 0xe8;
|
||||||
|
- insn[1] = 0;
|
||||||
|
- insn[2] = 0;
|
||||||
|
- insn[3] = 0;
|
||||||
|
- insn[4] = 0;
|
||||||
|
-
|
||||||
|
- rela->type = R_X86_64_PC32;
|
||||||
+ sym->name);
|
+ sym->name);
|
||||||
+
|
+
|
||||||
+ /* change the nop to bl __fentry__ */
|
+ /* change the nop to bl __fentry__ */
|
||||||
@ -329,11 +408,10 @@ index 2707cdb..7a27b58 100644
|
|||||||
+
|
+
|
||||||
+ } else {
|
+ } else {
|
||||||
+ ERROR("unsupport arch %d\n", arch);
|
+ ERROR("unsupport arch %d\n", arch);
|
||||||
+ }
|
}
|
||||||
|
|
||||||
index++;
|
index++;
|
||||||
}
|
@@ -3349,6 +3489,8 @@ int main(int argc, char *argv[])
|
||||||
@@ -3349,6 +3483,8 @@ int main(int argc, char *argv[])
|
|
||||||
char *hint = NULL, *orig_obj, *patched_obj, *parent_name;
|
char *hint = NULL, *orig_obj, *patched_obj, *parent_name;
|
||||||
char *parent_symtab, *mod_symvers, *patch_name, *output_obj;
|
char *parent_symtab, *mod_symvers, *patch_name, *output_obj;
|
||||||
struct sym_compare_type *base_locals, *sym_comp;
|
struct sym_compare_type *base_locals, *sym_comp;
|
||||||
@ -342,7 +420,7 @@ index 2707cdb..7a27b58 100644
|
|||||||
|
|
||||||
arguments.debug = 0;
|
arguments.debug = 0;
|
||||||
argp_parse (&argp, argc, argv, 0, NULL, &arguments);
|
argp_parse (&argp, argc, argv, 0, NULL, &arguments);
|
||||||
@@ -3369,6 +3505,13 @@ int main(int argc, char *argv[])
|
@@ -3369,6 +3511,13 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
kelf_base = kpatch_elf_open(orig_obj);
|
kelf_base = kpatch_elf_open(orig_obj);
|
||||||
kelf_patched = kpatch_elf_open(patched_obj);
|
kelf_patched = kpatch_elf_open(patched_obj);
|
||||||
@ -356,7 +434,7 @@ index 2707cdb..7a27b58 100644
|
|||||||
|
|
||||||
kpatch_compare_elf_headers(kelf_base->elf, kelf_patched->elf);
|
kpatch_compare_elf_headers(kelf_base->elf, kelf_patched->elf);
|
||||||
kpatch_check_program_headers(kelf_base->elf);
|
kpatch_check_program_headers(kelf_base->elf);
|
||||||
@@ -3407,7 +3550,12 @@ int main(int argc, char *argv[])
|
@@ -3407,7 +3556,12 @@ int main(int argc, char *argv[])
|
||||||
*/
|
*/
|
||||||
kpatch_mark_ignored_sections(kelf_patched);
|
kpatch_mark_ignored_sections(kelf_patched);
|
||||||
kpatch_compare_correlated_elements(kelf_patched);
|
kpatch_compare_correlated_elements(kelf_patched);
|
||||||
@ -370,7 +448,7 @@ index 2707cdb..7a27b58 100644
|
|||||||
kpatch_elf_teardown(kelf_base);
|
kpatch_elf_teardown(kelf_base);
|
||||||
kpatch_elf_free(kelf_base);
|
kpatch_elf_free(kelf_base);
|
||||||
|
|
||||||
@@ -3467,7 +3615,14 @@ int main(int argc, char *argv[])
|
@@ -3467,7 +3621,13 @@ int main(int argc, char *argv[])
|
||||||
kpatch_create_callbacks_objname_rela(kelf_out, parent_name);
|
kpatch_create_callbacks_objname_rela(kelf_out, parent_name);
|
||||||
kpatch_build_strings_section_data(kelf_out);
|
kpatch_build_strings_section_data(kelf_out);
|
||||||
|
|
||||||
@ -378,19 +456,18 @@ index 2707cdb..7a27b58 100644
|
|||||||
+ gcc_add_option = getenv("GCC_ADD_OPTION");
|
+ gcc_add_option = getenv("GCC_ADD_OPTION");
|
||||||
+ if (gcc_add_option)
|
+ if (gcc_add_option)
|
||||||
+ mlongcall = strstr(gcc_add_option, "-mlong-calls");
|
+ mlongcall = strstr(gcc_add_option, "-mlong-calls");
|
||||||
+ if (arch == EM_AARCH64 && mlongcall) {
|
+ if (arch == EM_AARCH64 && mlongcall)
|
||||||
+ printf("-mlong-calls found, no need to create mcount section\n");
|
+ printf("-mlong-calls found, no need to create mcount section\n");
|
||||||
+ } else {
|
+ else
|
||||||
+ kpatch_create_mcount_sections(kelf_out);
|
+ kpatch_create_mcount_sections(kelf_out);
|
||||||
+ }
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* At this point, the set of output sections and symbols is
|
* At this point, the set of output sections and symbols is
|
||||||
diff --git a/kpatch-build/create-kpatch-module.c b/kpatch-build/create-kpatch-module.c
|
diff --git a/kpatch-build/create-kpatch-module.c b/kpatch-build/create-kpatch-module.c
|
||||||
index 3d197a7..758630b 100644
|
index 3d197a7..e8a235d 100644
|
||||||
--- a/kpatch-build/create-kpatch-module.c
|
--- a/kpatch-build/create-kpatch-module.c
|
||||||
+++ b/kpatch-build/create-kpatch-module.c
|
+++ b/kpatch-build/create-kpatch-module.c
|
||||||
@@ -31,6 +31,17 @@
|
@@ -31,6 +31,18 @@
|
||||||
char *childobj;
|
char *childobj;
|
||||||
enum loglevel loglevel = NORMAL;
|
enum loglevel loglevel = NORMAL;
|
||||||
|
|
||||||
@ -400,6 +477,7 @@ index 3d197a7..758630b 100644
|
|||||||
+static unsigned int arch_of_elf(Elf *elf)
|
+static unsigned int arch_of_elf(Elf *elf)
|
||||||
+{
|
+{
|
||||||
+ GElf_Ehdr eh;
|
+ GElf_Ehdr eh;
|
||||||
|
+
|
||||||
+ if (!gelf_getehdr(elf, &eh))
|
+ if (!gelf_getehdr(elf, &eh))
|
||||||
+ ERROR("gelf_getehdr");
|
+ ERROR("gelf_getehdr");
|
||||||
+ return eh.e_machine;
|
+ return eh.e_machine;
|
||||||
@ -408,7 +486,7 @@ index 3d197a7..758630b 100644
|
|||||||
/*
|
/*
|
||||||
* Create .kpatch.dynrelas from .kpatch.relocations and .kpatch.symbols sections
|
* Create .kpatch.dynrelas from .kpatch.relocations and .kpatch.symbols sections
|
||||||
*
|
*
|
||||||
@@ -102,14 +113,14 @@ static void create_dynamic_rela_sections(struct kpatch_elf *kelf, struct section
|
@@ -102,14 +114,14 @@ static void create_dynamic_rela_sections(struct kpatch_elf *kelf, struct section
|
||||||
/* dest */
|
/* dest */
|
||||||
ALLOC_LINK(rela, &dynsec->rela->relas);
|
ALLOC_LINK(rela, &dynsec->rela->relas);
|
||||||
rela->sym = sym;
|
rela->sym = sym;
|
||||||
@ -425,7 +503,7 @@ index 3d197a7..758630b 100644
|
|||||||
rela->addend = name_offset;
|
rela->addend = name_offset;
|
||||||
rela->offset = (unsigned int)(index * sizeof(*dynrelas) + \
|
rela->offset = (unsigned int)(index * sizeof(*dynrelas) + \
|
||||||
offsetof(struct kpatch_patch_dynrela, name));
|
offsetof(struct kpatch_patch_dynrela, name));
|
||||||
@@ -117,7 +128,7 @@ static void create_dynamic_rela_sections(struct kpatch_elf *kelf, struct section
|
@@ -117,7 +129,7 @@ static void create_dynamic_rela_sections(struct kpatch_elf *kelf, struct section
|
||||||
/* objname */
|
/* objname */
|
||||||
ALLOC_LINK(rela, &dynsec->rela->relas);
|
ALLOC_LINK(rela, &dynsec->rela->relas);
|
||||||
rela->sym = strsec->secsym;
|
rela->sym = strsec->secsym;
|
||||||
@ -434,7 +512,7 @@ index 3d197a7..758630b 100644
|
|||||||
rela->addend = objname_offset;
|
rela->addend = objname_offset;
|
||||||
rela->offset = (unsigned int)(index * sizeof(*dynrelas) + \
|
rela->offset = (unsigned int)(index * sizeof(*dynrelas) + \
|
||||||
offsetof(struct kpatch_patch_dynrela, objname));
|
offsetof(struct kpatch_patch_dynrela, objname));
|
||||||
@@ -200,6 +211,13 @@ int main(int argc, char *argv[])
|
@@ -200,6 +212,13 @@ int main(int argc, char *argv[])
|
||||||
childobj = basename(arguments.args[0]);
|
childobj = basename(arguments.args[0]);
|
||||||
|
|
||||||
kelf = kpatch_elf_open(arguments.args[0]);
|
kelf = kpatch_elf_open(arguments.args[0]);
|
||||||
@ -662,4 +740,5 @@ index 9663290..35d7c1c 100755
|
|||||||
if [ "$1" = "-o" ]; then
|
if [ "$1" = "-o" ]; then
|
||||||
obj="$2"
|
obj="$2"
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
From 4511c2f36744529d0298a4d8e56d0b38c2ea5714 Mon Sep 17 00:00:00 2001
|
From 232f97ae9acb73ad7bb0b974f6a94ae4c4ca03d9 Mon Sep 17 00:00:00 2001
|
||||||
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
Date: Tue, 25 Feb 2020 22:44:50 -0500
|
Date: Tue, 25 Feb 2020 22:44:50 -0500
|
||||||
Subject: [PATCH 03/21] create-diff-object: new static var should be included
|
Subject: [PATCH 03/23] create-diff-object: new static var should be included
|
||||||
|
|
||||||
Before this patch, only global variables(no referenced) will be
|
Before this patch, only global variables(no referenced) will be
|
||||||
included by kpatch-build. But some macros put some static varibles
|
included by kpatch-build. But some macros put some static varibles
|
||||||
@ -14,41 +14,43 @@ cause a problem even the new static variables are in unbundled section.
|
|||||||
Signed-off-by: Zhou Chengming <zhouchengming1@huawei.com>
|
Signed-off-by: Zhou Chengming <zhouchengming1@huawei.com>
|
||||||
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
---
|
---
|
||||||
kpatch-build/create-diff-object.c | 15 +++++++++++++++
|
kpatch-build/create-diff-object.c | 16 ++++++++++++++++
|
||||||
1 file changed, 15 insertions(+)
|
1 file changed, 16 insertions(+)
|
||||||
|
|
||||||
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
||||||
index 7a27b58..267bd66 100644
|
index b161fee..b94060e 100644
|
||||||
--- a/kpatch-build/create-diff-object.c
|
--- a/kpatch-build/create-diff-object.c
|
||||||
+++ b/kpatch-build/create-diff-object.c
|
+++ b/kpatch-build/create-diff-object.c
|
||||||
@@ -1702,6 +1702,20 @@ static void kpatch_include_force_elements(struct kpatch_elf *kelf)
|
@@ -1704,6 +1704,21 @@ static void kpatch_include_force_elements(struct kpatch_elf *kelf)
|
||||||
sym->include = 0;
|
sym->include = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
+int kpatch_include_new_static_var(struct kpatch_elf *kelf)
|
+int kpatch_include_new_static_var(struct kpatch_elf *kelf)
|
||||||
+{
|
+{
|
||||||
+ struct symbol *sym;
|
+ struct symbol *sym;
|
||||||
+
|
+
|
||||||
+ list_for_each_entry(sym, &kelf->symbols, list) {
|
+ list_for_each_entry(sym, &kelf->symbols, list) {
|
||||||
+ if (sym->status == NEW &&
|
+ if (sym->status == NEW &&
|
||||||
+ sym->bind == STB_LOCAL &&
|
+ sym->bind == STB_LOCAL &&
|
||||||
+ (sym->type == STT_OBJECT || (sym->type == STT_NOTYPE && sym->name[0] != '$')))
|
+ (sym->type == STT_OBJECT ||
|
||||||
+ kpatch_include_symbol(sym);
|
+ (sym->type == STT_NOTYPE && sym->name[0] != '$')))
|
||||||
+ }
|
+ kpatch_include_symbol(sym);
|
||||||
|
+ }
|
||||||
+
|
+
|
||||||
+ return 0;
|
+ return 0;
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
static int kpatch_include_new_globals(struct kpatch_elf *kelf)
|
static int kpatch_include_new_globals(struct kpatch_elf *kelf)
|
||||||
{
|
{
|
||||||
struct symbol *sym;
|
struct symbol *sym;
|
||||||
@@ -3567,6 +3581,7 @@ int main(int argc, char *argv[])
|
@@ -3573,6 +3588,7 @@ int main(int argc, char *argv[])
|
||||||
callbacks_exist = kpatch_include_callback_elements(kelf_patched);
|
callbacks_exist = kpatch_include_callback_elements(kelf_patched);
|
||||||
kpatch_include_force_elements(kelf_patched);
|
kpatch_include_force_elements(kelf_patched);
|
||||||
new_globals_exist = kpatch_include_new_globals(kelf_patched);
|
new_globals_exist = kpatch_include_new_globals(kelf_patched);
|
||||||
+ kpatch_include_new_static_var(kelf_patched);
|
+ kpatch_include_new_static_var(kelf_patched);
|
||||||
kpatch_include_debug_sections(kelf_patched);
|
kpatch_include_debug_sections(kelf_patched);
|
||||||
|
|
||||||
kpatch_process_special_sections(kelf_patched);
|
kpatch_process_special_sections(kelf_patched);
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
From b407defcd16f6a8a49ed0f66d4902eb0bc1b2021 Mon Sep 17 00:00:00 2001
|
From 67c3fb57cf0b991c4f70aec78bdf25a47fb590b4 Mon Sep 17 00:00:00 2001
|
||||||
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
Date: Fri, 2 Nov 2018 17:24:42 +0000
|
Date: Fri, 2 Nov 2018 17:24:42 +0000
|
||||||
Subject: [PATCH 04/21] livepatch, fix: use THIS modname as the name of
|
Subject: [PATCH 04/23] livepatch, fix: use THIS modname as the name of
|
||||||
ddebug_table
|
ddebug_table
|
||||||
|
|
||||||
We just want a unique name for every module, so put a _ddebug in
|
We just want a unique name for every module, so put a _ddebug in
|
||||||
@ -16,16 +16,17 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
|||||||
1 file changed, 1 insertion(+)
|
1 file changed, 1 insertion(+)
|
||||||
|
|
||||||
diff --git a/kmod/patch/livepatch-patch-hook.c b/kmod/patch/livepatch-patch-hook.c
|
diff --git a/kmod/patch/livepatch-patch-hook.c b/kmod/patch/livepatch-patch-hook.c
|
||||||
index e12fd50..613d037 100644
|
index e12fd50..6ae40de 100644
|
||||||
--- a/kmod/patch/livepatch-patch-hook.c
|
--- a/kmod/patch/livepatch-patch-hook.c
|
||||||
+++ b/kmod/patch/livepatch-patch-hook.c
|
+++ b/kmod/patch/livepatch-patch-hook.c
|
||||||
@@ -473,6 +473,7 @@ out:
|
@@ -473,6 +473,7 @@ out:
|
||||||
|
|
||||||
static void __exit patch_exit(void)
|
static void __exit patch_exit(void)
|
||||||
{
|
{
|
||||||
+ pr_debug("make THIS modname first\n");
|
+ pr_debug("make THIS modname first\n");
|
||||||
#ifndef HAVE_SIMPLE_ENABLE
|
#ifndef HAVE_SIMPLE_ENABLE
|
||||||
WARN_ON(klp_unregister_patch(lpatch));
|
WARN_ON(klp_unregister_patch(lpatch));
|
||||||
#endif
|
#endif
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
From e3a9643c7fa2ac5f8093c8ac578ce9dfd45084c7 Mon Sep 17 00:00:00 2001
|
From 24c01beb0ac8cee521ba654ece6c22f6ce9bdafe Mon Sep 17 00:00:00 2001
|
||||||
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
Date: Fri, 2 Nov 2018 17:24:51 +0000
|
Date: Fri, 2 Nov 2018 17:24:51 +0000
|
||||||
Subject: [PATCH 05/21] create-diff-object: fix correlate static local
|
Subject: [PATCH 05/23] create-diff-object: fix correlate static local
|
||||||
variables for __param section
|
variables for __param section
|
||||||
|
|
||||||
kpatch-build correlate fail when no sections reference
|
kpatch-build correlate fail when no sections reference
|
||||||
@ -31,10 +31,10 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
|||||||
1 file changed, 4 insertions(+)
|
1 file changed, 4 insertions(+)
|
||||||
|
|
||||||
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
||||||
index 267bd66..78f5a7e 100644
|
index b94060e..3681adb 100644
|
||||||
--- a/kpatch-build/create-diff-object.c
|
--- a/kpatch-build/create-diff-object.c
|
||||||
+++ b/kpatch-build/create-diff-object.c
|
+++ b/kpatch-build/create-diff-object.c
|
||||||
@@ -1107,6 +1107,10 @@ static int kpatch_is_normal_static_local(struct symbol *sym)
|
@@ -1108,6 +1108,10 @@ static int kpatch_is_normal_static_local(struct symbol *sym)
|
||||||
if (is_special_static(sym))
|
if (is_special_static(sym))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -47,3 +47,4 @@ index 267bd66..78f5a7e 100644
|
|||||||
|
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
From 28a1433cc6342ee48cfea60b755c0e746b9ff548 Mon Sep 17 00:00:00 2001
|
From 30446d9a1a65c8369a54844d471c2aeb4c9139dd Mon Sep 17 00:00:00 2001
|
||||||
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
Date: Fri, 2 Nov 2018 17:24:58 +0000
|
Date: Fri, 2 Nov 2018 17:24:58 +0000
|
||||||
Subject: [PATCH 06/21] create-diff-object: don't create dynamic reloc for
|
Subject: [PATCH 06/23] create-diff-object: don't create dynamic reloc for
|
||||||
symbol exported by patch itself
|
symbol exported by patch itself
|
||||||
|
|
||||||
when a patch export a new function, ___kcrctab+xxx has a reloc,
|
when a patch export a new function, ___kcrctab+xxx has a reloc,
|
||||||
@ -13,10 +13,10 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
|||||||
1 file changed, 3 insertions(+)
|
1 file changed, 3 insertions(+)
|
||||||
|
|
||||||
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
||||||
index 78f5a7e..2cda233 100644
|
index 3681adb..ba2976b 100644
|
||||||
--- a/kpatch-build/create-diff-object.c
|
--- a/kpatch-build/create-diff-object.c
|
||||||
+++ b/kpatch-build/create-diff-object.c
|
+++ b/kpatch-build/create-diff-object.c
|
||||||
@@ -3053,6 +3053,9 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
@@ -3056,6 +3056,9 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
||||||
if (!strcmp(sym_objname, "vmlinux"))
|
if (!strcmp(sym_objname, "vmlinux"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -28,3 +28,4 @@ index 78f5a7e..2cda233 100644
|
|||||||
}
|
}
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
From f6d53ba1e5d1b8c8e026bd537235e201f8482065 Mon Sep 17 00:00:00 2001
|
From 66d1b112903b4942cc1033a1be93ae79c1ecf8ef Mon Sep 17 00:00:00 2001
|
||||||
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
Date: Fri, 2 Nov 2018 17:25:38 +0000
|
Date: Fri, 2 Nov 2018 17:25:38 +0000
|
||||||
Subject: [PATCH 07/21] create-diff-object: create dynamic relocs for changed
|
Subject: [PATCH 07/23] create-diff-object: create dynamic relocs for changed
|
||||||
functions in this object
|
functions in this object
|
||||||
|
|
||||||
Currently, we only create dynamic relocs for changed functions of
|
Currently, we only create dynamic relocs for changed functions of
|
||||||
@ -22,29 +22,29 @@ Signed-off-by: Zhou Chengming <zhouchengming1@huawei.com>
|
|||||||
Signed-off-by: Li Bin <huawei.libin@huawei.com>
|
Signed-off-by: Li Bin <huawei.libin@huawei.com>
|
||||||
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
---
|
---
|
||||||
kpatch-build/create-diff-object.c | 20 ++++++++++++++++----
|
kpatch-build/create-diff-object.c | 23 +++++++++++++++++++----
|
||||||
1 file changed, 16 insertions(+), 4 deletions(-)
|
1 file changed, 19 insertions(+), 4 deletions(-)
|
||||||
|
|
||||||
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
||||||
index 2cda233..67c062e 100644
|
index ba2976b..8ce3b59 100644
|
||||||
--- a/kpatch-build/create-diff-object.c
|
--- a/kpatch-build/create-diff-object.c
|
||||||
+++ b/kpatch-build/create-diff-object.c
|
+++ b/kpatch-build/create-diff-object.c
|
||||||
@@ -2897,6 +2897,14 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
@@ -2900,6 +2900,14 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
||||||
*/
|
*/
|
||||||
if (may_need_dynrela(rela))
|
if (may_need_dynrela(rela))
|
||||||
toc_rela(rela)->need_dynrela = 1;
|
toc_rela(rela)->need_dynrela = 1;
|
||||||
+ if (rela->sym->sec) {
|
+ if (rela->sym->sec) {
|
||||||
+ if (rela->sym->type == STT_FUNC &&
|
+ if (rela->sym->type == STT_FUNC &&
|
||||||
+ rela->sym->status == CHANGED &&
|
+ rela->sym->status == CHANGED &&
|
||||||
+ rela->sym->sec != sec->base &&
|
+ rela->sym->sec != sec->base &&
|
||||||
+ sec->base->sym &&
|
+ sec->base->sym &&
|
||||||
+ sec->base->sym->type == STT_FUNC)
|
+ sec->base->sym->type == STT_FUNC)
|
||||||
+ toc_rela(rela)->need_dynrela = 1;
|
+ toc_rela(rela)->need_dynrela = 1;
|
||||||
+ }
|
+ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2979,10 +2987,14 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
@@ -2982,10 +2990,17 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
||||||
/* An unchanged local symbol */
|
/* An unchanged local symbol */
|
||||||
ret = lookup_local_symbol(table,
|
ret = lookup_local_symbol(table,
|
||||||
rela->sym->name, &result);
|
rela->sym->name, &result);
|
||||||
@ -53,10 +53,13 @@ index 2cda233..67c062e 100644
|
|||||||
- rela->sym->name, sec->base->name);
|
- rela->sym->name, sec->base->name);
|
||||||
-
|
-
|
||||||
+ if (ret) {
|
+ if (ret) {
|
||||||
+ /* maybe it is a global symbol converted in kpatch_create_patches_sections*/
|
+ /*
|
||||||
|
+ * maybe it is a global symbol converted in
|
||||||
|
+ * kpatch_create_patches_sections
|
||||||
|
+ */
|
||||||
+ ret = lookup_global_symbol(table,
|
+ ret = lookup_global_symbol(table,
|
||||||
+ rela->sym->name, &result);
|
+ rela->sym->name, &result);
|
||||||
+ if (ret)
|
+ if (ret)
|
||||||
+ ERROR("lookup_local_symbol %s needed for %s",
|
+ ERROR("lookup_local_symbol %s needed for %s",
|
||||||
+ rela->sym->name, sec->base->name);
|
+ rela->sym->name, sec->base->name);
|
||||||
+ }
|
+ }
|
||||||
@ -65,3 +68,4 @@ index 2cda233..67c062e 100644
|
|||||||
/*
|
/*
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
From 10370cef2ef3e690355412048d19a88f81fa465b Mon Sep 17 00:00:00 2001
|
From 9f30a27617915ee8c59aa43d9165d938129796b3 Mon Sep 17 00:00:00 2001
|
||||||
From: Zhiyu Hu <huzhiyu1@huawei.com>
|
From: Zhiyu Hu <huzhiyu1@huawei.com>
|
||||||
Date: Fri, 28 Dec 2018 07:06:38 +0000
|
Date: Fri, 28 Dec 2018 07:06:38 +0000
|
||||||
Subject: [PATCH 08/21] fix rodata.str problem
|
Subject: [PATCH 08/23] fix rodata.str problem
|
||||||
|
|
||||||
fix some rodata.str problem
|
fix some rodata.str problem
|
||||||
|
|
||||||
@ -11,10 +11,10 @@ Signed-off-by: Zhiyu Hu <huzhiyu1@huawei.com>
|
|||||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||||
|
|
||||||
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
||||||
index 67c062e..bb2a803 100644
|
index 8ce3b59..f37d404 100644
|
||||||
--- a/kpatch-build/create-diff-object.c
|
--- a/kpatch-build/create-diff-object.c
|
||||||
+++ b/kpatch-build/create-diff-object.c
|
+++ b/kpatch-build/create-diff-object.c
|
||||||
@@ -1632,7 +1632,7 @@ static void kpatch_include_standard_elements(struct kpatch_elf *kelf)
|
@@ -1634,7 +1634,7 @@ static void kpatch_include_standard_elements(struct kpatch_elf *kelf)
|
||||||
!strcmp(sec->name, ".toc") ||
|
!strcmp(sec->name, ".toc") ||
|
||||||
!strcmp(sec->name, ".rodata") ||
|
!strcmp(sec->name, ".rodata") ||
|
||||||
(!strncmp(sec->name, ".rodata.", 8) &&
|
(!strncmp(sec->name, ".rodata.", 8) &&
|
||||||
@ -25,3 +25,4 @@ index 67c062e..bb2a803 100644
|
|||||||
}
|
}
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
From 66b833f4de9dca62b97f077df962c3702c919664 Mon Sep 17 00:00:00 2001
|
From 1bc8c76085839576576fc780336fbd9d7ebd29ef Mon Sep 17 00:00:00 2001
|
||||||
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
Date: Tue, 25 Feb 2020 23:40:37 -0500
|
Date: Tue, 25 Feb 2020 23:40:37 -0500
|
||||||
Subject: [PATCH 09/21] livepatch-patch-hook: don't active patch when insmod
|
Subject: [PATCH 09/23] livepatch-patch-hook: don't active patch when insmod
|
||||||
|
|
||||||
Don't active patch after loading the patch when
|
Don't active patch after loading the patch when
|
||||||
DISABLE_AFTER_LOAD is set.
|
DISABLE_AFTER_LOAD is set.
|
||||||
@ -13,7 +13,7 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
|||||||
2 files changed, 6 insertions(+)
|
2 files changed, 6 insertions(+)
|
||||||
|
|
||||||
diff --git a/kmod/patch/livepatch-patch-hook.c b/kmod/patch/livepatch-patch-hook.c
|
diff --git a/kmod/patch/livepatch-patch-hook.c b/kmod/patch/livepatch-patch-hook.c
|
||||||
index 613d037..163ae1d 100644
|
index 6ae40de..fb23a94 100644
|
||||||
--- a/kmod/patch/livepatch-patch-hook.c
|
--- a/kmod/patch/livepatch-patch-hook.c
|
||||||
+++ b/kmod/patch/livepatch-patch-hook.c
|
+++ b/kmod/patch/livepatch-patch-hook.c
|
||||||
@@ -455,6 +455,7 @@ static int __init patch_init(void)
|
@@ -455,6 +455,7 @@ static int __init patch_init(void)
|
||||||
@ -49,3 +49,4 @@ index 17a5e11..894f0ab 100755
|
|||||||
if [[ -z "$USERSRCDIR" ]] && [[ "$DISTRO" = ubuntu ]]; then
|
if [[ -z "$USERSRCDIR" ]] && [[ "$DISTRO" = ubuntu ]]; then
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
From 8486c25a0b94eb9b415572eec58508204d8e5458 Mon Sep 17 00:00:00 2001
|
From a1303033db88fa0036387f3a86f71d162bd5c037 Mon Sep 17 00:00:00 2001
|
||||||
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
Date: Wed, 26 Feb 2020 06:44:06 -0500
|
Date: Wed, 26 Feb 2020 06:44:06 -0500
|
||||||
Subject: [PATCH 10/21] kpatch-build: enhance for out of tree module
|
Subject: [PATCH 10/23] kpatch-build: enhance for out of tree module
|
||||||
|
|
||||||
support set USERMODBUILDDIR to build patch for out
|
support set USERMODBUILDDIR to build patch for out
|
||||||
of tree module.
|
of tree module.
|
||||||
@ -130,3 +130,4 @@ index 894f0ab..4e38412 100755
|
|||||||
readelf -s --wide "$KOBJFILE_PATH" > "$SYMTAB"
|
readelf -s --wide "$KOBJFILE_PATH" > "$SYMTAB"
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
From e438d0139d5e0c60b1e8dc78af8825f1a26fa438 Mon Sep 17 00:00:00 2001
|
From d170861502e78c396f0283f66f444a496efd11de Mon Sep 17 00:00:00 2001
|
||||||
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
Date: Wed, 26 Feb 2020 07:36:59 -0500
|
Date: Wed, 26 Feb 2020 07:36:59 -0500
|
||||||
Subject: [PATCH 11/21] support c plus kernel module
|
Subject: [PATCH 11/23] support c plus kernel module
|
||||||
|
|
||||||
support GNU_UNIQUE type symbols.
|
support GNU_UNIQUE type symbols.
|
||||||
support .group section corelation.
|
support .group section corelation.
|
||||||
@ -9,18 +9,18 @@ ignore compile warning for third party modules.
|
|||||||
|
|
||||||
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
---
|
---
|
||||||
kpatch-build/create-diff-object.c | 62 ++++++++++++++++++++-----------
|
kpatch-build/create-diff-object.c | 60 +++++++++++++++++++++----------
|
||||||
kpatch-build/kpatch-build | 2 +-
|
kpatch-build/kpatch-build | 2 +-
|
||||||
kpatch-build/kpatch-elf.c | 8 +++-
|
kpatch-build/kpatch-elf.c | 8 ++++-
|
||||||
kpatch-build/kpatch-gcc | 3 +-
|
kpatch-build/kpatch-gcc | 3 +-
|
||||||
kpatch-build/lookup.c | 5 ++-
|
kpatch-build/lookup.c | 5 ++-
|
||||||
5 files changed, 55 insertions(+), 25 deletions(-)
|
5 files changed, 55 insertions(+), 23 deletions(-)
|
||||||
|
|
||||||
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
||||||
index bb2a803..5f90c6b 100644
|
index f37d404..d139f45 100644
|
||||||
--- a/kpatch-build/create-diff-object.c
|
--- a/kpatch-build/create-diff-object.c
|
||||||
+++ b/kpatch-build/create-diff-object.c
|
+++ b/kpatch-build/create-diff-object.c
|
||||||
@@ -459,7 +459,7 @@ static void kpatch_compare_correlated_nonrela_section(struct section *sec)
|
@@ -460,7 +460,7 @@ static void kpatch_compare_correlated_nonrela_section(struct section *sec)
|
||||||
{
|
{
|
||||||
struct section *sec1 = sec, *sec2 = sec->twin;
|
struct section *sec1 = sec, *sec2 = sec->twin;
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ index bb2a803..5f90c6b 100644
|
|||||||
memcmp(sec1->data->d_buf, sec2->data->d_buf, sec1->data->d_size))
|
memcmp(sec1->data->d_buf, sec2->data->d_buf, sec1->data->d_size))
|
||||||
sec->status = CHANGED;
|
sec->status = CHANGED;
|
||||||
else
|
else
|
||||||
@@ -475,7 +475,7 @@ static void kpatch_compare_correlated_section(struct section *sec)
|
@@ -476,7 +476,7 @@ static void kpatch_compare_correlated_section(struct section *sec)
|
||||||
sec1->sh.sh_flags != sec2->sh.sh_flags ||
|
sec1->sh.sh_flags != sec2->sh.sh_flags ||
|
||||||
sec1->sh.sh_entsize != sec2->sh.sh_entsize ||
|
sec1->sh.sh_entsize != sec2->sh.sh_entsize ||
|
||||||
(sec1->sh.sh_addralign != sec2->sh.sh_addralign &&
|
(sec1->sh.sh_addralign != sec2->sh.sh_addralign &&
|
||||||
@ -38,11 +38,12 @@ index bb2a803..5f90c6b 100644
|
|||||||
DIFF_FATAL("%s section header details differ from %s", sec1->name, sec2->name);
|
DIFF_FATAL("%s section header details differ from %s", sec1->name, sec2->name);
|
||||||
|
|
||||||
/* Short circuit for mcount sections, we rebuild regardless */
|
/* Short circuit for mcount sections, we rebuild regardless */
|
||||||
@@ -912,6 +912,33 @@ static void kpatch_correlate_section(struct section *sec1, struct section *sec2)
|
@@ -913,6 +913,34 @@ static void kpatch_correlate_section(struct section *sec1, struct section *sec2)
|
||||||
kpatch_correlate_symbol(sec1->sym, sec2->sym);
|
kpatch_correlate_symbol(sec1->sym, sec2->sym);
|
||||||
}
|
}
|
||||||
|
|
||||||
+static int kpatch_correlate_group_section(struct list_head *seclist1, struct list_head *seclist2, struct section *sec1, struct section *sec2)
|
+static int kpatch_correlate_group_section(struct list_head *seclist1,
|
||||||
|
+ struct list_head *seclist2, struct section *sec1, struct section *sec2)
|
||||||
+{
|
+{
|
||||||
+ unsigned int *data1, *end1, *data2;
|
+ unsigned int *data1, *end1, *data2;
|
||||||
+ struct section *isec1, *isec2;
|
+ struct section *isec1, *isec2;
|
||||||
@ -72,15 +73,13 @@ index bb2a803..5f90c6b 100644
|
|||||||
static void kpatch_correlate_sections(struct list_head *seclist1, struct list_head *seclist2)
|
static void kpatch_correlate_sections(struct list_head *seclist1, struct list_head *seclist2)
|
||||||
{
|
{
|
||||||
struct section *sec1, *sec2;
|
struct section *sec1, *sec2;
|
||||||
@@ -929,15 +956,19 @@ static void kpatch_correlate_sections(struct list_head *seclist1, struct list_he
|
@@ -931,14 +959,19 @@ static void kpatch_correlate_sections(struct list_head *seclist1, struct list_he
|
||||||
sec1->secsym))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
- /*
|
/*
|
||||||
- * Group sections must match exactly to be correlated.
|
- * Group sections must match exactly to be correlated.
|
||||||
- * Changed group sections are currently not supported.
|
- * Changed group sections are currently not supported.
|
||||||
- */
|
+ * Group section的格式为:
|
||||||
+ /* Group section的格式为:
|
|
||||||
+ * flag
|
+ * flag
|
||||||
+ * section index
|
+ * section index
|
||||||
+ * section index
|
+ * section index
|
||||||
@ -89,18 +88,18 @@ index bb2a803..5f90c6b 100644
|
|||||||
+ * 当C++代码发生修改时,section index可能会发生变化
|
+ * 当C++代码发生修改时,section index可能会发生变化
|
||||||
+ * 这时候我们就比对一下section index所对应的section的
|
+ * 这时候我们就比对一下section index所对应的section的
|
||||||
+ * name,如果相同,我们就认为这两个group是SAME
|
+ * name,如果相同,我们就认为这两个group是SAME
|
||||||
+ * */
|
*/
|
||||||
+
|
+
|
||||||
if (sec1->sh.sh_type == SHT_GROUP) {
|
if (sec1->sh.sh_type == SHT_GROUP) {
|
||||||
- if (sec1->data->d_size != sec2->data->d_size)
|
- if (sec1->data->d_size != sec2->data->d_size)
|
||||||
- continue;
|
- continue;
|
||||||
- if (memcmp(sec1->data->d_buf, sec2->data->d_buf,
|
- if (memcmp(sec1->data->d_buf, sec2->data->d_buf,
|
||||||
- sec1->data->d_size))
|
- sec1->data->d_size))
|
||||||
+ if(kpatch_correlate_group_section(seclist1, seclist2, sec1, sec2))
|
+ if (kpatch_correlate_group_section(seclist1, seclist2, sec1, sec2))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1519,17 +1550,6 @@ static void kpatch_verify_patchability(struct kpatch_elf *kelf)
|
@@ -1521,17 +1554,6 @@ static void kpatch_verify_patchability(struct kpatch_elf *kelf)
|
||||||
errs++;
|
errs++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +131,7 @@ index 4e38412..4896136 100755
|
|||||||
cp -f "$TEMPDIR/patch/$MODNAME.ko" "$BASE" || die
|
cp -f "$TEMPDIR/patch/$MODNAME.ko" "$BASE" || die
|
||||||
|
|
||||||
diff --git a/kpatch-build/kpatch-elf.c b/kpatch-build/kpatch-elf.c
|
diff --git a/kpatch-build/kpatch-elf.c b/kpatch-build/kpatch-elf.c
|
||||||
index c6af59e..b3ca7f5 100644
|
index c6af59e..f76a9eb 100644
|
||||||
--- a/kpatch-build/kpatch-elf.c
|
--- a/kpatch-build/kpatch-elf.c
|
||||||
+++ b/kpatch-build/kpatch-elf.c
|
+++ b/kpatch-build/kpatch-elf.c
|
||||||
@@ -710,8 +710,14 @@ void kpatch_reindex_elements(struct kpatch_elf *kelf)
|
@@ -710,8 +710,14 @@ void kpatch_reindex_elements(struct kpatch_elf *kelf)
|
||||||
@ -142,10 +141,10 @@ index c6af59e..b3ca7f5 100644
|
|||||||
- list_for_each_entry(sec, &kelf->sections, list)
|
- list_for_each_entry(sec, &kelf->sections, list)
|
||||||
+ list_for_each_entry(sec, &kelf->sections, list) {
|
+ list_for_each_entry(sec, &kelf->sections, list) {
|
||||||
sec->index = index++;
|
sec->index = index++;
|
||||||
+ /*
|
+ /*
|
||||||
+ * since we exclude .group section, we clear SHF_GROUP
|
+ * since we exclude .group section, we clear SHF_GROUP
|
||||||
+ * for every section in case of link error.
|
+ * for every section in case of link error.
|
||||||
+ * */
|
+ */
|
||||||
+ sec->sh.sh_flags &= (~SHF_GROUP);
|
+ sec->sh.sh_flags &= (~SHF_GROUP);
|
||||||
+ }
|
+ }
|
||||||
|
|
||||||
@ -190,3 +189,4 @@ index 8387e8b..4e2fcb9 100644
|
|||||||
result->size = sym->size;
|
result->size = sym->size;
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
From cf0a8995e6924d8130087a4859c5bf619515768d Mon Sep 17 00:00:00 2001
|
From 8dbdf64abc81a8c6f9ec71a4187eb7db9b81d090 Mon Sep 17 00:00:00 2001
|
||||||
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
Date: Wed, 26 Feb 2020 22:03:55 -0500
|
Date: Wed, 26 Feb 2020 22:03:55 -0500
|
||||||
Subject: [PATCH 12/21] symbol lookup enhancement
|
Subject: [PATCH 12/23] symbol lookup enhancement
|
||||||
|
|
||||||
For symbols which have same name in one module or have
|
For symbols which have same name in one module or have
|
||||||
length longger than KSYM_NAME_LEN(128 bytes). we add
|
length longger than KSYM_NAME_LEN(128 bytes). we add
|
||||||
@ -13,16 +13,16 @@ style.
|
|||||||
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
---
|
---
|
||||||
kmod/patch/kpatch-patch.h | 4 +
|
kmod/patch/kpatch-patch.h | 4 +
|
||||||
kpatch-build/create-diff-object.c | 46 ++++++++++-
|
kpatch-build/create-diff-object.c | 53 +++++++++++-
|
||||||
kpatch-build/create-klp-module.c | 26 ++++--
|
kpatch-build/create-klp-module.c | 25 +++++-
|
||||||
kpatch-build/kpatch-build | 12 +++
|
kpatch-build/kpatch-build | 12 +++
|
||||||
kpatch-build/kpatch-intermediate.h | 2 +
|
kpatch-build/kpatch-intermediate.h | 2 +
|
||||||
kpatch-build/lookup.c | 123 ++++++++++++++++++++++++++++-
|
kpatch-build/lookup.c | 129 ++++++++++++++++++++++++++++-
|
||||||
kpatch-build/lookup.h | 13 +++
|
kpatch-build/lookup.h | 13 +++
|
||||||
7 files changed, 217 insertions(+), 9 deletions(-)
|
7 files changed, 230 insertions(+), 8 deletions(-)
|
||||||
|
|
||||||
diff --git a/kmod/patch/kpatch-patch.h b/kmod/patch/kpatch-patch.h
|
diff --git a/kmod/patch/kpatch-patch.h b/kmod/patch/kpatch-patch.h
|
||||||
index da4f6a0..3530f66 100644
|
index da4f6a0..9df7818 100644
|
||||||
--- a/kmod/patch/kpatch-patch.h
|
--- a/kmod/patch/kpatch-patch.h
|
||||||
+++ b/kmod/patch/kpatch-patch.h
|
+++ b/kmod/patch/kpatch-patch.h
|
||||||
@@ -30,6 +30,8 @@ struct kpatch_patch_func {
|
@@ -30,6 +30,8 @@ struct kpatch_patch_func {
|
||||||
@ -38,16 +38,16 @@ index da4f6a0..3530f66 100644
|
|||||||
char *objname;
|
char *objname;
|
||||||
int external;
|
int external;
|
||||||
long addend;
|
long addend;
|
||||||
+ char *ref_name;
|
+ char *ref_name;
|
||||||
+ long ref_offset;
|
+ long ref_offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct kpatch_pre_patch_callback {
|
struct kpatch_pre_patch_callback {
|
||||||
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
||||||
index 5f90c6b..1bec4f4 100644
|
index d139f45..73c557b 100644
|
||||||
--- a/kpatch-build/create-diff-object.c
|
--- a/kpatch-build/create-diff-object.c
|
||||||
+++ b/kpatch-build/create-diff-object.c
|
+++ b/kpatch-build/create-diff-object.c
|
||||||
@@ -2748,6 +2748,28 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf,
|
@@ -2753,6 +2753,29 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf,
|
||||||
funcs[index].old_size = result.size;
|
funcs[index].old_size = result.size;
|
||||||
funcs[index].new_size = sym->sym.st_size;
|
funcs[index].new_size = sym->sym.st_size;
|
||||||
funcs[index].sympos = result.pos;
|
funcs[index].sympos = result.pos;
|
||||||
@ -55,7 +55,8 @@ index 5f90c6b..1bec4f4 100644
|
|||||||
+ struct lookup_refsym refsym;
|
+ struct lookup_refsym refsym;
|
||||||
+ long offset;
|
+ long offset;
|
||||||
+
|
+
|
||||||
+ if (lookup_ref_symbol_offset(table, sym->name, &refsym, objname, &offset))
|
+ if (lookup_ref_symbol_offset(table, sym->name, &refsym,
|
||||||
|
+ objname, &offset))
|
||||||
+ ERROR("unresolvable ambiguity on symbol %s\n", sym->name);
|
+ ERROR("unresolvable ambiguity on symbol %s\n", sym->name);
|
||||||
+
|
+
|
||||||
+ funcs[index].ref_offset = offset;
|
+ funcs[index].ref_offset = offset;
|
||||||
@ -76,16 +77,17 @@ index 5f90c6b..1bec4f4 100644
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Add a relocation that will populate
|
* Add a relocation that will populate
|
||||||
@@ -2767,7 +2789,7 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf,
|
@@ -2772,7 +2795,8 @@ static void kpatch_create_patches_sections(struct kpatch_elf *kelf,
|
||||||
ALLOC_LINK(rela, &relasec->relas);
|
ALLOC_LINK(rela, &relasec->relas);
|
||||||
rela->sym = strsym;
|
rela->sym = strsym;
|
||||||
rela->type = absolute_rela_type;
|
rela->type = absolute_rela_type;
|
||||||
- rela->addend = offset_of_string(&kelf->strings, sym->name);
|
- rela->addend = offset_of_string(&kelf->strings, sym->name);
|
||||||
+ rela->addend = offset_of_string(&kelf->strings, strndup(sym->name, KSYM_NAME_LEN-1));
|
+ rela->addend = offset_of_string(&kelf->strings,
|
||||||
|
+ strndup(sym->name, KSYM_NAME_LEN-1));
|
||||||
rela->offset = (unsigned int)(index * sizeof(*funcs) +
|
rela->offset = (unsigned int)(index * sizeof(*funcs) +
|
||||||
offsetof(struct kpatch_patch_func, name));
|
offsetof(struct kpatch_patch_func, name));
|
||||||
|
|
||||||
@@ -2886,6 +2908,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
@@ -2891,6 +2915,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
||||||
struct lookup_result result;
|
struct lookup_result result;
|
||||||
char *sym_objname;
|
char *sym_objname;
|
||||||
int ret, vmlinux, external;
|
int ret, vmlinux, external;
|
||||||
@ -93,7 +95,7 @@ index 5f90c6b..1bec4f4 100644
|
|||||||
|
|
||||||
vmlinux = !strcmp(objname, "vmlinux");
|
vmlinux = !strcmp(objname, "vmlinux");
|
||||||
|
|
||||||
@@ -3094,12 +3117,28 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
@@ -3102,12 +3127,32 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
||||||
log_debug("lookup for %s @ 0x%016lx len %lu\n",
|
log_debug("lookup for %s @ 0x%016lx len %lu\n",
|
||||||
rela->sym->name, result.value, result.size);
|
rela->sym->name, result.value, result.size);
|
||||||
|
|
||||||
@ -105,17 +107,21 @@ index 5f90c6b..1bec4f4 100644
|
|||||||
+ else {
|
+ else {
|
||||||
/* for modules, src is discovered at runtime */
|
/* for modules, src is discovered at runtime */
|
||||||
ksyms[index].src = 0;
|
ksyms[index].src = 0;
|
||||||
+ if (lookup_is_duplicate_symbol(table, rela->sym->name, objname, result.pos)) {
|
+ if (lookup_is_duplicate_symbol(table, rela->sym->name, objname,
|
||||||
|
+ result.pos)) {
|
||||||
+ struct lookup_refsym refsym;
|
+ struct lookup_refsym refsym;
|
||||||
+
|
+
|
||||||
+ if (lookup_ref_symbol_offset(table, rela->sym->name, &refsym, objname, &ref_offset))
|
+ if (lookup_ref_symbol_offset(table, rela->sym->name,
|
||||||
+ ERROR("unresolvable ambiguity on symbol %s\n", rela->sym->name);
|
+ &refsym, objname, &ref_offset))
|
||||||
|
+ ERROR("unresolvable ambiguity on symbol %s\n",
|
||||||
|
+ rela->sym->name);
|
||||||
+
|
+
|
||||||
+ /* add rela to fill in ref_name field */
|
+ /* add rela to fill in ref_name field */
|
||||||
+ ALLOC_LINK(rela2, &krela_sec->rela->relas);
|
+ ALLOC_LINK(rela2, &krela_sec->rela->relas);
|
||||||
+ rela2->sym = strsym;
|
+ rela2->sym = strsym;
|
||||||
+ rela2->type = absolute_rela_type;
|
+ rela2->type = absolute_rela_type;
|
||||||
+ rela2->addend = offset_of_string(&kelf->strings, refsym.name);
|
+ rela2->addend = offset_of_string(&kelf->strings,
|
||||||
|
+ refsym.name);
|
||||||
+ rela2->offset = (unsigned int)(index * sizeof(*krelas) +
|
+ rela2->offset = (unsigned int)(index * sizeof(*krelas) +
|
||||||
+ offsetof(struct kpatch_relocation, ref_name));
|
+ offsetof(struct kpatch_relocation, ref_name));
|
||||||
+ }
|
+ }
|
||||||
@ -123,16 +129,17 @@ index 5f90c6b..1bec4f4 100644
|
|||||||
ksyms[index].pos = result.pos;
|
ksyms[index].pos = result.pos;
|
||||||
ksyms[index].type = rela->sym->type;
|
ksyms[index].type = rela->sym->type;
|
||||||
ksyms[index].bind = rela->sym->bind;
|
ksyms[index].bind = rela->sym->bind;
|
||||||
@@ -3108,7 +3147,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
@@ -3116,7 +3161,8 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
||||||
ALLOC_LINK(rela2, &ksym_sec->rela->relas);
|
ALLOC_LINK(rela2, &ksym_sec->rela->relas);
|
||||||
rela2->sym = strsym;
|
rela2->sym = strsym;
|
||||||
rela2->type = absolute_rela_type;
|
rela2->type = absolute_rela_type;
|
||||||
- rela2->addend = offset_of_string(&kelf->strings, rela->sym->name);
|
- rela2->addend = offset_of_string(&kelf->strings, rela->sym->name);
|
||||||
+ rela2->addend = offset_of_string(&kelf->strings, strndup(rela->sym->name, KSYM_NAME_LEN-1));
|
+ rela2->addend = offset_of_string(&kelf->strings,
|
||||||
|
+ strndup(rela->sym->name, KSYM_NAME_LEN-1));
|
||||||
rela2->offset = (unsigned int)(index * sizeof(*ksyms) + \
|
rela2->offset = (unsigned int)(index * sizeof(*ksyms) + \
|
||||||
offsetof(struct kpatch_symbol, name));
|
offsetof(struct kpatch_symbol, name));
|
||||||
|
|
||||||
@@ -3127,6 +3166,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
@@ -3135,6 +3181,7 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
||||||
krelas[index].addend = rela->addend;
|
krelas[index].addend = rela->addend;
|
||||||
krelas[index].type = rela->type;
|
krelas[index].type = rela->type;
|
||||||
krelas[index].external = external;
|
krelas[index].external = external;
|
||||||
@ -141,7 +148,7 @@ index 5f90c6b..1bec4f4 100644
|
|||||||
/* add rela to fill in krelas[index].dest field */
|
/* add rela to fill in krelas[index].dest field */
|
||||||
ALLOC_LINK(rela2, &krela_sec->rela->relas);
|
ALLOC_LINK(rela2, &krela_sec->rela->relas);
|
||||||
diff --git a/kpatch-build/create-klp-module.c b/kpatch-build/create-klp-module.c
|
diff --git a/kpatch-build/create-klp-module.c b/kpatch-build/create-klp-module.c
|
||||||
index a97b146..0b441fa 100644
|
index a97b146..5b89b73 100644
|
||||||
--- a/kpatch-build/create-klp-module.c
|
--- a/kpatch-build/create-klp-module.c
|
||||||
+++ b/kpatch-build/create-klp-module.c
|
+++ b/kpatch-build/create-klp-module.c
|
||||||
@@ -38,7 +38,9 @@ enum loglevel loglevel = NORMAL;
|
@@ -38,7 +38,9 @@ enum loglevel loglevel = NORMAL;
|
||||||
@ -176,7 +183,7 @@ index a97b146..0b441fa 100644
|
|||||||
struct rela *rela;
|
struct rela *rela;
|
||||||
char *objname;
|
char *objname;
|
||||||
unsigned int nr, index, offset, dest_off;
|
unsigned int nr, index, offset, dest_off;
|
||||||
+ char *ref_name;
|
+ char *ref_name;
|
||||||
|
|
||||||
krelas = krelasec->data->d_buf;
|
krelas = krelasec->data->d_buf;
|
||||||
nr = (unsigned int)(krelasec->data->d_size / sizeof(*krelas));
|
nr = (unsigned int)(krelasec->data->d_size / sizeof(*krelas));
|
||||||
@ -186,23 +193,22 @@ index a97b146..0b441fa 100644
|
|||||||
|
|
||||||
+ /* Get the unique ref_name */
|
+ /* Get the unique ref_name */
|
||||||
+ rela = find_rela_by_offset(krelasec->rela,
|
+ rela = find_rela_by_offset(krelasec->rela,
|
||||||
+ (unsigned int)(offset + offsetof(struct kpatch_relocation, ref_name)));
|
+ (unsigned int)(offset + offsetof(struct kpatch_relocation,
|
||||||
|
+ ref_name)));
|
||||||
+ if (!rela)
|
+ if (!rela)
|
||||||
+ ref_name = NULL;
|
+ ref_name = NULL;
|
||||||
+ else {
|
+ else
|
||||||
+ ref_name = strings + rela->addend;
|
+ ref_name = strings + rela->addend;
|
||||||
+ }
|
|
||||||
+
|
+
|
||||||
/* Get the .kpatch.symbol entry for the rela src */
|
/* Get the .kpatch.symbol entry for the rela src */
|
||||||
rela = find_rela_by_offset(krelasec->rela,
|
rela = find_rela_by_offset(krelasec->rela,
|
||||||
(unsigned int)(offset + offsetof(struct kpatch_relocation, ksym)));
|
(unsigned int)(offset + offsetof(struct kpatch_relocation, ksym)));
|
||||||
@@ -207,8 +224,7 @@ static void create_klp_relasecs_and_syms(struct kpatch_elf *kelf, struct section
|
@@ -208,7 +225,7 @@ static void create_klp_relasecs_and_syms(struct kpatch_elf *kelf, struct section
|
||||||
ERROR("find_rela_by_offset");
|
|
||||||
|
|
||||||
/* Create (or find) a klp symbol from the rela src entry */
|
/* Create (or find) a klp symbol from the rela src entry */
|
||||||
- sym = find_or_add_ksym_to_symbols(kelf, ksymsec, strings,
|
sym = find_or_add_ksym_to_symbols(kelf, ksymsec, strings,
|
||||||
- (unsigned int)rela->addend);
|
- (unsigned int)rela->addend);
|
||||||
+ sym = find_or_add_ksym_to_symbols(kelf, ksymsec, strings, (unsigned int)rela->addend, ref_name, krelas[index].ref_offset);
|
+ (unsigned int)rela->addend, ref_name, krelas[index].ref_offset);
|
||||||
if (!sym)
|
if (!sym)
|
||||||
ERROR("error finding or adding ksym to symtab");
|
ERROR("error finding or adding ksym to symtab");
|
||||||
|
|
||||||
@ -230,20 +236,20 @@ index 4896136..8bef7fb 100755
|
|||||||
BUILDDIR="/lib/modules/$ARCHVERSION/build/"
|
BUILDDIR="/lib/modules/$ARCHVERSION/build/"
|
||||||
SYMVERS_FILE="$TEMPDIR/Module.symvers"
|
SYMVERS_FILE="$TEMPDIR/Module.symvers"
|
||||||
diff --git a/kpatch-build/kpatch-intermediate.h b/kpatch-build/kpatch-intermediate.h
|
diff --git a/kpatch-build/kpatch-intermediate.h b/kpatch-build/kpatch-intermediate.h
|
||||||
index 7230cd4..7247cac 100644
|
index 7230cd4..5322e7a 100644
|
||||||
--- a/kpatch-build/kpatch-intermediate.h
|
--- a/kpatch-build/kpatch-intermediate.h
|
||||||
+++ b/kpatch-build/kpatch-intermediate.h
|
+++ b/kpatch-build/kpatch-intermediate.h
|
||||||
@@ -39,6 +39,8 @@ struct kpatch_relocation {
|
@@ -39,6 +39,8 @@ struct kpatch_relocation {
|
||||||
long addend;
|
long addend;
|
||||||
char *objname; /* object to which this rela applies to */
|
char *objname; /* object to which this rela applies to */
|
||||||
struct kpatch_symbol *ksym;
|
struct kpatch_symbol *ksym;
|
||||||
+ char *ref_name;
|
+ char *ref_name;
|
||||||
+ long ref_offset;
|
+ long ref_offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct kpatch_arch {
|
struct kpatch_arch {
|
||||||
diff --git a/kpatch-build/lookup.c b/kpatch-build/lookup.c
|
diff --git a/kpatch-build/lookup.c b/kpatch-build/lookup.c
|
||||||
index 4e2fcb9..190a7d8 100644
|
index 4e2fcb9..1dd183f 100644
|
||||||
--- a/kpatch-build/lookup.c
|
--- a/kpatch-build/lookup.c
|
||||||
+++ b/kpatch-build/lookup.c
|
+++ b/kpatch-build/lookup.c
|
||||||
@@ -44,6 +44,7 @@ struct object_symbol {
|
@@ -44,6 +44,7 @@ struct object_symbol {
|
||||||
@ -262,15 +268,17 @@ index 4e2fcb9..190a7d8 100644
|
|||||||
|
|
||||||
if (!strcmp(bind, "LOCAL")) {
|
if (!strcmp(bind, "LOCAL")) {
|
||||||
table->obj_syms[i].bind = STB_LOCAL;
|
table->obj_syms[i].bind = STB_LOCAL;
|
||||||
@@ -398,6 +400,15 @@ int lookup_local_symbol(struct lookup_table *table, char *name,
|
@@ -398,6 +400,17 @@ int lookup_local_symbol(struct lookup_table *table, char *name,
|
||||||
for_each_obj_symbol(i, sym, table) {
|
for_each_obj_symbol(i, sym, table) {
|
||||||
if (sym->bind == STB_LOCAL && !strcmp(sym->name, name))
|
if (sym->bind == STB_LOCAL && !strcmp(sym->name, name))
|
||||||
pos++;
|
pos++;
|
||||||
+ else {
|
+ else {
|
||||||
+ /* symbol name longer than KSYM_NAME_LEN will be truncated
|
+ /*
|
||||||
|
+ * symbol name longer than KSYM_NAME_LEN will be truncated
|
||||||
+ * by kernel, so we can not find it using its original
|
+ * by kernel, so we can not find it using its original
|
||||||
+ * name. we need to add pos for symbols which have same
|
+ * name. we need to add pos for symbols which have same
|
||||||
+ * KSYM_NAME_LEN-1 long prefix.*/
|
+ * KSYM_NAME_LEN-1 long prefix.
|
||||||
|
+ */
|
||||||
+ if (strlen(name) >= KSYM_NAME_LEN-1 &&
|
+ if (strlen(name) >= KSYM_NAME_LEN-1 &&
|
||||||
+ !strncmp(sym->name, name, KSYM_NAME_LEN-1))
|
+ !strncmp(sym->name, name, KSYM_NAME_LEN-1))
|
||||||
+ pos++;
|
+ pos++;
|
||||||
@ -278,7 +286,7 @@ index 4e2fcb9..190a7d8 100644
|
|||||||
|
|
||||||
if (table->local_syms == sym) {
|
if (table->local_syms == sym) {
|
||||||
in_file = 1;
|
in_file = 1;
|
||||||
@@ -429,16 +440,25 @@ int lookup_global_symbol(struct lookup_table *table, char *name,
|
@@ -429,16 +442,27 @@ int lookup_global_symbol(struct lookup_table *table, char *name,
|
||||||
struct lookup_result *result)
|
struct lookup_result *result)
|
||||||
{
|
{
|
||||||
struct object_symbol *sym;
|
struct object_symbol *sym;
|
||||||
@ -287,10 +295,12 @@ index 4e2fcb9..190a7d8 100644
|
|||||||
|
|
||||||
memset(result, 0, sizeof(*result));
|
memset(result, 0, sizeof(*result));
|
||||||
for_each_obj_symbol(i, sym, table) {
|
for_each_obj_symbol(i, sym, table) {
|
||||||
+ /* symbol name longer than KSYM_NAME_LEN will be truncated
|
+ /*
|
||||||
|
+ * symbol name longer than KSYM_NAME_LEN will be truncated
|
||||||
+ * by kernel, so we can not find it using its original
|
+ * by kernel, so we can not find it using its original
|
||||||
+ * name. we need to add pos for symbols which have same
|
+ * name. we need to add pos for symbols which have same
|
||||||
+ * KSYM_NAME_LEN-1 long prefix.*/
|
+ * KSYM_NAME_LEN-1 long prefix.
|
||||||
|
+ */
|
||||||
+ if (strlen(name) >= KSYM_NAME_LEN-1 &&
|
+ if (strlen(name) >= KSYM_NAME_LEN-1 &&
|
||||||
+ !strncmp(sym->name, name, KSYM_NAME_LEN-1))
|
+ !strncmp(sym->name, name, KSYM_NAME_LEN-1))
|
||||||
+ pos++;
|
+ pos++;
|
||||||
@ -305,7 +315,7 @@ index 4e2fcb9..190a7d8 100644
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -485,6 +505,107 @@ char *lookup_exported_symbol_objname(struct lookup_table *table, char *name)
|
@@ -485,6 +509,109 @@ char *lookup_exported_symbol_objname(struct lookup_table *table, char *name)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,12 +333,14 @@ index 4e2fcb9..190a7d8 100644
|
|||||||
+ return 1;
|
+ return 1;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ /* symbol name longer than KSYM_NAME_LEN will be truncated
|
+ /*
|
||||||
|
+ * symbol name longer than KSYM_NAME_LEN will be truncated
|
||||||
+ * by kernel, so we can not find it using its original
|
+ * by kernel, so we can not find it using its original
|
||||||
+ * name. Here, we consider these long name symbol as duplicated
|
+ * name. Here, we consider these long name symbol as duplicated
|
||||||
+ * symbols. since create_klp_module will create symbol name
|
+ * symbols. since create_klp_module will create symbol name
|
||||||
+ * format like .klp.sym.objname.symbol,pos, so we consider name
|
+ * format like .klp.sym.objname.symbol,pos, so we consider name
|
||||||
+ * length longer than KSYM_NAME_LEN-1 bytes as duplicated symbol*/
|
+ * length longer than KSYM_NAME_LEN-1 bytes as duplicated symbol
|
||||||
|
+ */
|
||||||
+ snprintf(posstr, 32, "%lu", pos);
|
+ snprintf(posstr, 32, "%lu", pos);
|
||||||
+ snprintf(buf, 256, KLP_SYM_PREFIX "%s.%s,%s", objname, name, posstr);
|
+ snprintf(buf, 256, KLP_SYM_PREFIX "%s.%s,%s", objname, name, posstr);
|
||||||
+ if (strlen(buf) >= KSYM_NAME_LEN-1)
|
+ if (strlen(buf) >= KSYM_NAME_LEN-1)
|
||||||
@ -414,7 +426,7 @@ index 4e2fcb9..190a7d8 100644
|
|||||||
static void find_this(struct lookup_table *table, char *sym, char *hint)
|
static void find_this(struct lookup_table *table, char *sym, char *hint)
|
||||||
{
|
{
|
||||||
diff --git a/kpatch-build/lookup.h b/kpatch-build/lookup.h
|
diff --git a/kpatch-build/lookup.h b/kpatch-build/lookup.h
|
||||||
index 420d0f0..fed3fe9 100644
|
index 420d0f0..6f640fd 100644
|
||||||
--- a/kpatch-build/lookup.h
|
--- a/kpatch-build/lookup.h
|
||||||
+++ b/kpatch-build/lookup.h
|
+++ b/kpatch-build/lookup.h
|
||||||
@@ -1,6 +1,9 @@
|
@@ -1,6 +1,9 @@
|
||||||
@ -446,9 +458,10 @@ index 420d0f0..fed3fe9 100644
|
|||||||
+int lookup_is_duplicate_symbol(struct lookup_table *table, char *name,
|
+int lookup_is_duplicate_symbol(struct lookup_table *table, char *name,
|
||||||
+ char *objname, unsigned long pos);
|
+ char *objname, unsigned long pos);
|
||||||
+int lookup_ref_symbol_offset(struct lookup_table *table, char *name,
|
+int lookup_ref_symbol_offset(struct lookup_table *table, char *name,
|
||||||
+ struct lookup_refsym *refsym, char *objname,
|
+ struct lookup_refsym *refsym, char *objname,
|
||||||
+ long *offset);
|
+ long *offset);
|
||||||
|
|
||||||
#endif /* _LOOKUP_H_ */
|
#endif /* _LOOKUP_H_ */
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
From 0475b1196c1b5eea3a52e2ff104be91fb27192be Mon Sep 17 00:00:00 2001
|
From 5e6c1b2c91af547ad53faafeec20cddaedf7aaa4 Mon Sep 17 00:00:00 2001
|
||||||
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
Date: Wed, 26 Feb 2020 20:28:13 -0500
|
Date: Wed, 26 Feb 2020 20:28:13 -0500
|
||||||
Subject: [PATCH 13/21] Add running kernel symbol table to help symbol lookup
|
Subject: [PATCH 13/23] Add running kernel symbol table to help symbol lookup
|
||||||
|
|
||||||
For some duplicate symbols whose section have no other
|
For some duplicate symbols whose section have no other
|
||||||
symbols, we need running kernel symbol table to help
|
symbols, we need running kernel symbol table to help
|
||||||
@ -10,15 +10,15 @@ symbol lookup.
|
|||||||
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
---
|
---
|
||||||
kpatch-build/create-diff-object.c | 7 ++-
|
kpatch-build/create-diff-object.c | 7 ++-
|
||||||
kpatch-build/lookup.c | 73 ++++++++++++++++++++++++++++++-
|
kpatch-build/lookup.c | 74 ++++++++++++++++++++++++++++++-
|
||||||
kpatch-build/lookup.h | 3 +-
|
kpatch-build/lookup.h | 3 +-
|
||||||
3 files changed, 80 insertions(+), 3 deletions(-)
|
3 files changed, 81 insertions(+), 3 deletions(-)
|
||||||
|
|
||||||
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
||||||
index 1bec4f4..10d07ba 100644
|
index 73c557b..c5320d4 100644
|
||||||
--- a/kpatch-build/create-diff-object.c
|
--- a/kpatch-build/create-diff-object.c
|
||||||
+++ b/kpatch-build/create-diff-object.c
|
+++ b/kpatch-build/create-diff-object.c
|
||||||
@@ -3578,6 +3578,7 @@ int main(int argc, char *argv[])
|
@@ -3597,6 +3597,7 @@ int main(int argc, char *argv[])
|
||||||
struct sym_compare_type *base_locals, *sym_comp;
|
struct sym_compare_type *base_locals, *sym_comp;
|
||||||
char *no_profiling_calls = NULL;
|
char *no_profiling_calls = NULL;
|
||||||
char *gcc_add_option = NULL, *mlongcall = NULL;
|
char *gcc_add_option = NULL, *mlongcall = NULL;
|
||||||
@ -26,7 +26,7 @@ index 1bec4f4..10d07ba 100644
|
|||||||
|
|
||||||
arguments.debug = 0;
|
arguments.debug = 0;
|
||||||
argp_parse (&argp, argc, argv, 0, NULL, &arguments);
|
argp_parse (&argp, argc, argv, 0, NULL, &arguments);
|
||||||
@@ -3691,8 +3692,12 @@ int main(int argc, char *argv[])
|
@@ -3710,8 +3711,12 @@ int main(int argc, char *argv[])
|
||||||
*/
|
*/
|
||||||
kpatch_elf_teardown(kelf_patched);
|
kpatch_elf_teardown(kelf_patched);
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ index 1bec4f4..10d07ba 100644
|
|||||||
free(sym_comp->name);
|
free(sym_comp->name);
|
||||||
}
|
}
|
||||||
diff --git a/kpatch-build/lookup.c b/kpatch-build/lookup.c
|
diff --git a/kpatch-build/lookup.c b/kpatch-build/lookup.c
|
||||||
index 190a7d8..8f53567 100644
|
index 1dd183f..03a5b32 100644
|
||||||
--- a/kpatch-build/lookup.c
|
--- a/kpatch-build/lookup.c
|
||||||
+++ b/kpatch-build/lookup.c
|
+++ b/kpatch-build/lookup.c
|
||||||
@@ -45,6 +45,7 @@ struct object_symbol {
|
@@ -45,6 +45,7 @@ struct object_symbol {
|
||||||
@ -52,7 +52,7 @@ index 190a7d8..8f53567 100644
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct export_symbol {
|
struct export_symbol {
|
||||||
@@ -284,6 +285,56 @@ static void symtab_read(struct lookup_table *table, char *path)
|
@@ -284,6 +285,57 @@ static void symtab_read(struct lookup_table *table, char *path)
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,9 +63,10 @@ index 190a7d8..8f53567 100644
|
|||||||
+ unsigned long value;
|
+ unsigned long value;
|
||||||
+ int i, j, idx;
|
+ int i, j, idx;
|
||||||
+ char line[256], name[256], type[256], mod[256];
|
+ char line[256], name[256], type[256], mod[256];
|
||||||
+ idx = 0;
|
|
||||||
+
|
+
|
||||||
+ if ((file = fopen(path, "r")) == NULL)
|
+ idx = 0;
|
||||||
|
+ file = fopen(path, "r");
|
||||||
|
+ if (file == NULL)
|
||||||
+ ERROR("fopen");
|
+ ERROR("fopen");
|
||||||
+
|
+
|
||||||
+ while (fgets(line, 256, file)) {
|
+ while (fgets(line, 256, file)) {
|
||||||
@ -109,7 +110,7 @@ index 190a7d8..8f53567 100644
|
|||||||
/*
|
/*
|
||||||
* Symvers file format is the following for kernels v5.3 and newer:
|
* Symvers file format is the following for kernels v5.3 and newer:
|
||||||
* <CRC> <Symbol> <Namespace> <Module> <Export Type>
|
* <CRC> <Symbol> <Namespace> <Module> <Export Type>
|
||||||
@@ -352,7 +403,8 @@ static void symvers_read(struct lookup_table *table, char *path)
|
@@ -352,7 +404,8 @@ static void symvers_read(struct lookup_table *table, char *path)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct lookup_table *lookup_open(char *symtab_path, char *symvers_path,
|
struct lookup_table *lookup_open(char *symtab_path, char *symvers_path,
|
||||||
@ -119,7 +120,7 @@ index 190a7d8..8f53567 100644
|
|||||||
{
|
{
|
||||||
struct lookup_table *table;
|
struct lookup_table *table;
|
||||||
|
|
||||||
@@ -363,6 +415,8 @@ struct lookup_table *lookup_open(char *symtab_path, char *symvers_path,
|
@@ -363,6 +416,8 @@ struct lookup_table *lookup_open(char *symtab_path, char *symvers_path,
|
||||||
|
|
||||||
symtab_read(table, symtab_path);
|
symtab_read(table, symtab_path);
|
||||||
symvers_read(table, symvers_path);
|
symvers_read(table, symvers_path);
|
||||||
@ -128,7 +129,7 @@ index 190a7d8..8f53567 100644
|
|||||||
find_local_syms(table, hint, locals);
|
find_local_syms(table, hint, locals);
|
||||||
|
|
||||||
return table;
|
return table;
|
||||||
@@ -603,6 +657,23 @@ int lookup_ref_symbol_offset(struct lookup_table *table, char *name,
|
@@ -609,6 +664,23 @@ int lookup_ref_symbol_offset(struct lookup_table *table, char *name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +154,7 @@ index 190a7d8..8f53567 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
diff --git a/kpatch-build/lookup.h b/kpatch-build/lookup.h
|
diff --git a/kpatch-build/lookup.h b/kpatch-build/lookup.h
|
||||||
index fed3fe9..00b6ccc 100644
|
index 6f640fd..daeea73 100644
|
||||||
--- a/kpatch-build/lookup.h
|
--- a/kpatch-build/lookup.h
|
||||||
+++ b/kpatch-build/lookup.h
|
+++ b/kpatch-build/lookup.h
|
||||||
@@ -23,7 +23,8 @@ struct lookup_refsym {
|
@@ -23,7 +23,8 @@ struct lookup_refsym {
|
||||||
@ -168,3 +169,4 @@ index fed3fe9..00b6ccc 100644
|
|||||||
struct lookup_result *result);
|
struct lookup_result *result);
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
@ -1,38 +1,49 @@
|
|||||||
From aacab0b9a2f65adfee8258515cbbb34546f3acc7 Mon Sep 17 00:00:00 2001
|
From 62e9cb43c324c933b2934ce9d2923097b96dab1e Mon Sep 17 00:00:00 2001
|
||||||
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
Date: Wed, 26 Feb 2020 20:43:34 -0500
|
Date: Wed, 26 Feb 2020 20:43:34 -0500
|
||||||
Subject: [PATCH 14/21] livepatch-patch-hook: support force enable/disable
|
Subject: [PATCH 14/23] livepatch-patch-hook: support force enable/disable
|
||||||
|
|
||||||
we use force to indicate function which bypass stack check
|
we use force to indicate function which bypass stack check
|
||||||
|
|
||||||
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
---
|
---
|
||||||
|
kmod/patch/kpatch-patch.h | 1 +
|
||||||
kmod/patch/livepatch-patch-hook.c | 18 ++++++++++++++++++
|
kmod/patch/livepatch-patch-hook.c | 18 ++++++++++++++++++
|
||||||
kpatch-build/kpatch-build | 4 ++++
|
kpatch-build/kpatch-build | 4 ++++
|
||||||
2 files changed, 22 insertions(+)
|
3 files changed, 23 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/kmod/patch/kpatch-patch.h b/kmod/patch/kpatch-patch.h
|
||||||
|
index 9df7818..6e39364 100644
|
||||||
|
--- a/kmod/patch/kpatch-patch.h
|
||||||
|
+++ b/kmod/patch/kpatch-patch.h
|
||||||
|
@@ -64,4 +64,5 @@ struct kpatch_post_unpatch_callback {
|
||||||
|
char *objname;
|
||||||
|
};
|
||||||
|
|
||||||
|
+extern unsigned long __kpatch_force_funcs[], __kpatch_force_funcs_end[];
|
||||||
|
#endif /* _KPATCH_PATCH_H_ */
|
||||||
diff --git a/kmod/patch/livepatch-patch-hook.c b/kmod/patch/livepatch-patch-hook.c
|
diff --git a/kmod/patch/livepatch-patch-hook.c b/kmod/patch/livepatch-patch-hook.c
|
||||||
index 163ae1d..7e848a7 100644
|
index fb23a94..5a0de7f 100644
|
||||||
--- a/kmod/patch/livepatch-patch-hook.c
|
--- a/kmod/patch/livepatch-patch-hook.c
|
||||||
+++ b/kmod/patch/livepatch-patch-hook.c
|
+++ b/kmod/patch/livepatch-patch-hook.c
|
||||||
@@ -238,6 +238,17 @@ extern struct kpatch_pre_patch_callback __kpatch_callbacks_pre_patch[], __kpatch
|
@@ -239,6 +239,17 @@ extern struct kpatch_post_patch_callback __kpatch_callbacks_post_patch[], __kpat
|
||||||
extern struct kpatch_post_patch_callback __kpatch_callbacks_post_patch[], __kpatch_callbacks_post_patch_end[];
|
|
||||||
extern struct kpatch_pre_unpatch_callback __kpatch_callbacks_pre_unpatch[], __kpatch_callbacks_pre_unpatch_end[];
|
extern struct kpatch_pre_unpatch_callback __kpatch_callbacks_pre_unpatch[], __kpatch_callbacks_pre_unpatch_end[];
|
||||||
extern struct kpatch_post_unpatch_callback __kpatch_callbacks_post_unpatch[], __kpatch_callbacks_post_unpatch_end[];
|
extern struct kpatch_post_unpatch_callback __kpatch_callbacks_post_unpatch[], __kpatch_callbacks_post_unpatch_end[];
|
||||||
+extern unsigned long __kpatch_force_funcs[], __kpatch_force_funcs_end[];
|
|
||||||
+
|
|
||||||
+static int patch_is_func_forced(unsigned long addr)
|
+static int patch_is_func_forced(unsigned long addr)
|
||||||
+{
|
+{
|
||||||
+ unsigned long *a;
|
+ unsigned long *a;
|
||||||
|
+
|
||||||
+ for (a = __kpatch_force_funcs; a < __kpatch_force_funcs_end; a++)
|
+ for (a = __kpatch_force_funcs; a < __kpatch_force_funcs_end; a++)
|
||||||
+ if (*a == addr)
|
+ if (*a == addr)
|
||||||
+ return 1;
|
+ return 1;
|
||||||
+ return 0;
|
+ return 0;
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
|
+
|
||||||
#ifdef HAVE_CALLBACKS
|
#ifdef HAVE_CALLBACKS
|
||||||
static int add_callbacks_to_patch_objects(void)
|
static int add_callbacks_to_patch_objects(void)
|
||||||
|
{
|
||||||
@@ -403,6 +414,13 @@ static int __init patch_init(void)
|
@@ -403,6 +414,13 @@ static int __init patch_init(void)
|
||||||
lfunc = &lfuncs[j];
|
lfunc = &lfuncs[j];
|
||||||
lfunc->old_name = func->kfunc->name;
|
lfunc->old_name = func->kfunc->name;
|
||||||
@ -64,3 +75,4 @@ index 8bef7fb..57487b1 100755
|
|||||||
fi
|
fi
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
From 4e3c6975dcd0d36509a69bbed1f200f3c49fab23 Mon Sep 17 00:00:00 2001
|
From 48fef6d7eceb336816e45690d43093f8be919315 Mon Sep 17 00:00:00 2001
|
||||||
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
Date: Wed, 26 Feb 2020 21:01:02 -0500
|
Date: Wed, 26 Feb 2020 21:01:02 -0500
|
||||||
Subject: [PATCH 15/21] kpatch-build: ignore debuginfo in patch
|
Subject: [PATCH 15/23] kpatch-build: ignore debuginfo in patch
|
||||||
|
|
||||||
Just ignore all .debug_* sections
|
Just ignore all .debug_* sections
|
||||||
|
|
||||||
@ -12,10 +12,10 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
|||||||
2 files changed, 19 insertions(+)
|
2 files changed, 19 insertions(+)
|
||||||
|
|
||||||
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
||||||
index 10d07ba..495cce1 100644
|
index c5320d4..bc3685b 100644
|
||||||
--- a/kpatch-build/create-diff-object.c
|
--- a/kpatch-build/create-diff-object.c
|
||||||
+++ b/kpatch-build/create-diff-object.c
|
+++ b/kpatch-build/create-diff-object.c
|
||||||
@@ -2409,6 +2409,23 @@ static void kpatch_include_debug_sections(struct kpatch_elf *kelf)
|
@@ -2414,6 +2414,23 @@ static void kpatch_include_debug_sections(struct kpatch_elf *kelf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,9 +39,9 @@ index 10d07ba..495cce1 100644
|
|||||||
static void kpatch_mark_ignored_sections(struct kpatch_elf *kelf)
|
static void kpatch_mark_ignored_sections(struct kpatch_elf *kelf)
|
||||||
{
|
{
|
||||||
struct section *sec, *strsec, *ignoresec;
|
struct section *sec, *strsec, *ignoresec;
|
||||||
@@ -3663,6 +3680,7 @@ int main(int argc, char *argv[])
|
@@ -3682,6 +3699,7 @@ int main(int argc, char *argv[])
|
||||||
new_globals_exist = kpatch_include_new_globals(kelf_patched);
|
new_globals_exist = kpatch_include_new_globals(kelf_patched);
|
||||||
kpatch_include_new_static_var(kelf_patched);
|
kpatch_include_new_static_var(kelf_patched);
|
||||||
kpatch_include_debug_sections(kelf_patched);
|
kpatch_include_debug_sections(kelf_patched);
|
||||||
+ kpatch_ignore_debug_sections(kelf_patched);
|
+ kpatch_ignore_debug_sections(kelf_patched);
|
||||||
|
|
||||||
@ -61,3 +61,4 @@ index 57487b1..c109ee3 100755
|
|||||||
if [[ -z "$KPATCH_LDFLAGS" ]]; then
|
if [[ -z "$KPATCH_LDFLAGS" ]]; then
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,11 @@
|
|||||||
From ea1fb4eb836033b33f08047c3a1cb74a1a458fb2 Mon Sep 17 00:00:00 2001
|
From 24392c6f62e26afb192992808772bd19ceab5446 Mon Sep 17 00:00:00 2001
|
||||||
From: Bin Yang <robin.yb@huawei.com>
|
From: Bin Yang <robin.yb@huawei.com>
|
||||||
Date: Tue, 16 Jul 2019 14:39:27 +0800
|
Date: Tue, 16 Jul 2019 14:39:27 +0800
|
||||||
Subject: [PATCH 16/21] add object in kpatch
|
Subject: [PATCH 16/23] add object in kpatch
|
||||||
|
|
||||||
|
it is required by make_hotpatch users
|
||||||
|
|
||||||
|
Signed-off-by: Bin Yang <robin.yb@huawei.com>
|
||||||
---
|
---
|
||||||
kpatch-build/kpatch-build | 3 +++
|
kpatch-build/kpatch-build | 3 +++
|
||||||
1 file changed, 3 insertions(+)
|
1 file changed, 3 insertions(+)
|
||||||
@ -30,3 +33,4 @@ index c109ee3..de448dc 100755
|
|||||||
|
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
From 9fa4a3a0a62a383e635ea7de631176a4513f6db9 Mon Sep 17 00:00:00 2001
|
From a1d89dc3ab47d443e879d4553a9ff80e8b82a3ab Mon Sep 17 00:00:00 2001
|
||||||
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
Date: Thu, 27 Feb 2020 15:36:55 -0500
|
Date: Thu, 27 Feb 2020 15:36:55 -0500
|
||||||
Subject: [PATCH 17/21] create-diff-object: fix .orc_unwind_ip error
|
Subject: [PATCH 17/23] create-diff-object: fix .orc_unwind_ip error
|
||||||
|
|
||||||
error: .orc_unwind_ip section header details
|
error: .orc_unwind_ip section header details
|
||||||
differ from .orc_unwind_ip
|
differ from .orc_unwind_ip
|
||||||
@ -14,10 +14,10 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
|||||||
1 file changed, 6 insertions(+)
|
1 file changed, 6 insertions(+)
|
||||||
|
|
||||||
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
||||||
index 495cce1..45979d6 100644
|
index bc3685b..20213a0 100644
|
||||||
--- a/kpatch-build/create-diff-object.c
|
--- a/kpatch-build/create-diff-object.c
|
||||||
+++ b/kpatch-build/create-diff-object.c
|
+++ b/kpatch-build/create-diff-object.c
|
||||||
@@ -972,6 +972,9 @@ static void kpatch_correlate_sections(struct list_head *seclist1, struct list_he
|
@@ -975,6 +975,9 @@ static void kpatch_correlate_sections(struct list_head *seclist1, struct list_he
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ index 495cce1..45979d6 100644
|
|||||||
kpatch_correlate_section(sec1, sec2);
|
kpatch_correlate_section(sec1, sec2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1017,6 +1020,9 @@ static void kpatch_correlate_symbols(struct list_head *symlist1, struct list_hea
|
@@ -1020,6 +1023,9 @@ static void kpatch_correlate_symbols(struct list_head *symlist1, struct list_hea
|
||||||
sym1->sec->twin != sym2->sec)
|
sym1->sec->twin != sym2->sec)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -39,3 +39,4 @@ index 495cce1..45979d6 100644
|
|||||||
}
|
}
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
From 7c7f582a9b051c4570a00f215f5534ff0fdfd9a0 Mon Sep 17 00:00:00 2001
|
From f162056f0448e676345e3205ef4b190f81b51295 Mon Sep 17 00:00:00 2001
|
||||||
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
Date: Thu, 12 Mar 2020 05:10:55 -0400
|
Date: Thu, 12 Mar 2020 05:10:55 -0400
|
||||||
Subject: [PATCH 18/21] use orignal reloc for symbols from modules
|
Subject: [PATCH 18/23] use original reloc for symbols from modules
|
||||||
|
|
||||||
symbols exported in a patch will generate a symbol version with
|
symbols exported in a patch will generate a symbol version with
|
||||||
object module name in Module.symvers, but the symbol is actually
|
object module name in Module.symvers, but the symbol is actually
|
||||||
@ -13,10 +13,10 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
|||||||
1 file changed, 1 insertion(+), 3 deletions(-)
|
1 file changed, 1 insertion(+), 3 deletions(-)
|
||||||
|
|
||||||
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
||||||
index 45979d6..7d24c7e 100644
|
index 20213a0..457d517 100644
|
||||||
--- a/kpatch-build/create-diff-object.c
|
--- a/kpatch-build/create-diff-object.c
|
||||||
+++ b/kpatch-build/create-diff-object.c
|
+++ b/kpatch-build/create-diff-object.c
|
||||||
@@ -3131,10 +3131,8 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
@@ -3141,10 +3141,8 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
||||||
if (!strcmp(sym_objname, "vmlinux"))
|
if (!strcmp(sym_objname, "vmlinux"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -24,9 +24,10 @@ index 45979d6..7d24c7e 100644
|
|||||||
- continue;
|
- continue;
|
||||||
-
|
-
|
||||||
external = 1;
|
external = 1;
|
||||||
+ continue;
|
+ continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log_debug("lookup for %s @ 0x%016lx len %lu\n",
|
log_debug("lookup for %s @ 0x%016lx len %lu\n",
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
@ -1,7 +1,7 @@
|
|||||||
From 9233e07a0dfdb3eceb44093feb2e5928a9e391d9 Mon Sep 17 00:00:00 2001
|
From c0b20224cf1b081fba152cb4944d762515561d89 Mon Sep 17 00:00:00 2001
|
||||||
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
Date: Mon, 2 Mar 2020 04:35:07 -0500
|
Date: Mon, 2 Mar 2020 04:35:07 -0500
|
||||||
Subject: [PATCH 19/21] create-diff-object: add jump label support
|
Subject: [PATCH 19/23] create-diff-object: add jump label support
|
||||||
|
|
||||||
This patch processes the __jump_table special section, and
|
This patch processes the __jump_table special section, and
|
||||||
only the jump_lable used by the changed functions will be
|
only the jump_lable used by the changed functions will be
|
||||||
@ -15,10 +15,10 @@ Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
|||||||
1 file changed, 1 insertion(+), 46 deletions(-)
|
1 file changed, 1 insertion(+), 46 deletions(-)
|
||||||
|
|
||||||
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
||||||
index 7d24c7e..448911b 100644
|
index 457d517..4fa4488 100644
|
||||||
--- a/kpatch-build/create-diff-object.c
|
--- a/kpatch-build/create-diff-object.c
|
||||||
+++ b/kpatch-build/create-diff-object.c
|
+++ b/kpatch-build/create-diff-object.c
|
||||||
@@ -2135,7 +2135,6 @@ static void kpatch_regenerate_special_section(struct kpatch_elf *kelf,
|
@@ -2140,7 +2140,6 @@ static void kpatch_regenerate_special_section(struct kpatch_elf *kelf,
|
||||||
struct rela *rela, *safe;
|
struct rela *rela, *safe;
|
||||||
char *src, *dest;
|
char *src, *dest;
|
||||||
unsigned int group_size, src_offset, dest_offset, include;
|
unsigned int group_size, src_offset, dest_offset, include;
|
||||||
@ -26,7 +26,7 @@ index 7d24c7e..448911b 100644
|
|||||||
|
|
||||||
LIST_HEAD(newrelas);
|
LIST_HEAD(newrelas);
|
||||||
|
|
||||||
@@ -2175,49 +2174,6 @@ static void kpatch_regenerate_special_section(struct kpatch_elf *kelf,
|
@@ -2180,49 +2179,6 @@ static void kpatch_regenerate_special_section(struct kpatch_elf *kelf,
|
||||||
if (!include)
|
if (!include)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ index 7d24c7e..448911b 100644
|
|||||||
/*
|
/*
|
||||||
* Copy all relas in the group. It's possible that the relas
|
* Copy all relas in the group. It's possible that the relas
|
||||||
* aren't sorted (e.g. .rela.fixup), so go through the entire
|
* aren't sorted (e.g. .rela.fixup), so go through the entire
|
||||||
@@ -2654,8 +2610,7 @@ static void kpatch_process_special_sections(struct kpatch_elf *kelf)
|
@@ -2659,8 +2615,7 @@ static void kpatch_process_special_sections(struct kpatch_elf *kelf)
|
||||||
* jump labels and enable tracepoints in a patched function.
|
* jump labels and enable tracepoints in a patched function.
|
||||||
*/
|
*/
|
||||||
list_for_each_entry(sec, &kelf->sections, list) {
|
list_for_each_entry(sec, &kelf->sections, list) {
|
||||||
@ -88,3 +88,4 @@ index 7d24c7e..448911b 100644
|
|||||||
continue;
|
continue;
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
From da47ad5e439e9ba9422cac2ade847463bc8578ee Mon Sep 17 00:00:00 2001
|
From 586dcb3d2ccd8e45c78d3d140f0190ab5a78ecb3 Mon Sep 17 00:00:00 2001
|
||||||
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
Date: Thu, 12 Mar 2020 06:56:21 -0400
|
Date: Thu, 12 Mar 2020 06:56:21 -0400
|
||||||
Subject: [PATCH 20/21] kpatch-build: add compile flag -fno-reorder-functions
|
Subject: [PATCH 20/23] kpatch-build: add compile flag -fno-reorder-functions
|
||||||
|
|
||||||
Sometimes function foo with static variables can be put in
|
Sometimes function foo with static variables can be put in
|
||||||
.text.foo section in original binary and be put in
|
.text.foo section in original binary and be put in
|
||||||
@ -37,3 +37,4 @@ index de448dc..ad7ab71 100755
|
|||||||
echo "Reading special section data"
|
echo "Reading special section data"
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
From b05aaaf13978393f8e9c2329a80765c0069e7e87 Mon Sep 17 00:00:00 2001
|
From cff73a8dca7069d9e558c65f0b76297feab09719 Mon Sep 17 00:00:00 2001
|
||||||
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
Date: Thu, 12 Mar 2020 07:37:00 -0400
|
Date: Thu, 12 Mar 2020 07:37:00 -0400
|
||||||
Subject: [PATCH 21/21] kpatch-build: don't copy .config for out of tree module
|
Subject: [PATCH 21/23] kpatch-build: don't copy .config for out of tree module
|
||||||
|
|
||||||
|
.config only need to be restored when the build patch for kernel
|
||||||
|
|
||||||
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
---
|
---
|
||||||
@ -23,3 +25,4 @@ index ad7ab71..fd34812 100755
|
|||||||
# according to .config and kernel version
|
# according to .config and kernel version
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
From 4cad4a9ec87736e938ccd13b62c5ef8e595a591e Mon Sep 17 00:00:00 2001
|
From 11e57aa03ae87fa24028800851f34205a2aeb0d8 Mon Sep 17 00:00:00 2001
|
||||||
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
Date: Wed, 15 Apr 2020 06:37:59 -0400
|
Date: Wed, 15 Apr 2020 06:37:59 -0400
|
||||||
Subject: [PATCH 22/22] support force enable/disable for x86
|
Subject: [PATCH 22/23] support force enable/disable for x86
|
||||||
|
|
||||||
detect if the klp_func structure in vmlinux have force
|
detect if the klp_func structure in vmlinux have force
|
||||||
member, if it has, export KLP_SUPPORT_FORCE=y.
|
member, if it has, export KLP_SUPPORT_FORCE=y.
|
||||||
@ -55,3 +55,4 @@ index fd34812..523d5df 100755
|
|||||||
|
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
@ -1,49 +1,57 @@
|
|||||||
From 50401005b1a16b93307390983dd61f480492d495 Mon Sep 17 00:00:00 2001
|
From 459018cfabc65e9f29bf25476c727b4d5d8089c4 Mon Sep 17 00:00:00 2001
|
||||||
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
Date: Wed, 22 Apr 2020 05:55:33 -0400
|
Date: Wed, 22 Apr 2020 05:55:33 -0400
|
||||||
Subject: [PATCH] create-diff-object: fix duplicate symbols for vmlinux
|
Subject: [PATCH 23/23] create-diff-object: fix duplicate symbols for vmlinux
|
||||||
|
|
||||||
symbol pos in vmlinux may be different with runtime
|
symbol pos in vmlinux may be different with runtime
|
||||||
/proc/kallsyms, use ref_name and ref_offset method too.
|
/proc/kallsyms, use ref_name and ref_offset method too.
|
||||||
|
|
||||||
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
||||||
---
|
---
|
||||||
kpatch-build/create-diff-object.c | 28 +++++++++++++++-------------
|
kpatch-build/create-diff-object.c | 36 ++++++++++++++++---------------
|
||||||
1 file changed, 15 insertions(+), 13 deletions(-)
|
1 file changed, 19 insertions(+), 17 deletions(-)
|
||||||
|
|
||||||
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
||||||
index 2b1ee36..c0c8106 100644
|
index 4fa4488..ad5746b 100644
|
||||||
--- a/kpatch-build/create-diff-object.c
|
--- a/kpatch-build/create-diff-object.c
|
||||||
+++ b/kpatch-build/create-diff-object.c
|
+++ b/kpatch-build/create-diff-object.c
|
||||||
@@ -3100,21 +3100,23 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
@@ -3110,25 +3110,27 @@ static void kpatch_create_intermediate_sections(struct kpatch_elf *kelf,
|
||||||
else {
|
else {
|
||||||
/* for modules, src is discovered at runtime */
|
/* for modules, src is discovered at runtime */
|
||||||
ksyms[index].src = 0;
|
ksyms[index].src = 0;
|
||||||
- if (lookup_is_duplicate_symbol(table, rela->sym->name, objname, result.pos)) {
|
- if (lookup_is_duplicate_symbol(table, rela->sym->name, objname,
|
||||||
|
- result.pos)) {
|
||||||
- struct lookup_refsym refsym;
|
- struct lookup_refsym refsym;
|
||||||
-
|
-
|
||||||
- if (lookup_ref_symbol_offset(table, rela->sym->name, &refsym, objname, &ref_offset))
|
- if (lookup_ref_symbol_offset(table, rela->sym->name,
|
||||||
- ERROR("unresolvable ambiguity on symbol %s\n", rela->sym->name);
|
- &refsym, objname, &ref_offset))
|
||||||
|
- ERROR("unresolvable ambiguity on symbol %s\n",
|
||||||
|
- rela->sym->name);
|
||||||
-
|
-
|
||||||
- /* add rela to fill in ref_name field */
|
- /* add rela to fill in ref_name field */
|
||||||
- ALLOC_LINK(rela2, &krela_sec->rela->relas);
|
- ALLOC_LINK(rela2, &krela_sec->rela->relas);
|
||||||
- rela2->sym = strsym;
|
- rela2->sym = strsym;
|
||||||
- rela2->type = absolute_rela_type;
|
- rela2->type = absolute_rela_type;
|
||||||
- rela2->addend = offset_of_string(&kelf->strings, refsym.name);
|
- rela2->addend = offset_of_string(&kelf->strings,
|
||||||
|
- refsym.name);
|
||||||
- rela2->offset = (unsigned int)(index * sizeof(*krelas) +
|
- rela2->offset = (unsigned int)(index * sizeof(*krelas) +
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ if (lookup_is_duplicate_symbol(table, rela->sym->name, objname, result.pos)) {
|
+ if (lookup_is_duplicate_symbol(table, rela->sym->name, objname,
|
||||||
|
+ result.pos)) {
|
||||||
+ struct lookup_refsym refsym;
|
+ struct lookup_refsym refsym;
|
||||||
+
|
+
|
||||||
+ if (lookup_ref_symbol_offset(table, rela->sym->name, &refsym, objname, &ref_offset))
|
+ if (lookup_ref_symbol_offset(table, rela->sym->name,
|
||||||
+ ERROR("unresolvable ambiguity on symbol %s\n", rela->sym->name);
|
+ &refsym, objname, &ref_offset))
|
||||||
|
+ ERROR("unresolvable ambiguity on symbol %s\n",
|
||||||
|
+ rela->sym->name);
|
||||||
+
|
+
|
||||||
+ /* add rela to fill in ref_name field */
|
+ /* add rela to fill in ref_name field */
|
||||||
+ ALLOC_LINK(rela2, &krela_sec->rela->relas);
|
+ ALLOC_LINK(rela2, &krela_sec->rela->relas);
|
||||||
+ rela2->sym = strsym;
|
+ rela2->sym = strsym;
|
||||||
+ rela2->type = absolute_rela_type;
|
+ rela2->type = absolute_rela_type;
|
||||||
+ rela2->addend = offset_of_string(&kelf->strings, refsym.name);
|
+ rela2->addend = offset_of_string(&kelf->strings,
|
||||||
|
+ refsym.name);
|
||||||
+ rela2->offset = (unsigned int)(index * sizeof(*krelas) +
|
+ rela2->offset = (unsigned int)(index * sizeof(*krelas) +
|
||||||
offsetof(struct kpatch_relocation, ref_name));
|
offsetof(struct kpatch_relocation, ref_name));
|
||||||
- }
|
- }
|
||||||
@ -54,3 +62,4 @@ index 2b1ee36..c0c8106 100644
|
|||||||
ksyms[index].bind = rela->sym->bind;
|
ksyms[index].bind = rela->sym->bind;
|
||||||
--
|
--
|
||||||
2.18.1
|
2.18.1
|
||||||
|
|
||||||
|
|||||||
10
kpatch.spec
10
kpatch.spec
@ -3,7 +3,7 @@
|
|||||||
Name: kpatch
|
Name: kpatch
|
||||||
Epoch: 1
|
Epoch: 1
|
||||||
Version: %{raw_version}
|
Version: %{raw_version}
|
||||||
Release: 3
|
Release: 4
|
||||||
Summary: A Linux dynamic kernel patching infrastructure
|
Summary: A Linux dynamic kernel patching infrastructure
|
||||||
|
|
||||||
License: GPLv2
|
License: GPLv2
|
||||||
@ -31,7 +31,7 @@ Patch0014:0014-livepatch-patch-hook-support-force-enable-disable.patch
|
|||||||
Patch0015:0015-kpatch-build-ignore-debuginfo-in-patch.patch
|
Patch0015:0015-kpatch-build-ignore-debuginfo-in-patch.patch
|
||||||
Patch0016:0016-add-object-in-kpatch.patch
|
Patch0016:0016-add-object-in-kpatch.patch
|
||||||
Patch0017:0017-create-diff-object-fix-.orc_unwind_ip-error.patch
|
Patch0017:0017-create-diff-object-fix-.orc_unwind_ip-error.patch
|
||||||
Patch0018:0018-use-orignal-reloc-for-symbols-from-modules.patch
|
Patch0018:0018-use-original-reloc-for-symbols-from-modules.patch
|
||||||
Patch0019:0019-create-diff-object-add-jump-label-support.patch
|
Patch0019:0019-create-diff-object-add-jump-label-support.patch
|
||||||
Patch0020:0020-kpatch-build-add-compile-flag-fno-reorder-functions.patch
|
Patch0020:0020-kpatch-build-add-compile-flag-fno-reorder-functions.patch
|
||||||
Patch0021:0021-kpatch-build-don-t-copy-.config-for-out-of-tree-modu.patch
|
Patch0021:0021-kpatch-build-don-t-copy-.config-for-out-of-tree-modu.patch
|
||||||
@ -95,6 +95,12 @@ popd
|
|||||||
%{_mandir}/man1/*.1.gz
|
%{_mandir}/man1/*.1.gz
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Sat Sep 12 2020 Zhipeng Xie<xiezhipeng1@huawei.com> -1:0.9.1-4
|
||||||
|
- Type:enhancement
|
||||||
|
- ID:NA
|
||||||
|
- SUG:NA
|
||||||
|
- DESC:code optimization
|
||||||
|
|
||||||
* Sat Aug 29 2020 Yeqing Peng<pengyeqing@huawei.com> -1:0.9.1-3
|
* Sat Aug 29 2020 Yeqing Peng<pengyeqing@huawei.com> -1:0.9.1-3
|
||||||
- Type:bugfix
|
- Type:bugfix
|
||||||
- ID:NA
|
- ID:NA
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user