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. Yes it was a basic mistake. I assumed that the undefined reference was due to the extern declaration not being inserted.

So I guess DECL_EXTERNAL(var_decl) = 1 causes the var_decl to be set as an external declaration in the following code :

tree var_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("_binary_ccu_start"), char_type_node);
TREE_STATIC(var_decl) = 1;
DECL_EXTERNAL(var_decl) = 1;



I have another question. Right now I create the following declaration char *p;

using :
tree temp = create_tmp_var(TREE_TYPE(TREE_TYPE(elfset_decl)), "p");

where elfset_decl is set to be char* in a separate function.

However is there another way to create a pointer to char, especially if I want the exact identifier 'p' instead of
char * p.1;


which the gimple pass dump is showing me.

I tried to do it as follows :
tree var_decl1 = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("p"), char_type_node);
TREE_STATIC(var_decl1) = 0;
DECL_EXTERNAL(var_decl1) = 0;
rest_of_decl_compilation (var_decl1, 1, 0);


But nothing appears in the gimple pass dump. I think this may be due to not actually inserting the declaration in the tree using a gimple function.

Thanks,
Abhi


-----Original Message----- From: Ian Lance Taylor
Sent: Tuesday, June 14, 2011 7:38 PM
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:

My C input file is testcode.c and after I compile with the plugin
enabled as :

gcc -fplugin=./test_plugin.so -Wall -fdump-tree-gimple -fdump-tree-all
testcode.c molen_htx.c -o testcode

The molen_htx.c has the molen_elfset()

I get the following linker error :

root@slax:/mnt/f/Thesis/gcc-pluginelf# make testcode
cc -I/usr/lib/gcc/i486-slackware-linux/4.5.2/plugin/include -fPIC
-Wall   -c
-o test_plugin.o test_plugin.c
gcc -shared test_plugin.o -o test_plugin.so
gcc -fplugin=./test_plugin.so -Wall -fdump-tree-gimple -fdump-tree-all
testcode.c molen_htx.c -o testcode
plugin init test_plugin
testcode.c: In function 'main':
testcode.c:26:7: warning: unused variable 'q'
plugin init test_plugin
/tmp/ccLUccsU.o: In function `main':
testcode.c:(.text+0x82): undefined reference to `_binary_ccu_start'
<---------------
collect2: ld returned 1 exit status
make: *** [testcode] Error 1


A dump file called testcode.c.220t.replace is produced which does not show the global declaration(if it is being inserted at all)

But the undefined reference implies that the global extern declaration
was not inserted.

A global extern declaration is not a definition. The variable needs to be defined somewhere.

If your .c file has "extern char _binary_ccu_start;" you still need to
have some .c file which has "char _binary_ccu_start;", right?

Ian


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