modules: Fix build error in moduleloader.h
PATCH 1/1 modules: Fix build error in moduleloader.h
Fengguang Wu's build bot detected that if moduleloader.h is included in a C file (used by ftrace and kprobes to access module_alloc() when available), that it can fail to build if CONFIG_MODULES and CONFIG_MODULES_USE_ELF_REL is not defined.
This is because there's a printk() that dereferences struct module to print the name of the module. But as struct module does not exist when CONFIG_MODULES is not defined we get this error:
include/linux/moduleloader.h: In function 'apply_relocate':
Quoted 1 line
Quoted 1 line
include/linux/moduleloader.h:48:63: error: dereferencing pointer to incomplete type
printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
^Avoid the printk if CONFIG_MODULES is not set.
---
include/linux/moduleloader.h +3 -0
@@ -45,7 +45,10 @@ static inline int apply_relocate(Elf_Shdr *sechdrs, unsigned int relsec, struct module *me) { +/* me->name only exists if modules are enabled */ +#ifdef CONFIG_MODULES printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name); +#endif return -ENOEXEC ; }#endif
Quoted 9 lines · Steven Rostedt
Fengguang Wu's build bot detected that if
moduleloader.his included in a C file (used by ftrace and kprobes to accessmodule_alloc()when available), that it can fail to build ifCONFIG_MODULESandCONFIG_MODULES_USE_ELF_RELis not defined.This is because there's a
printk()that dereferences struct module to print the name of the module. But as struct module does not exist whenCONFIG_MODULESis not defined we get this error:
Quoted 5 lines
include/linux/moduleloader.h: In function 'apply_relocate':Quoted 1 line
Quoted 1 line
include/linux/moduleloader.h:48:63: error: dereferencing pointer to incomplete typeprintk(KERN_ERR "module %s: REL relocation unsupported\n", me->name); ^Avoid the printk if
CONFIG_MODULESis not set.
Looks OK to me. BTW, CONFIG_KPROBES depends on CONFIG_MODULES, so currently kprobes itself doesn't hit that problem.
Thank you, :)
Quoted 20 lines
Reported-by kbuild test robot <[email protected]>Signed-off-by Steven Rostedt <[email protected]>---
include/linux/moduleloader.h +3
-0@@ -45,7 +45,10 @@ static inline int apply_relocate(Elf_Shdr *sechdrs, unsigned int relsec, struct module *me) { +/* me->name only exists if modules are enabled */ +#ifdef CONFIG_MODULES printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name); +#endif return -ENOEXEC ; }#endif
Signature · 4 lines
Masami HIRAMATSU Software Platform Research Dept. Linux Technology Research Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
Quoted 8 lines · Steven Rostedt
Fengguang Wu's build bot detected that if
moduleloader.his included in a C file (used by ftrace and kprobes to accessmodule_alloc()when available), that it can fail to build ifCONFIG_MODULESandCONFIG_MODULES_USE_ELF_RELis not defined.This is because there's a
printk()that dereferences struct module to print the name of the module. But as struct module does not exist whenCONFIG_MODULESis not defined we get this error:
First, we have module_name() for exactly this.
Second, there are two places like this: you hit CONFIG_MODULES_USE_ELF_REL and not CONFIG_MODULES_USE_ELF_RELA.
(We could uninline them, and put them in module.c, but I think having them in the header is nice and self-documenting.)
So does this work for you?
Thanks,
Rusty.
PS. Masami Hiramatsu, your review should have caught the second case,
at least :(
Subject: modules: Fix build error in moduleloader.h
Fengguang Wu's build bot detected that if moduleloader.h is included in a C file (used by ftrace and kprobes to access module_alloc() when available), that it can fail to build if CONFIG_MODULES and CONFIG_MODULES_USE_ELF_REL is not defined.
This is because there's a printk() that dereferences struct module to print the name of the module. But as struct module does not exist when CONFIG_MODULES is not defined we get this error:
include/linux/moduleloader.h: In function 'apply_relocate':
Quoted 2 lines
Quoted 2 lines
include/linux/moduleloader.h:48:63: error: dereferencing pointer to incomplete type
printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name); ^
include/linux/moduleloader.h +4 -2
@@ -45,7 +45,8 @@ static inline int apply_relocate(Elf_Shdr *sechdrs, unsigned int relsec, struct module *me) { - printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name); + printk(KERN_ERR "module %s: REL relocation unsupported\n", + module_name(me));return -ENOEXEC ; }#endif
@@ -67,7 +68,8 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs, unsigned int relsec, struct module *me) { - printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name); + printk(KERN_ERR "module %s: REL relocation unsupported\n", + module_name(me));return -ENOEXEC ; }#endif
Quoted 18 lines · Rusty Russell
Quoted 8 lines · Steven Rostedt
Fengguang Wu's build bot detected that if
moduleloader.his included in a C file (used by ftrace and kprobes to accessmodule_alloc()when available), that it can fail to build ifCONFIG_MODULESandCONFIG_MODULES_USE_ELF_RELis not defined.This is because there's a
printk()that dereferences struct module to print the name of the module. But as struct module does not exist whenCONFIG_MODULESis not defined we get this error:First, we have
module_name()for exactly this.Second, there are two places like this: you hit
CONFIG_MODULES_USE_ELF_RELand notCONFIG_MODULES_USE_ELF_RELA.(We could uninline them, and put them in
module.c, but I think having them in the header is nice and self-documenting.)
Quoted 6 lines
So does this work for you?
Thanks,
Rusty.
PS. Masami Hiramatsu, your review should have caught the second case,at least :(
Oops, sorry, I missed the second one ... and this version seems good to me.
Thank you,
Quoted 46 lines
Subject: modules: Fix build error in
moduleloader.hFengguang Wu's build bot detected that if
moduleloader.his included in a C file (used by ftrace and kprobes to accessmodule_alloc()when available), that it can fail to build ifCONFIG_MODULESandCONFIG_MODULES_USE_ELF_RELis not defined.This is because there's a
printk()that dereferences struct module to print the name of the module. But as struct module does not exist whenCONFIG_MODULESis not defined we get this error:
include/linux/moduleloader.h: In function 'apply_relocate':Quoted 2 lines
Quoted 2 lines
include/linux/moduleloader.h:48:63: error: dereferencing pointer to incomplete typeprintk(KERN_ERR "module %s: REL relocation unsupported\n", me->name); ^Reported-by kbuild test robot <[email protected]>Based-on-the-true-story-by Steven Rostedt <[email protected]>Signed-off-by Rusty Russell <[email protected]>include/linux/moduleloader.h +4
-2@@ -45,7 +45,8 @@ static inline int apply_relocate(Elf_Shdr *sechdrs, unsigned int relsec, struct module *me) { - printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name); + printk(KERN_ERR "module %s: REL relocation unsupported\n", + module_name(me));return -ENOEXEC ; }#endif @@ -67,7 +68,8 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs, unsigned int relsec, struct module *me) { - printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name); + printk(KERN_ERR "module %s: REL relocation unsupported\n", + module_name(me));return -ENOEXEC ; }#endif
Signature · 4 lines
Masami HIRAMATSU Software Platform Research Dept. Linux Technology Research Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
Quoted 11 lines · On Tue, 08 Jul 2014 09:10:09 +0930 Rusty Russell <[email protected]> wrote:
Subject: modules: Fix build error in
moduleloader.hFengguang Wu's build bot detected that if
moduleloader.his included in a C file (used by ftrace and kprobes to accessmodule_alloc()when available), that it can fail to build ifCONFIG_MODULESandCONFIG_MODULES_USE_ELF_RELis not defined.This is because there's a
printk()that dereferences struct module to print the name of the module. But as struct module does not exist whenCONFIG_MODULESis not defined we get this error:
Quoted 7 lines
include/linux/moduleloader.h: In function 'apply_relocate':Quoted 2 lines
Quoted 2 lines
include/linux/moduleloader.h:48:63: error: dereferencing pointer to incomplete typeprintk(KERN_ERR "module %s: REL relocation unsupported\n", me->name); ^Reported-by kbuild test robot <[email protected]>Based-on-the-true-story-by Steven Rostedt <[email protected]>
-- Steve
Quoted 2 lines
Signed-off-by Rusty Russell <[email protected]>