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: Mikhail Maltsev <maltsevm at gmail dot com>
- To: "Bertram, Alexander" <alex at bedatadriven dot com>, Jonathan Wakely <jwakely dot gcc at gmail dot com>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Fri, 17 Jun 2016 15:00:59 +0300
- 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>
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