2023-01-30 16:10:43 +08:00
|
|
|
From fbf50da80b82c2749a76181f6bd76c9ee8d2539c Mon Sep 17 00:00:00 2001
|
2020-12-30 21:16:01 -05:00
|
|
|
From: Zhipeng Xie <xiezhipeng1@huawei.com>
|
|
|
|
|
Date: Wed, 30 Dec 2020 21:13:10 -0500
|
2023-01-30 16:10:43 +08:00
|
|
|
Subject: [PATCH 19/37] support remove static variables using
|
2021-11-16 12:10:06 +08:00
|
|
|
KPATCH_IGNORE_STATIC
|
2020-12-30 21:16:01 -05:00
|
|
|
|
|
|
|
|
Static variables will be removed due to compiler optimization.
|
|
|
|
|
And some static variables can be treated as new variables, such as
|
|
|
|
|
static variables in print limit macros. So add KPATCH_IGNORE_STATIC
|
|
|
|
|
to tell kpatch to treat the static variables as new variables.
|
|
|
|
|
|
|
|
|
|
Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
|
|
|
|
|
---
|
2021-11-16 12:10:06 +08:00
|
|
|
kmod/patch/kpatch-macros.h | 4 +++
|
2020-12-30 21:16:01 -05:00
|
|
|
kpatch-build/create-diff-object.c | 45 ++++++++++++++++++++++++++++++-
|
2021-11-16 12:10:06 +08:00
|
|
|
2 files changed, 48 insertions(+), 1 deletion(-)
|
2020-12-30 21:16:01 -05:00
|
|
|
|
|
|
|
|
diff --git a/kmod/patch/kpatch-macros.h b/kmod/patch/kpatch-macros.h
|
2023-01-30 16:10:43 +08:00
|
|
|
index 8e09702..02d548e 100644
|
2020-12-30 21:16:01 -05:00
|
|
|
--- a/kmod/patch/kpatch-macros.h
|
|
|
|
|
+++ b/kmod/patch/kpatch-macros.h
|
2023-01-30 16:10:43 +08:00
|
|
|
@@ -13,6 +13,10 @@
|
2021-11-16 12:10:06 +08:00
|
|
|
# define __kpatch_section(section) __section(#section)
|
|
|
|
|
#endif
|
2020-12-30 21:16:01 -05:00
|
|
|
|
|
|
|
|
+#define KPATCH_IGNORE_STATIC(_static) \
|
|
|
|
|
+ char *__UNIQUE_ID(kpatch_ignore_static_) __section(.kpatch.ignore.statics) = _static;
|
2021-11-16 12:10:06 +08:00
|
|
|
+
|
2020-12-30 21:16:01 -05:00
|
|
|
+
|
|
|
|
|
/*
|
|
|
|
|
* KPATCH_IGNORE_SECTION macro
|
|
|
|
|
*
|
|
|
|
|
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
|
2023-01-30 16:10:43 +08:00
|
|
|
index 2510620..c90b30a 100644
|
2020-12-30 21:16:01 -05:00
|
|
|
--- a/kpatch-build/create-diff-object.c
|
|
|
|
|
+++ b/kpatch-build/create-diff-object.c
|
2023-01-30 16:10:43 +08:00
|
|
|
@@ -1319,6 +1319,40 @@ static struct rela *kpatch_find_static_twin_ref(struct section *relasec,
|
2021-11-16 12:10:06 +08:00
|
|
|
return NULL;
|
2020-12-30 21:16:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+static int kpatch_mark_ignored_statics(struct kpatch_elf *kelf, struct symbol *sym)
|
|
|
|
|
+{
|
|
|
|
|
+ struct section *sec, *strsec;
|
|
|
|
|
+ struct rela *rela;
|
|
|
|
|
+ char *name;
|
|
|
|
|
+
|
|
|
|
|
+ sec = find_section_by_name(&kelf->sections, ".kpatch.ignore.statics");
|
|
|
|
|
+ if (!sec)
|
|
|
|
|
+ return 0;
|
|
|
|
|
+
|
|
|
|
|
+ list_for_each_entry(rela, &sec->rela->relas, list) {
|
|
|
|
|
+ strsec = rela->sym->sec;
|
|
|
|
|
+ strsec->status = CHANGED;
|
|
|
|
|
+ /*
|
|
|
|
|
+ * Include the string section here. This is because the
|
|
|
|
|
+ * KPATCH_IGNORE_STATIC() macro is passed a literal string
|
|
|
|
|
+ * by the patch author, resulting in a change to the string
|
|
|
|
|
+ * section. If we don't include it, then we will potentially
|
|
|
|
|
+ * get a "changed section not included" error in
|
|
|
|
|
+ * kpatch_verify_patchability() if no other function based change
|
|
|
|
|
+ * also changes the string section. We could try to exclude each
|
|
|
|
|
+ * literal string added to the section by KPATCH_IGNORE_STATIC()
|
|
|
|
|
+ * from the section data comparison, but this is a simpler way.
|
|
|
|
|
+ */
|
|
|
|
|
+ strsec->include = 1;
|
|
|
|
|
+ strsec->secsym->include = 1;
|
|
|
|
|
+ name = strsec->data->d_buf + rela->addend;
|
|
|
|
|
+ if (!strncmp(name, sym->name, strlen(name)))
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return 0;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
/*
|
|
|
|
|
* gcc renames static local variables by appending a period and a number. For
|
|
|
|
|
* example, __foo could be renamed to __foo.31452. Unfortunately this number
|
2023-01-30 16:10:43 +08:00
|
|
|
@@ -1399,6 +1433,11 @@ static void kpatch_correlate_static_local_variables(struct kpatch_elf *orig,
|
2020-12-30 21:16:01 -05:00
|
|
|
if (sym->twin)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
+ if (kpatch_mark_ignored_statics(patched, sym)) {
|
|
|
|
|
+ log_normal("KPATCH_IGNORE_STATIC:ignore static variable %s\n", sym->name);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
bundled = sym == sym->sec->sym;
|
2023-01-30 16:10:43 +08:00
|
|
|
if (bundled && sym->sec == relasec->base) {
|
2020-12-30 21:16:01 -05:00
|
|
|
/*
|
2023-01-30 16:10:43 +08:00
|
|
|
@@ -1456,6 +1495,11 @@ static void kpatch_correlate_static_local_variables(struct kpatch_elf *orig,
|
2020-12-30 21:16:01 -05:00
|
|
|
if (!kpatch_is_normal_static_local(sym))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
+ if (kpatch_mark_ignored_statics(patched, sym)) {
|
|
|
|
|
+ log_normal("KPATCH_IGNORE_STATIC:ignore static variable %s\n", sym->name);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
2023-01-30 16:10:43 +08:00
|
|
|
if (!relasec->twin && relasec->base->sym) {
|
2021-11-16 12:10:06 +08:00
|
|
|
struct symbol *parent = NULL;
|
|
|
|
|
|
2023-01-30 16:10:43 +08:00
|
|
|
@@ -1499,7 +1543,6 @@ static void kpatch_correlate_static_local_variables(struct kpatch_elf *orig,
|
2020-12-30 21:16:01 -05:00
|
|
|
log_normal("WARNING: unable to correlate static local variable %s used by %s, assuming variable is new\n",
|
|
|
|
|
sym->name,
|
2023-01-30 16:10:43 +08:00
|
|
|
kpatch_section_function_name(relasec));
|
2020-12-30 21:16:01 -05:00
|
|
|
- return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
--
|
2023-01-30 16:10:43 +08:00
|
|
|
2.33.0
|
2020-12-30 21:16:01 -05:00
|
|
|
|