lkml.org 
[lkml]   [2000]   [Mar]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] static int __init foobar_init(void) {} fix
Date
From
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:

- Add a prototype for the function (so the compiler will scream if it
doesn't match)
- Politely ask the GCC folks to consider an alias as a use (which I just
did)
--
Dr. Horst H. von Brand mailto:vonbrand@inf.utfsm.cl
Departamento de Informatica Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria +56 32 654239
Casilla 110-V, Valparaiso, Chile Fax: +56 32 797513

-
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/

\
 
 \ /
  Last update: 2005-03-22 13:57    [W:0.063 / U:0.140 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site