This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How to insert external global variable declarations and pointer assignment statements through GCC plugin GIMPLE pass


Hi Ian,

Thanks for the pointers. I have been trying to make a simple VAR_DECL using the following call :

tree type_node = make_node(POINTER_TYPE);
//TYPE_NAME(type_node) = type_id;
tree var_decl = build0(VAR_DECL, type_node);

I was using this post as a guide :
http://gcc.gnu.org/ml/gcc/2007-01/msg00536.html

But I get a segmentation fault :
testcode.c: In function 'main':
testcode.c:26:7: warning: unused variable 'q'
*** WARNING *** there are active plugins, do not report this as a bug unless you
can reproduce it without enabling any plugins.
Event | Plugins
PLUGIN_ATTRIBUTES | test_plugin
testcode.c:33:1: internal compiler error: Segmentation fault


Can someone please help me out on how to complete the variable declaration and gimplify it.

-------------------

What I am attempting to do is insert the assignment statement in main() as follows(the global extern declaration also needs to be inserted but I can work it out afterwards):

extern char _binary_ccu_start;

int main (int argc, char **argv)
{
....
   char *p = &_binary_ccu_start;
...
}

Thanks,
Abhi

-----Original Message----- From: Ian Lance Taylor
Sent: Wednesday, May 25, 2011 2:39 AM
To: Abhijit Nandy
Cc: gcc
Subject: Re: How to insert external global variable declarations and pointer assignment statements through GCC plugin GIMPLE pass


"Abhijit Nandy" <abhijit.nandy@gmail.com> writes:

This is ok but I am unable to figure out how to insert a statement
like the following in global scope:
extern char _binary_ccu_start;

or to make an assigment like the following inside main :
char *p = &_binary_ccu_start;

Is this possible to do using a plugin ?

You need to create a VAR_DECL with TREE_STATIC set to 1 and pass it to rest_of_decl_compilation. Then you can get an expression which takes it address by passing the decl to build_fold_addr_expr.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]