Identifying declared but unreferenced global variables from a plugin

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi there,

I'm trying to get the gcc-bridge plugin to dump out a list of _all_
global variables declared within a translation unit, even if they're
not used, and I've really hit a brick wall. Can anyone point me in the
right direction?

In more detail, say that you have a C source file consisting only of:

    int magic_number = 42;

With no functions declared. The global variable and its data is
written to the object file:

    $ gcc -c link1.c
    $ nm link1.o
    0000000000000000 D magic_number

But the global variable is not referenced by any functions so the
plugin never encounters it and doesn't know it exists.

I've tried iterating over the variable pool structure:

    struct varpool_node *node;
    for (node = varpool_nodes; node; node = node->next) {
        if(TREE_CODE(node->decl) == VAR_DECL) {
            dump_global_var(node->decl);
        }
   }

But it doesn't appear in this list either.
I've seen the check_global_declarations() method in toplev.c, which is
called with a list obtained from lang_hooks.decls.getdecls() in
langhooks.c, but when I call lang_hooks.decls.getdecls() from my
plugin, I get a NULL pointer back.

Any hints?

Many thanks,

Alex



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux