aboutsummaryrefslogtreecommitdiff
path: root/gas
diff options
context:
space:
mode:
authorRobert Yang <liezhi.yang@windriver.com>2018-09-17 16:26:58 +0100
committerNick Clifton <nickc@redhat.com>2018-09-17 16:26:58 +0100
commitbdfdf1717407e4857fe671f902434273a71b4fe1 (patch)
treef9f2468235a018a770277859311b6bd8bc98663b /gas
parent067f901e5db60b47de07f36772d066f539e030a4 (diff)
downloadgdb-bdfdf1717407e4857fe671f902434273a71b4fe1.zip
gdb-bdfdf1717407e4857fe671f902434273a71b4fe1.tar.gz
gdb-bdfdf1717407e4857fe671f902434273a71b4fe1.tar.bz2
Improve the code in the assembler to detect and reject a duplicate input and output file.
* as.c (main): Improve check for input file matching output file.
Diffstat (limited to 'gas')
-rw-r--r--gas/ChangeLog7
-rw-r--r--gas/as.c27
2 files changed, 27 insertions, 7 deletions
diff --git a/gas/ChangeLog b/gas/ChangeLog
index fe0d12a..31ee451 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,10 @@
+2018-09-17 Nick Clifton <nickc@redhat.com>
+
+ backport from mainline:
+ * 2018-08-14 Robert Yang <liezhi.yang@windriver.com>
+
+ * as.c (main): Improve check for input file matching output file.
+
2018-08-10 H.J. Lu <hongjiu.lu@intel.com>
* testsuite/gas/i386/evex-no-scale.s: Removed.
diff --git a/gas/as.c b/gas/as.c
index 02c7d29..919c24a 100644
--- a/gas/as.c
+++ b/gas/as.c
@@ -1254,14 +1254,27 @@ main (int argc, char ** argv)
{
struct stat sib;
- if (stat (argv[i], &sib) == 0)
+ /* Check that the input file and output file are different. */
+ if (stat (argv[i], &sib) == 0
+ && sib.st_ino == sob.st_ino
+ /* POSIX emulating systems may support stat() but if the
+ underlying file system does not support a file serial number
+ of some kind then they will return 0 for the inode. So
+ two files with an inode of 0 may not actually be the same.
+ On real POSIX systems no ordinary file will ever have an
+ inode of 0. */
+ && sib.st_ino != 0
+ /* Different files may have the same inode number if they
+ reside on different devices, so check the st_dev field as
+ well. */
+ && sib.st_dev == sob.st_dev)
{
- if (sib.st_ino == sob.st_ino && sib.st_ino != 0)
- {
- /* Don't let as_fatal remove the output file! */
- out_file_name = NULL;
- as_fatal (_("The input and output files must be distinct"));
- }
+ const char *saved_out_file_name = out_file_name;
+
+ /* Don't let as_fatal remove the output file! */
+ out_file_name = NULL;
+ as_fatal (_("The input '%s' and output '%s' files are the same"),
+ argv[i], saved_out_file_name);
}
}
}