Re: [RFC 00/31] objtool, livepatch: Livepatch module generation
From: Josh Poimboeuf
Date: Thu Sep 05 2024 - 03:14:02 EST
On Wed, Sep 04, 2024 at 09:14:00PM -0700, Josh Poimboeuf wrote:
> + if (!!nr_objs) {
^^
oops
Fixed version:
diff --git a/scripts/livepatch/module.c b/scripts/livepatch/module.c
index 101cabf6b2f1..2908999efa21 100644
--- a/scripts/livepatch/module.c
+++ b/scripts/livepatch/module.c
@@ -14,16 +14,13 @@
// TODO livepatch could recognize these sections directly
// TODO use function checksums instead of sympos
-extern char __start_klp_objects, __stop_klp_objects;
/*
* Create weak versions of the linker-created symbols to prevent modpost from
* warning about unresolved symbols.
*/
-__weak char __start_klp_objects = 0;
-__weak char __stop_klp_objects = 0;
-struct klp_object_ext *__start_objs = (struct klp_object_ext *)&__start_klp_objects;
-struct klp_object_ext *__stop_objs = (struct klp_object_ext *)&__stop_klp_objects;
+extern struct klp_object_ext __start_klp_objects[];
+extern struct klp_object_ext __stop_klp_objects[];
static struct klp_patch *patch;
@@ -33,9 +30,9 @@ static int __init livepatch_mod_init(void)
unsigned int nr_objs;
int ret;
- nr_objs = __stop_objs - __start_objs;
+ nr_objs = __stop_klp_objects - __start_klp_objects;
- if (!__start_klp_objects || !nr_objs) {
+ if (!nr_objs) {
pr_err("nothing to patch!\n");
ret = -EINVAL;
goto err;
@@ -54,7 +51,7 @@ static int __init livepatch_mod_init(void)
}
for (int i = 0; i < nr_objs; i++) {
- struct klp_object_ext *obj_ext = __start_objs + i;
+ struct klp_object_ext *obj_ext = __start_klp_objects;
struct klp_func_ext *funcs_ext = obj_ext->funcs;
unsigned int nr_funcs = obj_ext->nr_funcs;
struct klp_func *funcs = objs[i].funcs;
@@ -105,7 +102,7 @@ static void __exit livepatch_mod_exit(void)
{
unsigned int nr_objs;
- nr_objs = __stop_objs - __start_objs;
+ nr_objs = __stop_klp_objects - __start_klp_objects;
for (int i = 0; i < nr_objs; i++)
kfree(patch->objs[i].funcs);
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index f48d72d22dc2..20d0f03025b3 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1739,7 +1739,7 @@ static void check_exports(struct module *mod)
exp = find_symbol(s->name);
if (!exp) {
if (!s->weak && nr_unresolved++ < MAX_UNRESOLVED_REPORTS)
- modpost_log(warn_unresolved ? LOG_WARN : LOG_ERROR,
+ modpost_log(LOG_WARN,
"\"%s\" [%s.ko] undefined!\n",
s->name, mod->name);
continue;