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



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/



Relevant Pages

  • Re: linking C++ functions in a C program
    ... contains one function named foo() which is compiled in C, ... Therefore, no matter how you classify bar(), this program ... void foo; ... guess the compiler can generate two references to foo, one adorned, ...
    (comp.lang.c)
  • Circular dependency - I think..
    ... The header file for FOO is composed of BAR, ... int GetFbk(); ... void ComputeTorquerCmd(); ...
    (comp.lang.cpp)
  • Re: is assignment atomic/thread safe?
    ... void foo() ... with one thread running foo() while another runs bar(). ... and thus no guarantees are made about _when_ any given piece of code will execute. ...
    (comp.lang.java.programmer)
  • [PATCH 2/2] page table iterators
    ... * for_each_pmd - iterate through pmd entries in a given pud ... */ void clear_page_range{ ... int err = 0; ... } return err;} static void zap_pte_range(struct mmu_gather *tlb, ...
    (Linux-Kernel)
  • Re: Library bug or my fault?
    ... compiled using ARM/Linux cross-compiler and run on an ARM9 target. ... void memcpy ... 29 void cp(const Foo *foo) ... 31 Bar bar; ...
    (comp.lang.c)