public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "xricht17 at stud dot fit.vutbr.cz" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug pch/14940] PCH largefile test fails on various platforms
Date: Thu, 09 Jul 2015 18:47:00 -0000	[thread overview]
Message-ID: <bug-14940-4-4hpm0BKao2@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-14940-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #50 from Martin Richter <xricht17 at stud dot fit.vutbr.cz> ---
The following patch fixes segfault when gt_pch_use_address fails (returns -1).
fatal_error now correctly shows an error message and terminates the program.
I have basicly only reordered reads, and placed them after the file mapping
itself. Global pointers are changed only after gt_pch_use_address succeeds, so
in case of failure they still contain valid addresses.

This patch is meant for the master branch. However, it should not be hard to
modify it for others.


diff --git a/gcc/ggc-common.c b/gcc/ggc-common.c
index 5096837..f741f2c 100644
--- a/gcc/ggc-common.c
+++ b/gcc/ggc-common.c
@@ -599,7 +599,9 @@ gt_pch_restore (FILE *f)
   size_t i;
   struct mmap_info mmi;
   int result;
-
+  long pch_tabs_off;
+  long pch_data_off;
+  
   /* Delete any deletable objects.  This makes ggc_pch_read much
      faster, as it can be sure that no GCable objects remain other
      than the ones just read in.  */
@@ -607,20 +609,24 @@ gt_pch_restore (FILE *f)
     for (rti = *rt; rti->base != NULL; rti++)
       memset (rti->base, 0, rti->stride);

-  /* Read in all the scalar variables.  */
+  /* We need to read tables after mapping, or fatal_error will
+     segfault when gt_pch_use_address returns -1. Skip them for now. */
+  pch_tabs_off = ftell(f);
+     
+  /* Skip all the scalar variables. */
   for (rt = gt_pch_scalar_rtab; *rt; rt++)
     for (rti = *rt; rti->base != NULL; rti++)
-      if (fread (rti->base, rti->stride, 1, f) != 1)
-       fatal_error (input_location, "can%'t read PCH file: %m");
+      if (fseek (f, rti->stride, SEEK_CUR) != 0)
+        fatal_error (input_location, "can%'t read PCH file: %m");

-  /* Read in all the global pointers, in 6 easy loops.  */
+  /* Skip all the global pointers. */
   for (rt = gt_ggc_rtab; *rt; rt++)
     for (rti = *rt; rti->base != NULL; rti++)
       for (i = 0; i < rti->nelt; i++)
-       if (fread ((char *)rti->base + rti->stride * i,
-                  sizeof (void *), 1, f) != 1)
-         fatal_error (input_location, "can%'t read PCH file: %m");
-
+        if (fseek (f, sizeof (void *), SEEK_CUR) != 0)
+          fatal_error (input_location, "can%'t read PCH file: %m");
+          
+  /* mmi still has to be read now. */          
   if (fread (&mmi, sizeof (mmi), 1, f) != 1)
     fatal_error (input_location, "can%'t read PCH file: %m");

@@ -631,12 +637,35 @@ gt_pch_restore (FILE *f)
   if (result == 0)
     {
       if (fseek (f, mmi.offset, SEEK_SET) != 0
-         || fread (mmi.preferred_base, mmi.size, 1, f) != 1)
-       fatal_error (input_location, "can%'t read PCH file: %m");
+          || fread (mmi.preferred_base, mmi.size, 1, f) != 1)
+        fatal_error (input_location, "can%'t read PCH file: %m");
     }
   else if (fseek (f, mmi.offset + mmi.size, SEEK_SET) != 0)
     fatal_error (input_location, "can%'t read PCH file: %m");
+    
+  /* File mapping done, read tables now. */
+  pch_data_off = ftell(f);
+  
+  if (fseek (f, pch_tabs_off, SEEK_SET) != 0)
+    fatal_error (input_location, "can%'t read PCH file: %m");

+  /* Read in all the scalar variables.  */
+  for (rt = gt_pch_scalar_rtab; *rt; rt++)
+    for (rti = *rt; rti->base != NULL; rti++)
+      if (fread (rti->base, rti->stride, 1, f) != 1)
+        fatal_error (input_location, "can%'t read PCH file: %m");
+
+  /* Read in all the global pointers, in 6 easy loops.  */
+  for (rt = gt_ggc_rtab; *rt; rt++)
+    for (rti = *rt; rti->base != NULL; rti++)
+      for (i = 0; i < rti->nelt; i++)
+        if (fread ((char *)rti->base + rti->stride * i,
+            sizeof (void *), 1, f) != 1)
+          fatal_error (input_location, "can%'t read PCH file: %m");
+
+  if (fseek (f, pch_data_off, SEEK_SET) != 0)
+    fatal_error (input_location, "can%'t read PCH file: %m");
+            
   ggc_pch_read (f, mmi.preferred_base);

   gt_pch_restore_stringpool ();


  parent reply	other threads:[~2015-07-09 18:47 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-14940-4@http.gcc.gnu.org/bugzilla/>
2011-02-15  9:52 ` ro at gcc dot gnu.org
2011-02-15  9:58 ` ro at gcc dot gnu.org
2011-02-15 10:09 ` ro at gcc dot gnu.org
2015-05-31  6:22 ` asmwarrior at gmail dot com
2015-06-27 18:28 ` xricht17 at stud dot fit.vutbr.cz
2015-06-28  8:53 ` asmwarrior at gmail dot com
2015-07-09 18:47 ` xricht17 at stud dot fit.vutbr.cz [this message]
2020-11-11 15:30 ` julien.ruffin at ivu dot de
2021-05-19 17:37 ` redi at gcc dot gnu.org
2022-05-10  4:52 ` lh_mouse at 126 dot com
2022-05-10  4:59 ` pinskia at gcc dot gnu.org
2022-05-10  5:05 ` lh_mouse at 126 dot com
2022-05-10  5:15 ` pinskia at gcc dot gnu.org
2022-05-10  8:51 ` jakub at gcc dot gnu.org
2023-03-01 13:47 ` cvs-commit at gcc dot gnu.org
     [not found] <bug-14940-1313@http.gcc.gnu.org/bugzilla/>
2005-12-14 19:25 ` brett dot albertson at stratech dot com
2007-03-27  3:32 ` mmitchel at gcc dot gnu dot org
2007-05-08 21:06 ` mmitchel at gcc dot gnu dot org
2010-03-01 12:45 ` ro at gcc dot gnu dot org
2010-03-01 14:07 ` ro at gcc dot gnu dot org
2010-03-01 18:18 ` ro at gcc dot gnu dot org
2010-06-02 17:29 ` ro at gcc dot gnu dot org
2010-07-12 11:57 ` ro at gcc dot gnu dot org
2010-07-13  9:06 ` ro at gcc dot gnu dot org
2010-07-13  9:07 ` ro at gcc dot gnu dot org
     [not found] <20040413135721.14940.ian@airs.com>
2005-02-11 12:03 ` jsm28 at gcc dot gnu dot org
2005-02-11 12:48 ` dave at hiauly1 dot hia dot nrc dot ca
2005-02-13 20:05 ` ebotcazou at gcc dot gnu dot org
2005-02-15 23:42 ` cvs-commit at gcc dot gnu dot org
2005-08-02 19:04 ` cvs-commit at gcc dot gnu dot org
2005-08-04 17:41 ` dave at hiauly1 dot hia dot nrc dot ca
2005-08-04 17:54 ` ian at airs dot com
2005-08-04 18:04 ` dave at hiauly1 dot hia dot nrc dot ca
2005-08-07  2:48 ` cvs-commit at gcc dot gnu dot org
2004-04-13 14:48 [Bug pch/14940] New: " ian at wasabisystems dot com
2004-04-13 16:35 ` [Bug pch/14940] " ebotcazou at gcc dot gnu dot org
2004-04-13 16:55 ` pinskia at gcc dot gnu dot org
2004-04-13 19:48 ` geoffk at gcc dot gnu dot org
2004-04-14 18:49 ` ljrittle at gcc dot gnu dot org
2004-07-17  4:09 ` pinskia at gcc dot gnu dot org
2004-07-17  4:10 ` pinskia at gcc dot gnu dot org
2004-07-17  4:21 ` dave at hiauly1 dot hia dot nrc dot ca
2004-07-17 14:20 ` ian at wasabisystems dot com
2004-07-17 14:43 ` ian at wasabisystems dot com
2004-07-17 15:43 ` ebotcazou at gcc dot gnu dot org
2004-07-17 17:10 ` dave at hiauly1 dot hia dot nrc dot ca
2004-07-18 10:00 ` ebotcazou at gcc dot gnu dot org
2004-07-18 12:26 ` ian at wasabisystems dot com
2004-07-18 16:03 ` dave at hiauly1 dot hia dot nrc dot ca
2004-07-20 17:49 ` pinskia at gcc dot gnu dot org
2004-08-21 17:05 ` pinskia at gcc dot gnu dot org
2004-08-31 14:20 ` dave at hiauly1 dot hia dot nrc dot ca
2004-10-12 19:56 ` jgrimm2 at us dot ibm dot com
2004-11-04  4:57 ` phython at gcc dot gnu dot org
2004-11-04  7:09 ` ebotcazou at gcc dot gnu dot org
2004-11-09 12:35 ` cvs-commit at gcc dot gnu dot org
2004-11-23  2:30 ` cvs-commit at gcc dot gnu dot org
2004-11-27 16:57 ` cvs-commit at gcc dot gnu dot org
2004-11-30  3:11 ` cvs-commit 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=bug-14940-4-4hpm0BKao2@http.gcc.gnu.org/bugzilla/ \
    --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).