On Feb 11, 2007, at 1:17 PM, Brendon Costa wrote:
I am coding an extension for GCC and am having some difficulty with
pre-compiled headers. I dont know if my understanding of how they
work is completely correct and so my code is getting a segfault.
You _must_ have clean data structures and complete type safety. You
cannot have any pointers to GCed memory any place but GCed memory, or
file data marked with GTY(()) markers. The last rule is a good
approximation, cpp for examples deviates from this general rule.
So i also hook into c_common_no_more_pch()
Ick. You seem to have thought too much about pch. Instead, pretend
it isn't there, except for doing the GTY(()) thing on all static
scope data.
c_common_no_more_pch seems like the wrong place. You calculate
things when you have the data to calculate from and someplace to put
it, but the code there. You want to do it at the end of file
processing, put it there. You want to do it from the parser, or
optimizer, put it there.
1) Is there a better place to hook into to know when the PCH engine
has completed reconstructing the tree nodes?
See why this is the wrong question? The question is, I am doing this
calculation, where should I put it? The answer to that is, when you
have all the data from which you need to do the calculation and a
place to store it.
2) Is there something wrong in the way i understand the
reconstruction of data by the PCH engine? I assumed it would re-
construct a full tree hierarchy if i rooted a tree node.
Yes.
The mental model you should use for PCH is this, when processing a
header, the compiler does a complete memory walk and dumps it to a
file. Upon `reading' the pch file, it mmaps all that memory back in,
throwing out all previously allocated memory, and continues just
after the #include.
If you have any code that knows about pch (other than GTY(())),
you're probably trying to be too smart about pchness. I can't tell
if you are or not, unless you tell me why you want to be.