Re: [PATCH] HID: avoid sparse warning in HID_COMPAT_LOAD_DRIVER

From: Hannes Eder
Date: Tue Dec 16 2008 - 14:45:25 EST


On Tue, Dec 16, 2008 at 5:01 PM, Jiri Kosina <jkosina@xxxxxxx> wrote:
> On Tue, 16 Dec 2008, Ben Dooks wrote:
>
>> > #ifdef CONFIG_HID_COMPAT
>> > #define HID_COMPAT_LOAD_DRIVER(name) \
>> > +/* prototype to avoid sparse warning */ \
>> > +extern void hid_compat_##name(void); \
>> > void hid_compat_##name(void) { } \
>> surely this could simply be changed to 'static void
>> hid_compat_##name(void)' if it is only being defined to be an empty
>
> This will cause gcc emit warnings about unused symbols.

The real problem is that the symbol (in that case the function) is not
exported if defined static.

e.g.:

$ cat >foobar.c <<EOF
> static void foo(void) {}
> extern void foo(void);
>
> void bar(void) {}
> EOF
$ gcc -c foobar.c
$ nm foobar.o
00000005 T bar
00000000 t foo

from the nm manpage:
The symbol type. ... If lowercase, the symbol is local; if
uppercase, the symbol is global (external)

i.e. foo is local

see http://lkml.org/lkml/2008/9/4/495 for what ANSI C Std has to say
about that and about the proposed change.

But, don't ask my why the void functions with empty function bodies
are exported.

On Tue, Dec 16, 2008 at 8:41 PM, Ben Dooks <ben-linux@xxxxxxxxx> wrote:
> sorry, 'static inline void' then.

in that case the symbol would not even be local as it is not used with
the translation unit.

$ nm
00000005 T bar

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