This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] archive.c, bsd_write_armap, fail if stat fails


On Thu, Mar 03, 2011 at 03:39:18PM -0800, Michael Snyder wrote:
> Alan Modra wrote:
> >On Thu, Mar 03, 2011 at 10:46:09AM -0800, Michael Snyder wrote:
> >>	* archive.c (bsd_write_armap): Fail if stat fails.
> >
> >I think it would be better to just set the timestamp to zero if stat
> >fails.  There is precedent for this, eg. opncls.c:_maybe_make_executable.
> >
> Err, can I leave that to you?

	* archive.c (bsd_write_armap): Don't call stat in deterministic
	mode, and don't use st_mtime if stat returns error.

Index: bfd/archive.c
===================================================================
RCS file: /cvs/src/src/bfd/archive.c,v
retrieving revision 1.72
diff -u -p -r1.72 archive.c
--- bfd/archive.c	28 Feb 2011 18:30:16 -0000	1.72
+++ bfd/archive.c	4 Mar 2011 00:52:22 -0000
@@ -2299,31 +2299,28 @@ bsd_write_armap (bfd *arch,
   bfd_byte temp[4];
   unsigned int count;
   struct ar_hdr hdr;
-  struct stat statbuf;
   long uid, gid;
 
   firstreal = mapsize + elength + sizeof (struct ar_hdr) + SARMAG;
 
-  stat (arch->filename, &statbuf);
+  /* If deterministic, we use 0 as the timestamp in the map.
+     Some linkers may require that the archive filesystem modification
+     time is less than (or near to) the archive map timestamp.  Those
+     linkers should not be used with deterministic mode.  (GNU ld and
+     Gold do not have this restriction.)  */
+  bfd_ardata (arch)->armap_timestamp = 0;
+  uid = 0;
+  gid = 0;
   if ((arch->flags & BFD_DETERMINISTIC_OUTPUT) == 0)
     {
-      /* Remember the timestamp, to keep it holy.  But fudge it a little.  */
-      bfd_ardata (arch)->armap_timestamp = (statbuf.st_mtime
-                                            + ARMAP_TIME_OFFSET);
+      struct stat statbuf;
+
+      if (stat (arch->filename, &statbuf) == 0)
+	bfd_ardata (arch)->armap_timestamp = (statbuf.st_mtime
+					      + ARMAP_TIME_OFFSET);
       uid = getuid();
       gid = getgid();
     }
-  else
-    {
-      /* If deterministic, we use 0 as the timestamp in the map.
-         Some linkers may require that the archive filesystem modification
-         time is less than (or near to) the archive map timestamp.  Those
-         linkers should not be used with deterministic mode.  (GNU ld and
-         Gold do not have this restriction.)  */
-      bfd_ardata (arch)->armap_timestamp = 0;
-      uid = 0;
-      gid = 0;
-    }
 
   memset (&hdr, ' ', sizeof (struct ar_hdr));
   memcpy (hdr.ar_name, RANLIBMAG, strlen (RANLIBMAG));

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]