summaryrefslogtreecommitdiff
path: root/gcc/ggc-common.c
diff options
context:
space:
mode:
authorgeoffk <geoffk@138bc75d-0d04-0410-961f-82ee72b054a4>2003-07-29 23:36:53 +0000
committergeoffk <geoffk@138bc75d-0d04-0410-961f-82ee72b054a4>2003-07-29 23:36:53 +0000
commitddf4604f819bef7998a0849d258f0084775d7339 (patch)
treea81081c458d46be162c522a5f484e4265c5c1d47 /gcc/ggc-common.c
parent1824e2bdf8fefbcefbe05c7555628be245d5ce4e (diff)
downloadgcc-ddf4604f819bef7998a0849d258f0084775d7339.tar.gz
2003-07-29 Geoffrey Keating <geoffk@apple.com>
* c-common.c (allow_pch): Remove. * c-common.h (allow_pch): Remove. (c_common_no_more_pch): Declare. * c-lex.c (c_lex): Call c_common_no_more_pch when appropriate. * c-pch.c: Include hosthooks.h. (c_common_valid_pch): Don't check allow_pch. (c_common_read_pch): Clear valid_pch to prevent reading PCH files. (c_common_no_more_pch): New. * ggc-common.c: Include hosthooks.h. (gt_pch_save): Call gt_pch_get_address. (gt_pch_restore): Call gt_pch_use_address. * hooks.c (hook_voidp_size_t_null): New. (hook_bool_voidp_size_t_false): New. * hooks.h (hook_voidp_size_t_null): New. (hook_bool_voidp_size_t_false): New. * hosthooks-def.h (HOST_HOOKS_GT_PCH_GET_ADDRESS): New. (HOST_HOOKS_GT_PCH_USE_ADDRESS): New. (HOST_HOOKS_INITIALIZER): Add HOST_HOOKS_GT_PCH_GET_ADDRESS, HOST_HOOKS_GT_PCH_USE_ADDRESS. * hosthooks.h (struct host_hooks): Add gt_pch_get_address, gt_pch_use_address. * doc/hostconfig.texi (Host Common): Document HOST_HOOKS_GT_PCH_GET_ADDRESS, HOST_HOOKS_GT_PCH_USE_ADDRESS. * Makefile.in (c-pch.o): Depend on hosthooks.h. (ggc-common.o): Likewise. * config/rs6000/host-darwin.c (HOST_HOOKS_GT_PCH_GET_ADDRESS): Define. (HOST_HOOKS_GT_PCH_USE_ADDRESS): Define. (pch_address_space): New. (darwin_rs6000_gt_pch_get_address): New. (darwin_rs6000_gt_pch_use_address): New. Index: cp/ChangeLog 2003-07-29 Geoffrey Keating <geoffk@apple.com> * parser.c (cp_lexer_new_main): Use c_common_no_more_pch instead of setting valid_pch by hand. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@69944 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ggc-common.c')
-rw-r--r--gcc/ggc-common.c125
1 files changed, 80 insertions, 45 deletions
diff --git a/gcc/ggc-common.c b/gcc/ggc-common.c
index 3163c15f83b..284811878de 100644
--- a/gcc/ggc-common.c
+++ b/gcc/ggc-common.c
@@ -29,6 +29,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#include "ggc.h"
#include "toplev.h"
#include "params.h"
+#include "hosthooks.h"
#ifdef HAVE_SYS_RESOURCE_H
# include <sys/resource.h>
@@ -450,19 +451,24 @@ gt_pch_save (FILE *f)
mmi.size = ggc_pch_total_size (state.d);
- /* Try to arrange things so that no relocation is necessary,
- but don't try very hard. On most platforms, this will always work,
- and on the rest it's a lot of work to do better. */
+ /* Try to arrange things so that no relocation is necessary, but
+ don't try very hard. On most platforms, this will always work,
+ and on the rest it's a lot of work to do better.
+ (The extra work goes in HOST_HOOKS_GT_PCH_GET_ADDRESS and
+ HOST_HOOKS_GT_PCH_USE_ADDRESS.) */
+ mmi.preferred_base = host_hooks.gt_pch_get_address (mmi.size);
+
#if HAVE_MMAP_FILE
- mmi.preferred_base = mmap (NULL, mmi.size,
- PROT_READ | PROT_WRITE, MAP_PRIVATE,
- fileno (state.f), 0);
- if (mmi.preferred_base == (void *) MAP_FAILED)
- mmi.preferred_base = NULL;
- else
- munmap (mmi.preferred_base, mmi.size);
-#else /* HAVE_MMAP_FILE */
- mmi.preferred_base = NULL;
+ if (mmi.preferred_base == NULL)
+ {
+ mmi.preferred_base = mmap (NULL, mmi.size,
+ PROT_READ | PROT_WRITE, MAP_PRIVATE,
+ fileno (state.f), 0);
+ if (mmi.preferred_base == (void *) MAP_FAILED)
+ mmi.preferred_base = NULL;
+ else
+ munmap (mmi.preferred_base, mmi.size);
+ }
#endif /* HAVE_MMAP_FILE */
ggc_pch_this_base (state.d, mmi.preferred_base);
@@ -539,6 +545,7 @@ gt_pch_restore (FILE *f)
size_t i;
struct mmap_info mmi;
void *addr;
+ bool needs_read;
/* Delete any deletable objects. This makes ggc_pch_read much
faster, as it can be sure that no GCable objects remain other
@@ -571,47 +578,75 @@ gt_pch_restore (FILE *f)
if (fread (&mmi, sizeof (mmi), 1, f) != 1)
fatal_error ("can't read PCH file: %m");
+ if (host_hooks.gt_pch_use_address (mmi.preferred_base, mmi.size))
+ {
#if HAVE_MMAP_FILE
- addr = mmap (mmi.preferred_base, mmi.size,
- PROT_READ | PROT_WRITE, MAP_PRIVATE,
- fileno (f), mmi.offset);
+ void *mmap_result;
-#if HAVE_MINCORE
- if (addr != mmi.preferred_base)
- {
- size_t page_size = getpagesize();
- char one_byte;
-
- if (addr != (void *) MAP_FAILED)
- munmap (addr, mmi.size);
-
- /* We really want to be mapped at mmi.preferred_base
- so we're going to resort to MAP_FIXED. But before,
- make sure that we can do so without destroying a
- previously mapped area, by looping over all pages
- that would be affected by the fixed mapping. */
- errno = 0;
-
- for (i = 0; i < mmi.size; i+= page_size)
- if (mincore ((char *)mmi.preferred_base + i, page_size, (void *)&one_byte) == -1
- && errno == ENOMEM)
- continue; /* The page is not mapped. */
- else
- break;
-
- if (i >= mmi.size)
- addr = mmap (mmi.preferred_base, mmi.size,
- PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED,
- fileno (f), mmi.offset);
+ mmap_result = mmap (mmi.preferred_base, mmi.size,
+ PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED,
+ fileno (f), mmi.offset);
+
+ /* The file might not be mmap-able. */
+ needs_read = mmap_result == MAP_FAILED;
+
+ /* Sanity check for broken MAP_FIXED. */
+ if (! needs_read && mmap_result != mmi.preferred_base)
+ abort ();
+#else
+ needs_read = true;
+#endif
+ addr = mmi.preferred_base;
}
+ else
+ {
+#if HAVE_MMAP_FILE
+ addr = mmap (mmi.preferred_base, mmi.size,
+ PROT_READ | PROT_WRITE, MAP_PRIVATE,
+ fileno (f), mmi.offset);
+
+#if HAVE_MINCORE
+ if (addr != mmi.preferred_base)
+ {
+ size_t page_size = getpagesize();
+ char one_byte;
+
+ if (addr != (void *) MAP_FAILED)
+ munmap (addr, mmi.size);
+
+ /* We really want to be mapped at mmi.preferred_base
+ so we're going to resort to MAP_FIXED. But before,
+ make sure that we can do so without destroying a
+ previously mapped area, by looping over all pages
+ that would be affected by the fixed mapping. */
+ errno = 0;
+
+ for (i = 0; i < mmi.size; i+= page_size)
+ if (mincore ((char *)mmi.preferred_base + i, page_size,
+ (void *)&one_byte) == -1
+ && errno == ENOMEM)
+ continue; /* The page is not mapped. */
+ else
+ break;
+
+ if (i >= mmi.size)
+ addr = mmap (mmi.preferred_base, mmi.size,
+ PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_FIXED,
+ fileno (f), mmi.offset);
+ }
#endif /* HAVE_MINCORE */
+
+ needs_read = addr == (void *) MAP_FAILED;
#else /* HAVE_MMAP_FILE */
- addr = MAP_FAILED;
+ needs_read = true;
#endif /* HAVE_MMAP_FILE */
- if (addr == (void *) MAP_FAILED)
+ if (needs_read)
+ addr = xmalloc (mmi.size);
+ }
+
+ if (needs_read)
{
- addr = xmalloc (mmi.size);
if (fseek (f, mmi.offset, SEEK_SET) != 0
|| fread (&mmi, mmi.size, 1, f) != 1)
fatal_error ("can't read PCH file: %m");