Patchwork Improve handling of missing LTO input sections

login
register
mail settings
Submitter Andi Kleen
Date Oct. 2, 2010, 9:24 p.m.
Message ID <1286054664-20236-1-git-send-email-andi@firstfloor.org>
Download mbox | patch
Permalink /patch/66585/
State New
Headers show

Comments

Andi Kleen - Oct. 2, 2010, 9:24 p.m.
From: Andi Kleen <ak@linux.intel.com>

Avoid some segfaults in this case and replace one assert with
a clearer error message.

Passes bootstrap and test on x86-64-linux.

Ok to commit?

gcc/

2010-10-02  Andi Kleen <ak@linux.intel.com>

	* lto-cgraph.c (input_cgraph): Check for missing sections.

gcc/lto/

2010-10-02  Andi Kleen <ak@linux.intel.com>

	* lto.c (lto_file_finalize): Replace gcc_assert for missing section
        with fatal_error.
---
 gcc/lto-cgraph.c |    6 ++++++
 gcc/lto/lto.c    |    6 +++++-
 2 files changed, 11 insertions(+), 1 deletions(-)
Richard Guenther - Oct. 3, 2010, 3:35 p.m.
On Sat, Oct 2, 2010 at 11:24 PM, Andi Kleen <andi@firstfloor.org> wrote:
> From: Andi Kleen <ak@linux.intel.com>
>
> Avoid some segfaults in this case and replace one assert with
> a clearer error message.
>
> Passes bootstrap and test on x86-64-linux.
>
> Ok to commit?

Ok.

Thanks,
Richard.

> gcc/
>
> 2010-10-02  Andi Kleen <ak@linux.intel.com>
>
>        * lto-cgraph.c (input_cgraph): Check for missing sections.
>
> gcc/lto/
>
> 2010-10-02  Andi Kleen <ak@linux.intel.com>
>
>        * lto.c (lto_file_finalize): Replace gcc_assert for missing section
>        with fatal_error.
> ---
>  gcc/lto-cgraph.c |    6 ++++++
>  gcc/lto/lto.c    |    6 +++++-
>  2 files changed, 11 insertions(+), 1 deletions(-)
>
> diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c
> index b82fa73..b61e5d1 100644
> --- a/gcc/lto-cgraph.c
> +++ b/gcc/lto-cgraph.c
> @@ -1468,6 +1468,8 @@ input_cgraph (void)
>
>       ib = lto_create_simple_input_block (file_data, LTO_section_cgraph,
>                                          &data, &len);
> +      if (!ib)
> +       fatal_error ("Cannot find LTO cgraph in %s\n", file_data->file_name);
>       input_profile_summary (ib);
>       file_data->cgraph_node_encoder = lto_cgraph_encoder_new ();
>       nodes = input_cgraph_1 (file_data, ib);
> @@ -1476,12 +1478,16 @@ input_cgraph (void)
>
>       ib = lto_create_simple_input_block (file_data, LTO_section_varpool,
>                                          &data, &len);
> +      if (!ib)
> +       fatal_error ("Cannot find LTO varpool in %s\n", file_data->file_name);
>       varpool = input_varpool_1 (file_data, ib);
>       lto_destroy_simple_input_block (file_data, LTO_section_varpool,
>                                      ib, data, len);
>
>       ib = lto_create_simple_input_block (file_data, LTO_section_refs,
>                                          &data, &len);
> +      if (!ib)
> +       fatal_error("Cannot find LTO section refs in %s\n", file_data->file_name);
>       input_refs (ib, nodes, varpool);
>       lto_destroy_simple_input_block (file_data, LTO_section_refs,
>                                      ib, data, len);
> diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
> index e2fa975..2fbea73 100644
> --- a/gcc/lto/lto.c
> +++ b/gcc/lto/lto.c
> @@ -493,7 +493,11 @@ lto_file_finalize (struct lto_file_decl_data *file_data, lto_file *file)
>   file_data->renaming_hash_table = lto_create_renaming_table ();
>   file_data->file_name = file->filename;
>   data = lto_get_section_data (file_data, LTO_section_decls, NULL, &len);
> -  gcc_assert (data != NULL);
> +  if (data == NULL)
> +    {
> +      internal_error ("Cannot read LTO decls from %s", file_data->file_name);
> +      return;
> +    }
>   lto_read_decls (file_data, data, file_data->resolutions);
>   lto_free_section_data (file_data, LTO_section_decls, NULL, data, len);
>  }
> --
> 1.7.1
>
>

Patch

diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c
index b82fa73..b61e5d1 100644
--- a/gcc/lto-cgraph.c
+++ b/gcc/lto-cgraph.c
@@ -1468,6 +1468,8 @@  input_cgraph (void)
 
       ib = lto_create_simple_input_block (file_data, LTO_section_cgraph,
 					  &data, &len);
+      if (!ib) 
+	fatal_error ("Cannot find LTO cgraph in %s\n", file_data->file_name);
       input_profile_summary (ib);
       file_data->cgraph_node_encoder = lto_cgraph_encoder_new ();
       nodes = input_cgraph_1 (file_data, ib);
@@ -1476,12 +1478,16 @@  input_cgraph (void)
 
       ib = lto_create_simple_input_block (file_data, LTO_section_varpool,
 					  &data, &len);
+      if (!ib)
+	fatal_error ("Cannot find LTO varpool in %s\n", file_data->file_name);
       varpool = input_varpool_1 (file_data, ib);
       lto_destroy_simple_input_block (file_data, LTO_section_varpool,
 				      ib, data, len);
 
       ib = lto_create_simple_input_block (file_data, LTO_section_refs,
 					  &data, &len);
+      if (!ib)
+	fatal_error("Cannot find LTO section refs in %s\n", file_data->file_name);
       input_refs (ib, nodes, varpool);
       lto_destroy_simple_input_block (file_data, LTO_section_refs,
 				      ib, data, len);
diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
index e2fa975..2fbea73 100644
--- a/gcc/lto/lto.c
+++ b/gcc/lto/lto.c
@@ -493,7 +493,11 @@  lto_file_finalize (struct lto_file_decl_data *file_data, lto_file *file)
   file_data->renaming_hash_table = lto_create_renaming_table ();
   file_data->file_name = file->filename;
   data = lto_get_section_data (file_data, LTO_section_decls, NULL, &len);
-  gcc_assert (data != NULL);
+  if (data == NULL)
+    {
+      internal_error ("Cannot read LTO decls from %s", file_data->file_name);
+      return;
+    }
   lto_read_decls (file_data, data, file_data->resolutions);
   lto_free_section_data (file_data, LTO_section_decls, NULL, data, len);
 }