The following tries to cure random plugin claim failures I see when
building in KVM (still to be verified that this is the actual problem).
It seems that lto-plugin and simple-object fail to handle short reads
and read returning EINTR which the following fixes by teaching that
to simple_object_internal_read and using that from lto-plugin.c.

(LTO) Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Ok for trunk and branches?

(yes, simple_object_write would have the same issue - I'll fix that
as a followup if it turns out to fix the KVM build issues).

Thanks,
Richard.

2014-03-26  Richard Biener  <rguent...@suse.de>

        libiberty/
        * simple-object.c (simple_object_internal_read): Handle
        EINTR and short reads.

        lto-plugin/
        * lto-plugin.c (process_symtab): Use simple_object_internal_read.

Index: libiberty/simple-object.c
===================================================================
--- libiberty/simple-object.c   (revision 208812)
+++ libiberty/simple-object.c   (working copy)
@@ -72,15 +72,25 @@ simple_object_internal_read (int descrip
       return 0;
     }
 
-  got = read (descriptor, buffer, size);
-  if (got < 0)
+  do
     {
-      *errmsg = "read";
-      *err = errno;
-      return 0;
+      got = read (descriptor, buffer, size);
+      if (got < 0
+         && errno != EINTR)
+       {
+         *errmsg = "read";
+         *err = errno;
+         return 0;
+       }
+      else
+       {
+         buffer += got;
+         size -= got;
+       }
     }
+  while (got != 0 && size > 0);
 
-  if ((size_t) got < size)
+  if (size > 0)
     {
       *errmsg = "file too short";
       *err = 0;
Index: lto-plugin/lto-plugin.c
===================================================================
--- lto-plugin/lto-plugin.c     (revision 208812)
+++ lto-plugin/lto-plugin.c     (working copy)
@@ -818,6 +818,8 @@ process_symtab (void *data, const char *
   struct plugin_objfile *obj = (struct plugin_objfile *)data;
   char *s;
   char *secdata;
+  char *errmsg;
+  int err;
 
   if (strncmp (name, LTO_SECTION_PREFIX, LTO_SECTION_PREFIX_LEN) != 0)
     return 1;
@@ -827,8 +829,8 @@ process_symtab (void *data, const char *
     sscanf (s, ".%" PRI_LL "x", &obj->out->id);
   secdata = xmalloc (length);
   offset += obj->file->offset;
-  if (offset != lseek (obj->file->fd, offset, SEEK_SET)
-       || length != read (obj->file->fd, secdata, length))
+  if (!simple_object_internal_read (obj->file->fd, offset,
+                                   secdata, length, &errmsg, &err))
     {
       if (message)
        message (LDPL_FATAL, "%s: corrupt object file", obj->file->name);

Reply via email to