Skip to contentSkip to conversation

modules: Fix build error in moduleloader.h

PATCH In review Steven Rostedt 3 participants 5 messages Jul 3, 2014 – Jul 8, 2014 Module support

lore
Share & tools
lore
#0 lore raw

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
index 560ca53..d9da807 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Steven Rostedt

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:

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 type

     printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
                                                                  ^

Avoid the printk if CONFIG_MODULES is 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

---

include/linux/moduleloader.h +3 -0
index 560ca53..d9da807 100644
@@ -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]
#2 lore raw
In reply to Steven Rostedt
Quoted 8 lines · Steven Rostedt

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:

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
index 560ca53a75fa..7eeb9bbfb816 100644
@@ -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
#3 lore raw
Quoted 18 lines · Rusty Russell
Quoted 8 lines · Steven Rostedt

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:

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.)

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.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
index 560ca53a75fa..7eeb9bbfb816 100644
@@ -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]
#4 lore raw
In reply to Rusty Russell
Quoted 11 lines · On Tue, 08 Jul 2014 09:10:09 +0930 Rusty Russell <[email protected]> wrote:

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:

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 type

     printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
								  ^
Confirms-rustys-story-ends-the-same-by Steven Rostedt <[email protected]>

-- Steve

Quoted 2 lines