public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/38987]  New: Including a precompiled header from another header causes invalid assembly to be generated
@ 2009-01-27 16:27 frank dot richter at gmail dot com
  2009-01-27 16:29 ` [Bug c++/38987] " frank dot richter at gmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 15+ messages in thread
From: frank dot richter at gmail dot com @ 2009-01-27 16:27 UTC (permalink / raw)
  To: gcc-bugs

When a header(A) is precompiled and included from another header(B), compiling
a source file using B results in invalid assembly. The message from the
assembler is "file number X already allocated".


-- 
           Summary: Including a precompiled header from another header
                    causes invalid assembly to be generated
           Product: gcc
           Version: 4.2.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: frank dot richter at gmail dot com
  GCC host triplet: x86_64-pc-linux-gnu
GCC target triplet: x86_64-pc-linux-gnu


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


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

* [Bug c++/38987] Including a precompiled header from another header causes invalid assembly to be generated
  2009-01-27 16:27 [Bug c++/38987] New: Including a precompiled header from another header causes invalid assembly to be generated frank dot richter at gmail dot com
@ 2009-01-27 16:29 ` frank dot richter at gmail dot com
  2009-01-27 17:14 ` rguenth at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: frank dot richter at gmail dot com @ 2009-01-27 16:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from frank dot richter at gmail dot com  2009-01-27 16:28 -------
Created an attachment (id=17192)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17192&action=view)
Test case for precompiled header inclusion

This test case is a simple scenario where a precompiled header is included by
another header. Run 'cause-bug.sh' to precompile a header and then attempt to
build a source indirectly using that header-


-- 


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


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

* [Bug c++/38987] Including a precompiled header from another header causes invalid assembly to be generated
  2009-01-27 16:27 [Bug c++/38987] New: Including a precompiled header from another header causes invalid assembly to be generated 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
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-01-27 17:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2009-01-27 17:14 -------
CXX=g++-4.3 ./cause-error.sh 
In file included from <built-in>:0:
<built-in>:0: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugs.opensuse.org/> for instructions.

This looks related to https://bugzilla.novell.com/show_bug.cgi?id=432433
and https://bugzilla.novell.com/show_bug.cgi?id=444153

-> PCH is broken wrt location information.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-valid-code
      Known to fail|                            |4.1.2 4.2.4 4.3.3 4.4.0


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


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

* [Bug c++/38987] Including a precompiled header from another header causes invalid assembly to be generated
  2009-01-27 16:27 [Bug c++/38987] New: Including a precompiled header from another header causes invalid assembly to be generated 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
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: frank dot richter at gmail dot com @ 2009-01-27 17:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from frank dot richter at gmail dot com  2009-01-27 17:18 -------
No ICE here (gcc version 4.2.4 (Gentoo 4.2.4 p1.0)), but the underlying cause
might be the same.


-- 


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


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

* [Bug c++/38987] Including a precompiled header from another header causes invalid assembly to be generated
  2009-01-27 16:27 [Bug c++/38987] New: Including a precompiled header from another header causes invalid assembly to be generated frank dot richter at gmail dot com
                   ` (2 preceding siblings ...)
  2009-01-27 17:18 ` frank dot richter at gmail dot com
@ 2009-01-28 12:22 ` matz at gcc dot gnu dot org
  2009-02-24 13:06 ` [Bug preprocessor/38987] " rguenth at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: matz at gcc dot gnu dot org @ 2009-01-28 12:22 UTC (permalink / raw)
  To: gcc-bugs



------- 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


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

* [Bug preprocessor/38987] Including a precompiled header from another header causes invalid assembly to be generated
  2009-01-27 16:27 [Bug c++/38987] New: Including a precompiled header from another header causes invalid assembly to be generated frank dot richter at gmail dot com
                   ` (3 preceding siblings ...)
  2009-01-28 12:22 ` matz at gcc dot gnu dot org
@ 2009-02-24 13:06 ` rguenth at gcc dot gnu dot org
  2009-02-24 14:50 ` frank dot richter at gmail dot com
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-02-24 13:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rguenth at gcc dot gnu dot org  2009-02-24 13:06 -------
This is a preprocessor bug.  We should not use PCHs when it is not the very
first preprocessing directive in the TU that opens it.  Thus, doc/invoke.texi

"
@item
A precompiled header can't be used once the first C token is seen.  You
can have preprocessor directives before a precompiled header; you can
even include a precompiled header from inside another header, so long as
there are no C tokens before the @code{#include}.
"

is very overly optimistic about conditions a PCH is valid.

Tom, do you have an idea where to best restrict the use of PCHs this way?


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tromey at redhat dot com
             Status|UNCONFIRMED                 |NEW
          Component|c++                         |preprocessor
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2009-02-24 13:06:14
               date|                            |


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


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

* [Bug preprocessor/38987] Including a precompiled header from another header causes invalid assembly to be generated
  2009-01-27 16:27 [Bug c++/38987] New: Including a precompiled header from another header causes invalid assembly to be generated frank dot richter at gmail dot com
                   ` (4 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: frank dot richter at gmail dot com @ 2009-02-24 14:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from frank dot richter at gmail dot com  2009-02-24 14:50 -------
Arguably, that makes precompiled headers less useful - in scenarios where you
have two big libraries with complicated headers you can at most only use PCHs
for one of them. Anyhow, that issue is a separate matter.


-- 


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


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

* [Bug preprocessor/38987] Including a precompiled header from another header causes invalid assembly to be generated
  2009-01-27 16:27 [Bug c++/38987] New: Including a precompiled header from another header causes invalid assembly to be generated frank dot richter at gmail dot com
                   ` (5 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: rguenther at suse dot de @ 2009-02-24 14:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from rguenther at suse dot de  2009-02-24 14:52 -------
Subject: Re:  Including a precompiled header from
 another header causes invalid assembly to be generated

On Tue, 24 Feb 2009, frank dot richter at gmail dot com wrote:

> ------- Comment #6 from frank dot richter at gmail dot com  2009-02-24 14:50 -------
> Arguably, that makes precompiled headers less useful - in scenarios where you
> have two big libraries with complicated headers you can at most only use PCHs
> for one of them. Anyhow, that issue is a separate matter.

Using more than one PCH was never possible.

Richard.


-- 


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


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

* [Bug preprocessor/38987] Including a precompiled header from another header causes invalid assembly to be generated
  2009-01-27 16:27 [Bug c++/38987] New: Including a precompiled header from another header causes invalid assembly to be generated frank dot richter at gmail dot com
                   ` (6 preceding siblings ...)
  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
  9 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-04-23  0:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from pinskia at gcc dot gnu dot org  2009-04-23 00:11 -------
*** Bug 39854 has been marked as a duplicate of this bug. ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ryancacophony at gmail dot
                   |                            |com


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


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

* [Bug preprocessor/38987] Including a precompiled header from another header causes invalid assembly to be generated
  2009-01-27 16:27 [Bug c++/38987] New: Including a precompiled header from another header causes invalid assembly to be generated frank dot richter at gmail dot com
                   ` (8 preceding siblings ...)
  2009-09-22  8:38 ` rguenth at gcc dot gnu dot org
@ 2009-09-22  8:38 ` rguenth at gcc dot gnu dot org
  9 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-09-22  8:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from rguenth at gcc dot gnu dot org  2009-09-22 08:37 -------
Subject: Bug 38987

Author: rguenth
Date: Tue Sep 22 08:37:31 2009
New Revision: 151970

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=151970
Log:
2009-09-22  Richard Guenther  <rguenther@suse.de>

        PR pch/38987
        * files.c (pch_open_file): Disallow non-toplevel PCH inclusion.

Modified:
    trunk/libcpp/ChangeLog
    trunk/libcpp/files.c


-- 


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


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

* [Bug preprocessor/38987] Including a precompiled header from another header causes invalid assembly to be generated
  2009-01-27 16:27 [Bug c++/38987] New: Including a precompiled header from another header causes invalid assembly to be generated frank dot richter at gmail dot com
                   ` (7 preceding siblings ...)
  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
  9 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-09-22  8:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from rguenth at gcc dot gnu dot org  2009-09-22 08:38 -------
Fixed.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
      Known to work|                            |4.5.0
         Resolution|                            |FIXED
   Target Milestone|---                         |4.5.0


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


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

* [Bug preprocessor/38987] Including a precompiled header from another header causes invalid assembly to be generated
       [not found] <bug-38987-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2015-01-12 14:19 ` jakub at gcc dot gnu.org
@ 2023-12-17  4:20 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-17  4:20 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |danglin at gcc dot gnu.org

--- Comment #14 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 31872 has been marked as a duplicate of this bug. ***

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

* [Bug preprocessor/38987] Including a precompiled header from another header causes invalid assembly to be generated
       [not found] <bug-38987-4@http.gcc.gnu.org/bugzilla/>
  2010-12-05 22:21 ` rguenth at gcc dot gnu.org
  2012-03-07  9:58 ` rguenth at gcc dot gnu.org
@ 2015-01-12 14:19 ` jakub at gcc dot gnu.org
  2023-12-17  4:20 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu.org @ 2015-01-12 14:19 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jpyeron at pdinc dot us

--- Comment #13 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
*** Bug 64414 has been marked as a duplicate of this bug. ***


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

* [Bug preprocessor/38987] Including a precompiled header from another header causes invalid assembly to be generated
       [not found] <bug-38987-4@http.gcc.gnu.org/bugzilla/>
  2010-12-05 22:21 ` rguenth at gcc dot gnu.org
@ 2012-03-07  9:58 ` rguenth at gcc dot gnu.org
  2015-01-12 14:19 ` jakub at gcc dot gnu.org
  2023-12-17  4:20 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-03-07  9:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #12 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-03-07 09:55:32 UTC ---
Author: rguenth
Date: Wed Mar  7 09:55:26 2012
New Revision: 185029

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=185029
Log:
2012-03-07  Richard Guenther  <rguenther@suse.de>

    PR pch/52518
    PR pch/38987
    * doc/invoke.texi (Precompiled Headers): Remove sentence that
    suggests you can include PCHs from inside another header.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/doc/invoke.texi


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

* [Bug preprocessor/38987] Including a precompiled header from another header causes invalid assembly to be generated
       [not found] <bug-38987-4@http.gcc.gnu.org/bugzilla/>
@ 2010-12-05 22:21 ` rguenth at gcc dot gnu.org
  2012-03-07  9:58 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu.org @ 2010-12-05 22:21 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gafunchal at gmail dot com

--- Comment #11 from Richard Guenther <rguenth at gcc dot gnu.org> 2010-12-05 22:20:24 UTC ---
*** Bug 40272 has been marked as a duplicate of this bug. ***


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

end of thread, other threads:[~2023-12-17  4:20 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-27 16:27 [Bug c++/38987] New: Including a precompiled header from another header causes invalid assembly to be generated 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
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
     [not found] <bug-38987-4@http.gcc.gnu.org/bugzilla/>
2010-12-05 22:21 ` rguenth at gcc dot gnu.org
2012-03-07  9:58 ` rguenth at gcc dot gnu.org
2015-01-12 14:19 ` jakub at gcc dot gnu.org
2023-12-17  4:20 ` pinskia at gcc dot gnu.org

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).