12 Star 6 Fork 44

src-openEuler/kpatch

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0019-support-remove-static-variables-using-KPATCH_IGNORE_.patch 3.77 KB
一键复制 编辑 原始数据 按行查看 历史
HuBin95 提交于 2024-03-02 00:18 . kpatch: upgrade to 0.9.9
From bd30bf1f72ec04f272554b3a7074506c6f3af637 Mon Sep 17 00:00:00 2001
From: Zhipeng Xie <xiezhipeng1@huawei.com>
Date: Wed, 30 Dec 2020 21:13:10 -0500
Subject: [PATCH 19/38] support remove static variables using
KPATCH_IGNORE_STATIC
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>
---
kmod/patch/kpatch-macros.h | 4 +++
kpatch-build/create-diff-object.c | 45 ++++++++++++++++++++++++++++++-
2 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/kmod/patch/kpatch-macros.h b/kmod/patch/kpatch-macros.h
index b797838..69fdbbb 100644
--- a/kmod/patch/kpatch-macros.h
+++ b/kmod/patch/kpatch-macros.h
@@ -13,6 +13,10 @@
# define __kpatch_section(section) __section(#section)
#endif
+#define KPATCH_IGNORE_STATIC(_static) \
+ char *__UNIQUE_ID(kpatch_ignore_static_) __section(.kpatch.ignore.statics) = _static;
+
+
/*
* KPATCH_IGNORE_SECTION macro
*
diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 8c1b8ad..83836f6 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -1369,6 +1369,40 @@ static struct rela *kpatch_find_static_twin_ref(struct section *relasec,
return NULL;
}
+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
@@ -1449,6 +1483,11 @@ static void kpatch_correlate_static_local_variables(struct kpatch_elf *orig,
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;
if (bundled && sym->sec == relasec->base) {
/*
@@ -1506,6 +1545,11 @@ static void kpatch_correlate_static_local_variables(struct kpatch_elf *orig,
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;
+ }
+
if (!relasec->twin && relasec->base->sym) {
struct symbol *parent = NULL;
@@ -1549,7 +1593,6 @@ static void kpatch_correlate_static_local_variables(struct kpatch_elf *orig,
log_normal("WARNING: unable to correlate static local variable %s used by %s, assuming variable is new\n",
sym->name,
kpatch_section_function_name(relasec));
- return;
}
}
}
--
2.33.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/kpatch.git
git@gitee.com:src-openeuler/kpatch.git
src-openeuler
kpatch
kpatch
master

搜索帮助