public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "matz at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/38987] Including a precompiled header from another header causes invalid assembly to be generated
Date: Wed, 28 Jan 2009 12:22:00 -0000	[thread overview]
Message-ID: <20090128122243.23088.qmail@sourceware.org> (raw)
In-Reply-To: <bug-38987-17234@http.gcc.gnu.org/bugzilla/>



------- Comment #4 from matz at gcc dot gnu dot org  2009-01-28 12:22 -------
I'm fairly sure it's the same underlying problem.  The emitted file numbers
(in the .s file for debug info) are in garbage collected memory.  Hence
the directives emitted when the PCH is not yet loaded and those emitted after
it's loaded might use the same file number.  In this case you use -g3, meaning
to emit directives for defined macros.  These are emitted (obviously) as soon
as the include directive is seen.  This will allocate numbers 1 and 2 for
main.cpp and main.h.  Then the PCH file is loaded, overwriting the internally
(in dwarf2out.c:struct dwarf_file_data) stored file numbers, so we start
counting from 2 again (we overwrite only data from after the main file),
which is given to main.cpp again.

Hence the assembler gives the error message.

Later compilers simply segfault already earlier in the process, because
location info is also overwritten but still referenced, as detailed
in the https://bugzilla.novell.com/show_bug.cgi?id=444153 .

Also, as detailed there, it seems to be a fundamental design choice that the
PCH has to be included from the main file, as the PCH machinery uses the
garbage collection engine to actually retrieve the memory state like it
was when precompiling the file.  This obviously can only work if no stale
references exist to then overwritten information and this in turn can only
be ensured when there isn't "too much" information before loading the PCH file
at all.

No idea how easy this would be to fix, from a cursory look at the whole
machinery it looks quite difficult (at least if one wants to really fix
this, and not just work-around the cases that people happen to hit)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38987


  parent reply	other threads:[~2009-01-28 12:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-27 16:27 [Bug c++/38987] New: " frank dot richter at gmail dot com
2009-01-27 16:29 ` [Bug c++/38987] " frank dot richter at gmail dot com
2009-01-27 17:14 ` rguenth at gcc dot gnu dot org
2009-01-27 17:18 ` frank dot richter at gmail dot com
2009-01-28 12:22 ` matz at gcc dot gnu dot org [this message]
2009-02-24 13:06 ` [Bug preprocessor/38987] " rguenth at gcc dot gnu dot org
2009-02-24 14:50 ` frank dot richter at gmail dot com
2009-02-24 14:52 ` rguenther at suse dot de
2009-04-23  0:11 ` pinskia at gcc dot gnu dot org
2009-09-22  8:38 ` rguenth at gcc dot gnu dot org
2009-09-22  8:38 ` rguenth at gcc dot gnu dot org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090128122243.23088.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).