Re: [PATCH] static int __init foobar_init(void) {} fix

From: Jakub Jelinek (jakub@redhat.com)
Date: Fri Mar 17 2000 - 07:23:05 EST


On Thu, Mar 16, 2000 at 08:29:00AM -0400, Horst von Brand wrote:
> Rusty Russell <rusty@linuxcare.com.au> said:
> > In message <20000313153841.F568@mff.cuni.cz> you write:
> > > On the other side, we can cheat:
>
> > Linus, please apply this: Jakub you're my hero!
> >
> > [Comment added (it's a little obscure otherwise)].
> >
> > --- linux-2.3-official/include/linux/init.h Tue Mar 14 23:55:41 2000
> > +++ linux-2.3-nfmerge/include/linux/init.h Wed Mar 15 18:16:48 2000
> > @@ -98,8 +98,17 @@
> >
> > /* Not sure what version aliases were introduced in, but certainly in 2.91.66. */
> > #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 91)
> > -#define module_init(x) int init_module(void) __attribute__((alias(#x)));
> > -#define module_exit(x) void cleanup_module(void) __attribute__((alias(#x)));
> > +/* These macros create a dummy inline: gcc 2.9x does not count alias
> > + as usage, hence the `unused function' warning when __init functions
> > + are declared static */
> > +#define module_init(x) \
> > +int init_module(void) __attribute__((alias(#x))); \
> > +extern inline void *__init_module_inline(void) \
> > +{ return (void *)x; }
> > +#define module_exit(x) \
> > +void cleanup_module(void) __attribute__((alias(#x))); \
> > +extern inline void *__cleanup_module_inline(void) \
> > +{ return (void *)x; }
>
> This might get you into _serious_ trouble if someday gcc decides that it is
> better to use this bogus inline and not the real McCoy, as having two
> different definitions for a function is definitely illegal (but the
> compiler doesn't have to notice). Better:

Can you elaborate more on how could gcc someday decide to use an inline
function with completely different name?
I don't see how my patch introduces two different definitions for a
function.
BTW: Attached is a new patch I've posted yesterday which checks if the
function mentioned in module_init() or module_exit() has correct prototype
in addition to removing the bogus warning.
Even if the alias as a use is implemented in gcc, this patch should do no
harm IMHO, as unused extern inline should never be compiled into the code
(and even if it would, it would just waste space).

--- linux/include/linux/init.h.jj Sat Jan 29 21:21:06 2000
+++ linux/include/linux/init.h Wed Mar 15 08:44:41 2000
@@ -98,8 +98,21 @@ extern struct kernel_param __setup_start
 
 /* Not sure what version aliases were introduced in, but certainly in 2.91.66. */
 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 91)
-#define module_init(x) int init_module(void) __attribute__((alias(#x)));
-#define module_exit(x) void cleanup_module(void) __attribute__((alias(#x)));
+/* These macros create a dummy inline: gcc 2.9x does not count alias
+ as usage, hence the `unused function' warning when __init functions
+ are declared static. We use the dummy __*_module_inline functions
+ both to kill the warning and check the type of the init/cleanup
+ function. */
+typedef int (*__init_module_func_t)(void);
+typedef void (*__cleanup_module_func_t)(void);
+#define module_init(x) \
+int init_module(void) __attribute__((alias(#x))); \
+extern inline __init_module_func_t __init_module_inline(void) \
+{ return x; }
+#define module_exit(x) \
+void cleanup_module(void) __attribute__((alias(#x))); \
+extern inline __cleanup_module_func_t __cleanup_module_inline(void) \
+{ return x; }
 #else
 #define module_init(x) int init_module(void) { return x(); }
 #define module_exit(x) void cleanup_module(void) { x(); }

Cheers,
    Jakub
___________________________________________________________________
Jakub Jelinek | jakub@redhat.com | http://sunsite.mff.cuni.cz/~jj
Linux version 2.3.99-pre2 on a sparc64 machine (1343.49 BogoMips)
___________________________________________________________________

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu Mar 23 2000 - 21:00:23 EST