This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Problem with instrumenting GIMPLE for adding a global variable
- From: Prateek Saxena <prateeksaxena at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Sat, 20 Aug 2005 19:53:29 -0400
- Subject: Re: Problem with instrumenting GIMPLE for adding a global variable
Sorry, my mistake. I initialized it with a value, and it appeared in
the .data. :)
> Hi,
>
> I am trying to implement a prototype pass that instruments a function
> to check for safe memory accesses. As a starting point I looked at
> mudflap1 pass, in tree-mudflap.c and decided that I should write a
> dummy pass ( very simple, but similar to mudflap) that instruments the
> code to count the number of functions in the source file.
>
> I am unable to add a global variable in the file scope. The global
> VAR_DECL building function looks like this:
>
> {
> tree decl = build_decl (VAR_DECL, get_identifier ("my_var"),
> integer_type_node);
> TREE_PUBLIC (decl) = 0;
> DECL_EXTERNAL (decl) = 0;
> TREE_STATIC (decl) = 1;
> gimplify_stmt (my_variable);
> lang_hooks.decls.pushdecl (decl);
> return decl;
> }
>
> It is called from within my call-back function "execute_my_pass" ( as
> specified by me in the tree_opt_pass structure ).
>
> I increment "my_var" in every function. But, the instrumented object
> file doesnot have a storage allocated for this variable in the .data
> section. The problem is that DECL_CONTEXT of this VAR_DECL is always
> getting assigned to a function, and not to global file scope. Why is
> that?
>
> Any help would be appreciated.
>
> Thanks,
> Prateek.