diff options
author | Robert Yang <liezhi.yang@windriver.com> | 2018-09-17 16:26:58 +0100 |
---|---|---|
committer | Andreas K. Hüttel <dilfridge@gentoo.org> | 2018-11-30 23:46:16 +0100 |
commit | 38ac076b2f3ed0997bc21a7f8d4838988338476b (patch) | |
tree | 5eaf9f0f45ada1a4ebeb421f6d6f397740425642 /gas/as.c | |
parent | elf: Check for corrupt symbol version info (diff) | |
download | binutils-gdb-38ac076b2f3ed0997bc21a7f8d4838988338476b.tar.gz binutils-gdb-38ac076b2f3ed0997bc21a7f8d4838988338476b.tar.bz2 binutils-gdb-38ac076b2f3ed0997bc21a7f8d4838988338476b.zip |
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.
(cherry picked from commit bdfdf1717407e4857fe671f902434273a71b4fe1)
Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>
Diffstat (limited to 'gas/as.c')
-rw-r--r-- | gas/as.c | 27 |
1 files changed, 20 insertions, 7 deletions
@@ -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); } } } |