Identifying declared but unreferenced global variables from a plugin
Mikhail Maltsev
maltsevm@gmail.com
Fri Jun 17 12:01:00 GMT 2016
On 06/17/2016 12:39 PM, Bertram, Alexander wrote:
> Thanks for the pointer.
>
> But I'm not sure if this is the case here: the global variable is
> unreferenced, but it has external visibility and is ultimately written
> out to the object file as a symbol.
>
> I've kept digging around in the sources, and it looks like varasm.c
> might be something in the right direction:
>
> /* This file handles generation of all the assembler code
> *except* the instructions of a function.
> This includes declarations of variables and their initial values.
>
> We also output the assembler code for constants stored in memory
> and are responsible for combining constants with the same value. */
>
> So somehow the code in varasm gets a list of these global declarations
> and writes them as data(?) sections in the object file. Where does
> varasm get this list?
varpool.c has 'symbol_table::output_variables' method, it uses
'FOR_EACH_VARIABLE' and 'FOR_EACH_DEFINED_VARIABLE' macros to traverse the lists
of declared/defined variables. These macros are defined in cgraph.h
--
Regards,
Mikhail Maltsev
More information about the Gcc-help
mailing list