This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Identifying declared but unreferenced global variables from a plugin
- From: "Bertram, Alexander" <alex at bedatadriven dot com>
- To: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Mon, 20 Jun 2016 08:39:50 +0200
- Subject: Re: Identifying declared but unreferenced global variables from a plugin
- Authentication-results: sourceware.org; auth=none
- References: <CAOdV3zCp=S+XQPoeh8ejmT6YxuEoN2gGmau8qC4vXQ0w2b4G4g at mail dot gmail dot com> <CAH6eHdRaK47mEzM_cmxOJ9L_VwRW_UWJUrz876SwYVR+c4ur6w at mail dot gmail dot com> <CAOdV3zCZ70D0_FL3-JWtpg3-m+2xh0LF_8VUifiXfn7ibFT7Jg at mail dot gmail dot com> <5763E67B dot 3030505 at gmail dot com>
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