Messages in this thread Patch in this message | | | Date | Wed, 15 Mar 2000 11:02:58 +0100 | From | Jakub Jelinek <> | Subject | Re: [PATCH] static int __init foobar_init(void) {} fix |
| |
On Wed, Mar 15, 2000 at 06:20:50PM +1100, Rusty Russell wrote: > In message <20000313153841.F568@mff.cuni.cz> you write: > > On the other side, we can cheat: > > [Comment added (it's a little obscure otherwise)].
Here is another version which in addition to the patch Rusty posted checks if the function passed to module_init/module_exit has proper prototype. With this patch gcc will warn if one does:
void init_foo(int x) { }
module_init(init_foo)
but as previous patch will not give bogus warning about unused init_bar:
static int init_bar(void) { return 0; }
module_init(init_bar)
--- 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.51 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/
| |