This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Identifying declared but unreferenced global variables from a plugin


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]