8328d01
--- binutils.orig/gas/as.c	2019-01-30 11:02:04.055574300 +0000
8328d01
+++ binutils-2.31.1/gas/as.c	2019-01-30 11:03:12.212050935 +0000
8328d01
@@ -1254,14 +1254,27 @@ main (int argc, char ** argv)
8328d01
 	{
8328d01
 	  struct stat sib;
8328d01
 
8328d01
-	  if (stat (argv[i], &sib) == 0)
8328d01
+	  /* Check that the input file and output file are different.  */
8328d01
+	  if (stat (argv[i], &sib) == 0
8328d01
+	      && sib.st_ino == sob.st_ino
8328d01
+	      /* POSIX emulating systems may support stat() but if the
8328d01
+		 underlying file system does not support a file serial number
8328d01
+		 of some kind then they will return 0 for the inode.  So
8328d01
+		 two files with an inode of 0 may not actually be the same.
8328d01
+		 On real POSIX systems no ordinary file will ever have an
8328d01
+		 inode of 0.  */
8328d01
+	      && sib.st_ino != 0
8328d01
+	      /* Different files may have the same inode number if they
8328d01
+		 reside on different devices, so check the st_dev field as
8328d01
+		 well.  */
8328d01
+	      && sib.st_dev == sob.st_dev)
8328d01
 	    {
8328d01
-	      if (sib.st_ino == sob.st_ino && sib.st_ino != 0)
8328d01
-		{
8328d01
-		  /* Don't let as_fatal remove the output file!  */
8328d01
-		  out_file_name = NULL;
8328d01
-		  as_fatal (_("The input and output files must be distinct"));
8328d01
-		}
8328d01
+	      const char *saved_out_file_name = out_file_name;
8328d01
+
8328d01
+	      /* Don't let as_fatal remove the output file!  */
8328d01
+	      out_file_name = NULL;
8328d01
+	      as_fatal (_("The input '%s' and output '%s' files are the same"),
8328d01
+			argv[i], saved_out_file_name);
8328d01
 	    }
8328d01
 	}
8328d01
     }