[PVFS-users] Re: "insmod fails" after kernel compilation with gcc 3.4.X

Murali Vilayannur vilayann at mcs.anl.gov
Mon Jul 26 14:01:11 EDT 2004


Hi,
I am not sure what the right solution is here. Rob can help decide 
that. The problem with gcc 3.4.X is that the compiler is very "smart"
in throwing out what it considers are dead-code and dead-data. 

The definitions of MODULE_LICENSE(),
__module_kernel_version[], __module_using_checksums[]
 from linux/module.h on 2.4 kernels look like this,

#define MODULE_LICENSE(license)  \
static const char __module_license[]
__attribute__((section(".modinfo"))) =   \
"license=" license

static const char __module_kernel_version[] 
__attribute__((section(".modinfo"))) =
"kernel_version=" UTS_RELEASE;

#ifdef MODVERSIONS
static const char __module_using_checksums[] 
__attribute__((section(".modinfo"))) =
"using_checksums=1";
#endif

The compiler notices that none of these 3 variables are referenced (it 
has no clue that these are the symbols that insmod looks for!!) and it 
eliminates them. One option is to fix your headers like so,

static const char __module_license[] __attribute_used__ 
__attribute__((section(".modinfo"))) =   \
"license=" license

static const char __module_kernel_version[] __attribute_used__ 
__attribute__((section(".modinfo"))) =
"kernel_version=" UTS_RELEASE;

#ifdef MODVERSIONS
static const char __module_using_checksums[] __attribute_used__
__attribute__((section(".modinfo"))) =
"using_checksums=1";
#endif

where the __attribute_used__ is a macro that should be present in most 
recent 2.4 kernels and if not it is as follows,

#if __GNUC__ > 3
#define __attribute_used__ __attribute((__used__))
#elif __GNUC__ == 3
#if  __GNUC_MINOR__ >= 3
# define __attribute_used__   __attribute__((__used__))
#else
# define __attribute_used__   __attribute__((__unused__))
#endif /* __GNUC_MINOR__ >= 3 */
#elif __GNUC__ == 2
#define __attribute_used__ __attribute__((__unused__))
#else
#define __attribute_used__ /* not implemented */
#endif /* __GNUC__ */

If you recompile the pvfs-kernel code after fixing these 3 definitions in 
linux/module.h, you should be able to load and use the pvfs kernel module.
NOTE that we don't have to fix MODULE_AUTHOR, MODULE_DESCRIPTION since 
those macros evaluate to a "const char" and not a "static const char".

The other option is the attached patch (where we don't assume whether or 
not the kernel headers are broken, whether or not gcc 3.4.x is used).
In the worst case this patch would add 3 new symbols to the .modinfo 
section of the object file, (i.e if the kernel headers are not broken).
Hence this approach should work in all scenarios or so I think.
Let us know if this patch fixes your problems.

Thanks,
Murali


On Sun, 25 Jul 2004, E. Otto wrote:

> I am not sure if the error is something else but after applying
> the patch for gcc340 to the pvfs-kernel source (v 1.6.2), the 
> compilation succeeds.  However, attempt to insert module pvfs.o 
> complains that it can't find the kernel module. The RedHat Kernel in use 
> is  2.4.20-30.9.
> The module copied to the kernel fs directory is the one generated after 
> the compilation. The messages are as shown:
> 
> [root at prahba ekw]# insmod pvfs
> Using /lib/modules/2.4.20-30.9/kernel/fs/pvfs/pvfs.o
> /lib/modules/2.4.20-30.9/kernel/fs/pvfs/pvfs.o: couldn't find the kernel 
> version the module was compiled for
> 
> _______________________________________________
> PVFS-users mailing list
> PVFS-users at www.beowulf-underground.org
> http://www.beowulf-underground.org/mailman/listinfo/pvfs-users
> 
> 
-------------- next part --------------
Index: pvfs_kernel_config.h
===================================================================
RCS file: /anoncvs/pvfs-kernel/pvfs_kernel_config.h,v
retrieving revision 1.33
diff -u -r1.33 pvfs_kernel_config.h
--- pvfs_kernel_config.h	19 Jun 2003 23:52:09 -0000	1.33
+++ pvfs_kernel_config.h	26 Jul 2004 16:37:42 -0000
@@ -36,6 +36,31 @@
 #include <linux/config.h>
 #include <linux/version.h>
 
+/* ugly hack needed for gcc 3.4.X and broken kernel headers */
+#if __GNUC__ > 3
+#ifndef __attribute_used__
+#define __attribute_used__ __attribute((__used__))
+#endif
+#elif __GNUC__ == 3
+#if  __GNUC_MINOR__ >= 3
+#ifndef __attribute_used__
+# define __attribute_used__   __attribute__((__used__))
+#endif
+#else
+#ifndef __attribute_used__
+# define __attribute_used__   __attribute__((__unused__))
+#endif
+#endif /* __GNUC_MINOR__ >= 3 */
+#elif __GNUC__ == 2
+#ifndef __attribute_used__
+#define __attribute_used__ __attribute__((__unused__))
+#endif
+#else
+#ifndef __attribute_used__
+#define __attribute_used__ /* not implemented */
+#endif
+#endif /* __GNUC__ */
+
 /* define __SMP__ if we detect SMP kernel running at configure time */
 #if defined(HAVE_SMP_KERNEL) && ! defined(__SMP__)
 #define __SMP__  
Index: pvfs_mod.c
===================================================================
RCS file: /anoncvs/pvfs-kernel/pvfs_mod.c,v
retrieving revision 1.23
diff -u -r1.23 pvfs_mod.c
--- pvfs_mod.c	9 Nov 2002 12:55:16 -0000	1.23
+++ pvfs_mod.c	26 Jul 2004 16:37:42 -0000
@@ -31,6 +31,20 @@
 #include "pvfsd.h"
 #endif
 
+/* Ugly hack needed for gcc 3.4.x and broken kernel headers */
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
+static const char __module_kernel_version1[] __attribute_used__
+       __attribute__((section(".modinfo"))) = "kernel_version=" UTS_RELEASE;
+#ifdef CONFIG_MODVERSIONS
+static const char __module_using_checksums1[] __attribute_used__ 
+		 __attribute__((section(".modinfo"))) = "using_checksums=1";
+#endif
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,9)
+static const char __module_license1[] __attribute_used__ 
+		 __attribute__((section(".modinfo"))) = "license=GPL";
+#endif
+#endif
+
 
 MODULE_AUTHOR("Rob Ross <rbross at parl.clemson.edu> and Phil Carns <pcarns at parl.clemson.edu>");
 MODULE_DESCRIPTION("pvfs: PVFS VFS support module");


More information about the PVFS-users mailing list