Patchwork [5/5] Add error checking to lto_section_read

login
register
mail settings
Submitter Andi Kleen
Date Oct. 9, 2011, 7:55 p.m.
Message ID <1318190141-1220-6-git-send-email-andi@firstfloor.org>
Download mbox | patch
Permalink /patch/118618/
State New
Headers show

Comments

Andi Kleen - Oct. 9, 2011, 7:55 p.m.
From: Andi Kleen <ak@linux.intel.com>

Various callers of lto_section_read segfault on a NULL return
when the mmap fails. Add some internal_errors to give a better
message to the user.

gcc/lto/:

2011-10-09   Andi Kleen <ak@linux.intel.com>

	* lto.c (lto_section_read): Call internal_error on IO or mmap errors.
---
 gcc/lto/lto.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
Richard Guenther - Oct. 10, 2011, 10:16 a.m.
On Sun, Oct 9, 2011 at 9:55 PM, Andi Kleen <andi@firstfloor.org> wrote:
> From: Andi Kleen <ak@linux.intel.com>
>
> Various callers of lto_section_read segfault on a NULL return
> when the mmap fails. Add some internal_errors to give a better
> message to the user.

Hm, shouldn't these be fatal_error () then?  Ok with that change.

Thanks,
Richard.

> gcc/lto/:
>
> 2011-10-09   Andi Kleen <ak@linux.intel.com>
>
>        * lto.c (lto_section_read): Call internal_error on IO or mmap errors.
> ---
>  gcc/lto/lto.c |   11 +++++++++--
>  1 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
> index a77eeb4..dc16db4 100644
> --- a/gcc/lto/lto.c
> +++ b/gcc/lto/lto.c
> @@ -1237,7 +1237,10 @@ lto_read_section_data (struct lto_file_decl_data *file_data,
>     {
>       fd = open (file_data->file_name, O_RDONLY|O_BINARY);
>       if (fd == -1)
> -       return NULL;
> +        {
> +         internal_error ("Cannot open %s", file_data->file_name);
> +         return NULL;
> +        }
>       fd_name = xstrdup (file_data->file_name);
>     }
>
> @@ -1255,7 +1258,10 @@ lto_read_section_data (struct lto_file_decl_data *file_data,
>   result = (char *) mmap (NULL, computed_len, PROT_READ, MAP_PRIVATE,
>                          fd, computed_offset);
>   if (result == MAP_FAILED)
> -    return NULL;
> +    {
> +      internal_error ("Cannot map %s", file_data->file_name);
> +      return NULL;
> +    }
>
>   return result + diff;
>  #else
> @@ -1264,6 +1270,7 @@ lto_read_section_data (struct lto_file_decl_data *file_data,
>       || read (fd, result, len) != (ssize_t) len)
>     {
>       free (result);
> +      internal_error ("Cannot read %s", file_data->file_name);
>       result = NULL;
>     }
>  #ifdef __MINGW32__
> --
> 1.7.5.4
>
>

Patch

diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
index a77eeb4..dc16db4 100644
--- a/gcc/lto/lto.c
+++ b/gcc/lto/lto.c
@@ -1237,7 +1237,10 @@  lto_read_section_data (struct lto_file_decl_data *file_data,
     {
       fd = open (file_data->file_name, O_RDONLY|O_BINARY);
       if (fd == -1)
-	return NULL;
+        {
+	  internal_error ("Cannot open %s", file_data->file_name);
+	  return NULL;
+        }
       fd_name = xstrdup (file_data->file_name);
     }
 
@@ -1255,7 +1258,10 @@  lto_read_section_data (struct lto_file_decl_data *file_data,
   result = (char *) mmap (NULL, computed_len, PROT_READ, MAP_PRIVATE,
 			  fd, computed_offset);
   if (result == MAP_FAILED)
-    return NULL;
+    {
+      internal_error ("Cannot map %s", file_data->file_name);
+      return NULL;
+    }
 
   return result + diff;
 #else
@@ -1264,6 +1270,7 @@  lto_read_section_data (struct lto_file_decl_data *file_data,
       || read (fd, result, len) != (ssize_t) len)
     {
       free (result);
+      internal_error ("Cannot read %s", file_data->file_name);
       result = NULL;
     }
 #ifdef __MINGW32__