This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Identifying declared but unreferenced global variables from a plugin
- From: "Bertram, Alexander" <alex at bedatadriven dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 17 Jun 2016 09:38:55 +0200
- Subject: Identifying declared but unreferenced global variables from a plugin
- Authentication-results: sourceware.org; auth=none
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