This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug pch/13675] #including a precompiled header more than once in the same unit fails



------- Comment #16 from l dot bermes at eurokey dot de  2007-11-27 03:06 -------
I got the same problems using gch in some projects. I'm using only one
precompiled header (defaults.h).
gcc is from SUSE Linux Enterprise Server 10
GNU C++ version 4.1.0 (SUSE Linux) (i586-suse-linux)
        compiled by GNU C version 4.1.0 (SUSE Linux).

strace shows that the fd for the pch is closed twice (but not opened twice)
which seems to lead to the error
[pid 20079] stat64("defaults.h.gch", {st_mode=S_IFREG|0644, st_size=9211224,
...}) = 0
[pid 20079] open("defaults.h.gch", O_RDONLY|O_NOCTTY) = 5
....
[pid 20079] close(5)                    = 0
[pid 20079] munmap(0xb7d18000, 4096)    = 0
[pid 20079] close(5)                    = -1 EBADF (Bad file descriptor)

The example from comment #11 leads to the same strace even if you use only
header1.h twice in test.cpp.

I removed all the not needed duplicates. This resolves most of the problems.

In some cases it was not possible to avoid the defaults.h in the headerfiles
because these are automatically generated source files (qt moc) which do not
include the precompiled header from the source so I had to put it in the
corresponding header. 
I used the define from the precompiled header in these headers to avoid the
conflict:
#ifndef __DEFAULTS_H__
#include "defaults.h"
#endif

But at the end I got a problem with the debug version.

As I did not find any duplicate includes in the header and the moc file.
I replaced the gch header by a copy which is not precompiled and the source
compiled succesfully (as expected).
I moved the precompiled header include from the header to the moc file for
testing and it compiled successfully. (suspicious)

Compiling with -v shows the following output:
GNU C++ version 4.1.0 (SUSE Linux) (i586-suse-linux)
        compiled by GNU C version 4.1.0 (SUSE Linux).
GGC heuristics: --param ggc-min-expand=77 --param ggc-min-heapsize=88425
Compiler executable checksum: 96db6faba1662b7eb3475b25f8211ddd
 as -V -Qy -o DrawWindow.moc.o /tmp/ccMxyQj6.s
GNU assembler version 2.17.50.0.6 (i386-redhat-linux-gnu) using BFD version
2.17.50.0.6 20061020
/tmp/ccMxyQj6.s: Assembler messages:
/tmp/ccMxyQj6.s:290: Error: file number 2 already allocated

The error does not occur if I use -g2 instead -g3 for compiling the precompiled
header but still using -g3 for all other files (with strace I see that the
precompiled header is used). But to avoid unpredictable results I'm using now
only -g2 to avoid conflicts.

Use the example from comment #11 to reproduce it without including header1.h in
the test.cpp:
$ cat test.cpp 
#include "header2.h" 

main() 
{ 
} 

compile with:
gcc -g3 -c -o header1.h.gch header1.h
gcc -g3 -c -o test test.cpp

If you use -g2 the bug does not occur.
If you include header1.h directly in test.cpp not via header2.h the bug does
not occur.

Is this a bug of "gcc" causing "as" to fail or a bug of "as"?
I will report it as a new bug if someone can check to whom it belongs.


-- 

l dot bermes at eurokey dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |l dot bermes at eurokey dot
                   |                            |de


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]