Identifying declared but unreferenced global variables from a plugin

Bertram, Alexander alex@bedatadriven.com
Mon Jun 20 06:40:00 GMT 2016


Yes! That was it!

Many thanks,
Alex

On Fri, Jun 17, 2016 at 2:00 PM, Mikhail Maltsev <maltsevm@gmail.com> wrote:
> 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



-- 
Alex Bertram
Technical Director
bedatadriven

Web: http://bedatadriven.com
Email: alex@bedatadriven.com
Tel. Nederlands: +31(0)647205388
Skype: akbertram



More information about the Gcc-help mailing list