[lto]: patch committed and new bug.

Jim Blandy jimb@codesourcery.com
Fri Sep 7 01:25:00 GMT 2007


Mark Mitchell <mark@codesourcery.com> writes:
> Jim Blandy wrote:
>
>> There's nothing in the DWARF information that indicates whether a
>> given variable has an initializer or not.  The current reader code
>> seems to assume that if a die isn't a declaration, then it must have
>> an initializer.  Is the intent that the absence of an appropriately
>> named ELF section indicates the absence of an initializer, or should
>> there be some positive indication in the DIE itself --- perhaps an
>> LTO-specific DWARF attribute?  Do I get to decide?
>
> There was no intent.  I forgot to think of this case.
>
> Yes, you get to decide.  My vote, though, is that we interpret lack of
> the ELF section as absence of an initializer.  That's not maximally
> consistency-checking-est, but it's easiest to implement.  And, we're
> trying not to make LTO files bigger than they need be, so we can justify
> our laziness as optimization.

How does the patch below look?  With it, Kenny's test program
compiles.  lto1 dies reading initializer for statically initialized
variables, which seems to be a separate problem.

$ make b.o
../../bin/gcc -O2 -flto -save-temps   -c -o b.o b.c
$ touch b.c
$ cat b.c
mstruct foo_
{
  int a;
  int b;
} foo = { 1, 2 };
$ touch b.c
$ cat b.c
struct foo_
{
  int a;
  int b;
} foo = { 1, 2 };
$ make b.o
../../bin/gcc -O2 -flto -save-temps   -c -o b.o b.c
$ ../../lto/gcc/lto1 -O2 b.o -o b.o.o
stream failure: looking for a '(' in the debug stream.
However the data translated into a 'i' at position2

     0   -->><<--
     1   -->>init<<--
             ^
             |
     6   -->>(constructor:typeU0x0flagsU0x1U0x2<<--
    41   -->> (integer_cst:typeU0x1flagsU0x4S0x1)<<--
    78   -->><<--
    79   -->> (integer_cst:typeU0x1flagsU0x4S0x2)<<--
   116   -->>)<<--
   118   -->>U0x0b.o:0: internal compiler error: in debug_out_fun, at lto/lto-read.c:1748
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
$ 


gcc/lto/ChangeLog:
2007-09-06  Jim Blandy  <jimb@codesourcery.com>

	* lto.c (lto_read_variable_formal_parameter_constant_DIE): If we
	can't find a var init for this variable, leave its DECL_INITIAL.
	* lto-elf.c (lto_elf_map_optional_lto_section): Renamed from
	lto_elf_map_fn_body.
	(lto_map_lto_section): New function.
	(lto_elf_file_vtable): Use lto_elf_map_lto_section for function
	bodies, and lto_elf_map_optional_lto_section for variable
	initializers.
	(lto_elf_find_section_data): Quietly return NULL if the section is
	missing.
	(lto_elf_file_open): Check for a NULL from lto_elf_find_section_data.

	* lto-elf.c (lto_elf_find_section_data): Remove dead code.

Index: gcc/lto/lto.c
===================================================================
--- gcc/lto/lto.c	(revision 128207)
+++ gcc/lto/lto.c	(working copy)
@@ -2047,8 +2047,11 @@
 	      name_str = IDENTIFIER_POINTER (asm_name);
 	      file = fd->base.file;
 	      init = file->vtable->map_var_init (file, name_str);
-	      lto_read_var_init (fd, context, decl, init);
-	      file->vtable->unmap_var_init (file, name_str, init);
+              if (init)
+                {
+                  lto_read_var_init (fd, context, decl, init);
+                  file->vtable->unmap_var_init (file, name_str, init);
+                }
 	    }
 	  /* If this variable has already been declared, merge the
 	     declarations.  */
Index: gcc/lto/lto-elf.c
===================================================================
--- gcc/lto/lto-elf.c	(revision 128207)
+++ gcc/lto/lto-elf.c	(working copy)
@@ -60,16 +60,19 @@
 /* Forward Declarations */
 
 static const void *
-lto_elf_map_fn_body (lto_file *file, const char *fn);
+lto_elf_map_lto_section (lto_file *file, const char *id);
 
+static const void *
+lto_elf_map_optional_lto_section (lto_file *file, const char *id);
+
 static void
 lto_elf_unmap_fn_body (lto_file *file, const char *fn, const void *data);
 
 /* The vtable for ELF input files.  */
 static const lto_file_vtable lto_elf_file_vtable = {
-  lto_elf_map_fn_body,
+  lto_elf_map_lto_section,
   lto_elf_unmap_fn_body,
-  lto_elf_map_fn_body,
+  lto_elf_map_optional_lto_section,
   lto_elf_unmap_fn_body
 };
 
@@ -127,9 +130,10 @@
     free (shdr);
 }
 
-/* A helper function to find the section named SECTION_NAME in ELF_FILE, and
-   return its data.  Emits an appropriate error message and returns NULL
-   if a unique section with that name is not found.  */
+/* A helper function to find the section named SECTION_NAME in
+   ELF_FILE, and return its data.  If we can't find a section by that
+   name, return NULL, but don't report an error.  If anything else
+   goes wrong, report an error and return NULL.  */
 
 static Elf_Data *
 lto_elf_find_section_data (lto_elf_file *elf_file, const char *section_name)
@@ -146,12 +150,6 @@
       size_t offset;
       const char *name;
 
-      if (!section)
-	{
-	  error ("could not read section information: %s", elf_errmsg (0));
-	  return NULL;
-	}
-
       /* Get the name of this section.  */
       shdr = lto_elf_get_shdr (elf_file, section);
       offset = shdr->sh_name;
@@ -179,10 +177,7 @@
 	}
     }
   if (! result)
-    {
-      error ("missing %qs section", section_name);
-      return NULL;
-    }
+    return NULL;
 
   data = elf_getdata (result, NULL);
   if (!data)
@@ -396,14 +391,22 @@
   /* Find the .debug_info and .debug_abbrev sections.  */
   data = lto_elf_find_section_data (elf_file, ".debug_info");
   if (!data)
-    goto fail;
+    {
+      error ("could not read %qs section: %s",
+             ".debug_info", elf_errmsg (0));
+      goto fail;
+    }
   fd = (lto_fd *) &result->debug_info;
   fd->start = (const char *) data->d_buf;
   fd->end = fd->start + data->d_size;
 
   data = lto_elf_find_section_data (elf_file, ".debug_abbrev");
   if (!data)
-    goto fail;
+    {
+      error ("could not read %qs section: %s", 
+             ".debug_abbrev", elf_errmsg (0));
+      goto fail;
+    }
   fd = (lto_fd *) &result->debug_abbrev;
   fd->start = (const char *) data->d_buf;
   fd->end = fd->start + data->d_size;
@@ -429,13 +432,13 @@
   lto_file_close (file);
 }
 
-const void *
-lto_elf_map_fn_body (lto_file *file,
-		     const char *fn)
+static const void *
+lto_elf_map_optional_lto_section (lto_file *file,
+                                  const char *id)
 {
   /* Look in the ELF file to find the actual data, which should be
      in the section named LTO_SECTION_NAME_PREFIX || "the function name".  */
-  const char *name = concat (LTO_SECTION_NAME_PREFIX, fn, NULL);
+  const char *name = concat (LTO_SECTION_NAME_PREFIX, id, NULL);
   Elf_Data *data = lto_elf_find_section_data ((lto_elf_file *)file, name);
 
   free ((void *)name);
@@ -446,7 +449,21 @@
     return (const void *)(data->d_buf);
 }
 
-void
+/* Like lto_elf_map_optional_lto_section, but report an error
+   if the section is not present.  */
+static const void *
+lto_elf_map_lto_section (lto_file *file,
+                         const char *id)
+{
+  const void *data = lto_elf_map_optional_lto_section (file, id);
+
+  if (! data)
+    error ("unable to find LTO data for %qs: %s", id, elf_errmsg (0));
+
+  return data;
+}
+
+static void
 lto_elf_unmap_fn_body (lto_file *file ATTRIBUTE_UNUSED, 
 		       const char *fn ATTRIBUTE_UNUSED, 
 		       const void *data ATTRIBUTE_UNUSED)



More information about the Gcc-patches mailing list