public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* How to avoid a tree node being garbage collected after C  frontend?
@ 2009-11-09 17:05 Bingfeng Mei
  2009-11-09 19:00 ` Ian Lance Taylor
  0 siblings, 1 reply; 5+ messages in thread
From: Bingfeng Mei @ 2009-11-09 17:05 UTC (permalink / raw)
  To: gcc

Hello,
I need to pass a tree node (section name from processing pragmas)
from C frontend to main GCC body (used in TARGET_INSERT_ATTRIBUTES). 
I store the node in a global pointer array delcared in target.c.
But the tree node is garbage collected in the end of c-parser
pass, and causes an ICE later on. I am not familiar with GC part 
at all. How to prevent this from hanppening?

I checked other targets. It seems v850 almost uses the same approach
to implement section name pragma. Not sure if it has the same problem.
Also the issue is very sensitive to certain condition. For example, with
-save-temps option the bug disappear. 

Thanks,
Bingfeng Mei

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to avoid a tree node being garbage collected after C  frontend?
  2009-11-09 17:05 How to avoid a tree node being garbage collected after C frontend? Bingfeng Mei
@ 2009-11-09 19:00 ` Ian Lance Taylor
  2009-11-10 11:01   ` Bingfeng Mei
  0 siblings, 1 reply; 5+ messages in thread
From: Ian Lance Taylor @ 2009-11-09 19:00 UTC (permalink / raw)
  To: Bingfeng Mei; +Cc: gcc

"Bingfeng Mei" <bmei@broadcom.com> writes:

> I need to pass a tree node (section name from processing pragmas)
> from C frontend to main GCC body (used in TARGET_INSERT_ATTRIBUTES). 
> I store the node in a global pointer array delcared in target.c.
> But the tree node is garbage collected in the end of c-parser
> pass, and causes an ICE later on. I am not familiar with GC part 
> at all. How to prevent this from hanppening?

Mark the global variable with GTY(()).  See many many existing
examples.

Ian

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: How to avoid a tree node being garbage collected after C  frontend?
  2009-11-09 19:00 ` Ian Lance Taylor
@ 2009-11-10 11:01   ` Bingfeng Mei
  2009-11-10 12:19     ` Basile STARYNKEVITCH
  0 siblings, 1 reply; 5+ messages in thread
From: Bingfeng Mei @ 2009-11-10 11:01 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc

Ian, 
Thanks. I tried to follow the examples, but it still doesn't work. 
Here is the related code:

in target-c.c:
extern GTY(()) tree pragma_ghs_sections[GHS_SECTION_COUNT];

...

pragma_ghs_sections[sec_num] = copy_node (sec_name);


in target.c:

...
  section_name = pragma_ghs_sections[sec_num];

  if (section_name == NULL_TREE)
    return;

  DECL_SECTION_NAME(decl) = section_name;
...


When I watch the memory pragma_ghs_sections[sec_num] points to,
it is motified by 

#0  0x006cb3e7 in memset () from /lib/tls/libc.so.6
#1  0xffffc4f0 in ?? ()
#2  0x08120da4 in poison_pages () at ../../src/gcc/ggc-page.c:1854
#3  0x08120ee6 in ggc_collect () at ../../src/gcc/ggc-page.c:1945
#4  0x080f3692 in c_parser_translation_unit (parser=0xf7f92834) at ../../src/gcc/c-parser.c:978
#5  0x08103bd7 in c_parse_file () at ../../src/gcc/c-parser.c:8290

So target.c won't get correct section_name. 

What is wrong here? I understood GTY marker tells GC that
this global pointer contains access to GC allocated memory. 


Thanks for any input,
Bingfeng 

> -----Original Message-----
> From: Ian Lance Taylor [mailto:iant@google.com] 
> Sent: 09 November 2009 19:00
> To: Bingfeng Mei
> Cc: gcc@gcc.gnu.org
> Subject: Re: How to avoid a tree node being garbage collected 
> after C frontend?
> 
> "Bingfeng Mei" <bmei@broadcom.com> writes:
> 
> > I need to pass a tree node (section name from processing pragmas)
> > from C frontend to main GCC body (used in 
> TARGET_INSERT_ATTRIBUTES). 
> > I store the node in a global pointer array delcared in target.c.
> > But the tree node is garbage collected in the end of c-parser
> > pass, and causes an ICE later on. I am not familiar with GC part 
> > at all. How to prevent this from hanppening?
> 
> Mark the global variable with GTY(()).  See many many existing
> examples.
> 
> Ian
> 
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to avoid a tree node being garbage collected after C  frontend?
  2009-11-10 11:01   ` Bingfeng Mei
@ 2009-11-10 12:19     ` Basile STARYNKEVITCH
  2009-11-10 13:21       ` Bingfeng Mei
  0 siblings, 1 reply; 5+ messages in thread
From: Basile STARYNKEVITCH @ 2009-11-10 12:19 UTC (permalink / raw)
  To: Bingfeng Mei; +Cc: Ian Lance Taylor, gcc

Bingfeng Mei wrote:
> Ian, 
> Thanks. I tried to follow the examples, but it still doesn't work. 
> Here is the related code:
> 
> in target-c.c:
> extern GTY(()) tree pragma_ghs_sections[GHS_SECTION_COUNT];
> 

Perhaps you need to make sure that target-c.c is processed by gengtype, and that it does include the generated 
gt-target-c.h file.

Regards.


-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: How to avoid a tree node being garbage collected after C  frontend?
  2009-11-10 12:19     ` Basile STARYNKEVITCH
@ 2009-11-10 13:21       ` Bingfeng Mei
  0 siblings, 0 replies; 5+ messages in thread
From: Bingfeng Mei @ 2009-11-10 13:21 UTC (permalink / raw)
  To: Basile STARYNKEVITCH; +Cc: Ian Lance Taylor, gcc

Thanks, it works. I should have read the internal manual 
more carefully :-)

Cheers,
Bingfeng 

> -----Original Message-----
> From: Basile STARYNKEVITCH [mailto:basile@starynkevitch.net] 
> Sent: 10 November 2009 12:20
> To: Bingfeng Mei
> Cc: Ian Lance Taylor; gcc@gcc.gnu.org
> Subject: Re: How to avoid a tree node being garbage collected 
> after C frontend?
> 
> Bingfeng Mei wrote:
> > Ian, 
> > Thanks. I tried to follow the examples, but it still doesn't work. 
> > Here is the related code:
> > 
> > in target-c.c:
> > extern GTY(()) tree pragma_ghs_sections[GHS_SECTION_COUNT];
> > 
> 
> Perhaps you need to make sure that target-c.c is processed by 
> gengtype, and that it does include the generated 
> gt-target-c.h file.
> 
> Regards.
> 
> 
> -- 
> Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
> email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
> 8, rue de la Faiencerie, 92340 Bourg La Reine, France
> *** opinions {are only mines, sont seulement les miennes} ***
> 
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-11-10 13:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-09 17:05 How to avoid a tree node being garbage collected after C frontend? Bingfeng Mei
2009-11-09 19:00 ` Ian Lance Taylor
2009-11-10 11:01   ` Bingfeng Mei
2009-11-10 12:19     ` Basile STARYNKEVITCH
2009-11-10 13:21       ` Bingfeng Mei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).