[Bug pch/15316] New: Precompiled headers fail on Cygwin due to mmap() behavior
pgonzalez at bluel dot com
gcc-bugzilla@gcc.gnu.org
Thu May 6 12:39:00 GMT 2004
I executed these commmands (using the files at the bottom of this note):
g++ -Winvalid-pch -x c++-header test.h
g++ -Winvalid-pch test.cpp -c
And I got this error:
test.cpp:1: sorry, unimplemented: had to relocate PCH
test.cpp:1: confused by earlier errors, bailing out
In the function gt_pch_save() in gcc/gcc-common.c, there is
this code:
mmi.offset = page_size - o % page_size;
if (mmi.offset == page_size)
mmi.offset = 0;
mmi.offset += o;
The gt_pch_save() function calls mmap() to guess the address that
mmap() will return later in gt_pch_restore(). It's important that
this guess is correct, since otherwise all the pointers will have
to be adjusted when the memory dump is reloaded, which is apparently
so undesirable that it is treated as an error ("had to relocate PCH").
The above code is a kludge to fixup the guess, since mmi.offset was
not known when mmap() was called. (A cleaner approach would
be to compute mmi.offset before mmi.preferred_base, but this is
nontrivial.)
Anyway, the bug is that on Windows XP, the memory mapped file pages
are NOT the same as "page_size". Specifically, the former is 64k,
whereas the latter is 4k. Thus, the guess to almost always incorrect,
so the PCH feature does not work at all. I tried replacing all
instances of page_size in the above expression with 0x10000 and
that fixed the problem. A more portable approach would be to use
dwAllocationGranularity from the Win32 GetSystemInfo(), but this
would need to be abstracted for the Cygwin/Mingw target somehow.
(Note that the host_hooks.gt_pch_get_address abstraction is not
being utilized at all here, which is why I called this code a
"kludge".)
Anyway, if you want PCH working on Cygwin, this is the information
necessary to fix it.
(Bug 11324 was marked as duplicate of another ICE, but my guess is
that it's actually caused by this PCH bug. The ggc-common.c code
assumes that mmap() succeeds (and that HAVE_MMAP_FILE is defined);
if not, there are cases where no error is reported and dangling
pointers are accessed.)
-------[test.h]-------
extern int x;
-------[test.cpp]-----
#include "test.h"
int test() {
return x;
}
--
Summary: Precompiled headers fail on Cygwin due to mmap()
behavior
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: pch
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: pgonzalez at bluel dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-cygwin
GCC host triplet: i686-pc-cygwin
GCC target triplet: arm-arm-elf
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15316
More information about the Gcc-bugs
mailing list