From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20026 invoked by alias); 14 Jun 2011 18:36:16 -0000 Received: (qmail 19787 invoked by uid 22791); 14 Jun 2011 18:36:14 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST X-Spam-Check-By: sourceware.org Received: from mail-ew0-f47.google.com (HELO mail-ew0-f47.google.com) (209.85.215.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 14 Jun 2011 18:35:59 +0000 Received: by ewy5 with SMTP id 5so2472822ewy.20 for ; Tue, 14 Jun 2011 11:35:58 -0700 (PDT) Received: by 10.14.120.201 with SMTP id p49mr3087629eeh.179.1308076558359; Tue, 14 Jun 2011 11:35:58 -0700 (PDT) Received: from abhiPC ([145.94.33.197]) by mx.google.com with ESMTPS id 67sm837905eet.16.2011.06.14.11.35.56 (version=SSLv3 cipher=OTHER); Tue, 14 Jun 2011 11:35:57 -0700 (PDT) Message-ID: <8699ADBA137D45809135AD97814C9B06@abhiPC> From: "Abhijit Nandy" To: "Ian Lance Taylor" Cc: "gcc" References: <68C14D8B8C1E48DC8FE5F9DAB722DB7A@abhiPC><84220E2299EC44BBBB8A67D9B09BBBE1@abhiPC> In-Reply-To: Subject: Re: How to insert external global variable declarations and pointer assignment statements through GCC plugin GIMPLE pass Date: Wed, 15 Jun 2011 07:25:00 -0000 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-06/txt/msg00252.txt.bz2 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" 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