OSDN Git Service

2009-11-17 Rafael Avila de Espindola <espindola@google.com>
authorespindola <espindola@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 17 Nov 2009 16:00:19 +0000 (16:00 +0000)
committerespindola <espindola@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 17 Nov 2009 16:00:19 +0000 (16:00 +0000)
* lto-elf.c (lto_file_init): Add offset argument.
(lto_elf_file_open): Record the offset.
* lto.c (lto_resolution_read): Change file_name into a lto_file
argument. Check offsets.
(lto_file_read): Update call to lto_resolution_read.
* lto.h (lto_file_struct): Add the offset field.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@154251 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/lto/ChangeLog
gcc/lto/lto-elf.c
gcc/lto/lto.c
gcc/lto/lto.h

index b37c549..54dabf2 100644 (file)
@@ -1,3 +1,12 @@
+2009-11-17  Rafael Avila de Espindola  <espindola@google.com>
+
+       * lto-elf.c (lto_file_init): Add offset argument.
+       (lto_elf_file_open): Record the offset.
+       * lto.c (lto_resolution_read): Change file_name into a lto_file
+       argument. Check offsets.
+       (lto_file_read): Update call to lto_resolution_read.
+       * lto.h (lto_file_struct): Add the offset field.
+
 2009-11-16  Rafael Avila de Espindola  <espindola@google.com>
 
        * lto-elf.c (lto_elf_file_open): Use strtoll to parse the offset.
index bc8e137..368d8d4 100644 (file)
@@ -32,9 +32,10 @@ along with GCC; see the file COPYING3.  If not see
 
 /* Initialize FILE, an LTO file object for FILENAME.  */
 static void
-lto_file_init (lto_file *file, const char *filename)
+lto_file_init (lto_file *file, const char *filename, off_t offset)
 {
   file->filename = filename;
+  file->offset = offset;
 }
 
 /* An ELF file.  */
@@ -542,6 +543,7 @@ lto_elf_file_open (const char *filename, bool writable)
   lto_elf_file *elf_file;
   lto_file *result = NULL;
   off_t offset;
+  off_t header_offset;
   const char *offset_p;
   char *fname;
 
@@ -550,6 +552,7 @@ lto_elf_file_open (const char *filename, bool writable)
     {
       fname = xstrdup (filename);
       offset = 0;
+      header_offset = 0;
     }
   else
     {
@@ -567,13 +570,13 @@ lto_elf_file_open (const char *filename, bool writable)
       /* elf_rand expects the offset to point to the ar header, not the
          object itself. Subtract the size of the ar header (60 bytes).
          We don't uses sizeof (struct ar_hd) to avoid including ar.h */
-      offset -= 60;
+      header_offset = offset - 60;
     }
 
   /* Set up.  */
   elf_file = XCNEW (lto_elf_file);
   result = (lto_file *) elf_file;
-  lto_file_init (result, fname);
+  lto_file_init (result, fname, offset);
   elf_file->fd = -1;
 
   /* Open the file.  */
@@ -603,8 +606,8 @@ lto_elf_file_open (const char *filename, bool writable)
   if (offset != 0)
     {
       Elf *e;
-      off_t t = elf_rand (elf_file->elf, offset);
-      if (t != offset)
+      off_t t = elf_rand (elf_file->elf, header_offset);
+      if (t != header_offset)
         {
           error ("could not seek in archive");
           goto fail;
index 40f3c30..9cb7d65 100644 (file)
@@ -254,7 +254,7 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data,
    size is written to SIZE. */
 
 static VEC(ld_plugin_symbol_resolution_t,heap) *
-lto_resolution_read (FILE *resolution, const char *file_name)
+lto_resolution_read (FILE *resolution, lto_file *file)
 {
   /* We require that objects in the resolution file are in the same
      order as the lto1 command line. */
@@ -268,15 +268,30 @@ lto_resolution_read (FILE *resolution, const char *file_name)
   if (!resolution)
     return NULL;
 
-  name_len = strlen (file_name);
+  name_len = strlen (file->filename);
   obj_name = XNEWVEC (char, name_len + 1);
   fscanf (resolution, " ");   /* Read white space. */
 
   fread (obj_name, sizeof (char), name_len, resolution);
   obj_name[name_len] = '\0';
-  if (strcmp (obj_name, file_name) != 0)
+  if (strcmp (obj_name, file->filename) != 0)
     internal_error ("unexpected file name %s in linker resolution file. "
-                   "Expected %s", obj_name, file_name);
+                   "Expected %s", obj_name, file->filename);
+  if (file->offset != 0)
+    {
+      int t;
+      char offset_p[21];
+      long long offset;
+      t = fscanf (resolution, "@%20s", offset_p);
+      if (t != 1)
+        internal_error ("could not parse file offset");
+      errno = 0;
+      offset = strtoll(offset_p, NULL, 10);
+      if (errno != 0)
+        internal_error ("could not parse file offset");
+      if (offset != file->offset)
+        internal_error ("unexpected offset");
+    }
 
   free (obj_name);
 
@@ -332,7 +347,7 @@ lto_file_read (lto_file *file, FILE *resolution_file)
   size_t len;
   VEC(ld_plugin_symbol_resolution_t,heap) *resolutions;
   
-  resolutions = lto_resolution_read (resolution_file, file->filename);
+  resolutions = lto_resolution_read (resolution_file, file);
 
   file_data = XCNEW (struct lto_file_decl_data);
   file_data->file_name = file->filename;
index cdd1e06..3b92b41 100644 (file)
@@ -28,6 +28,7 @@ typedef struct lto_file_struct
 {
   /* The name of the file.  */
   const char *filename;
+  off_t offset;
 } lto_file;
 
 /* In lto-lang.c  */