On Wed, Sep 04, 2024 at 01:59:51PM -0700, Josh Poimboeuf wrote:
> On Wed, Sep 04, 2024 at 01:23:55PM -0700, Song Liu wrote:
> > [ 7285.260195] livepatch: nothing to patch!

This seems to be tripping up on an awful hack I had for silencing
modpost warnings.  Apparently it doesn't work with your config.

Try the below.  You can ignore the modpost warnings for now:

  WARNING: modpost: "__stop_klp_objects" 
[/home/jpoimboe/git/linux/klp-tmp/out/livepatch.ko] undefined!
  WARNING: modpost: "__start_klp_objects" 
[/home/jpoimboe/git/linux/klp-tmp/out/livepatch.ko] undefined!

diff --git a/scripts/livepatch/module.c b/scripts/livepatch/module.c
index 101cabf6b2f1..7e4a8477231f 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;

Reply via email to