aboutsummaryrefslogtreecommitdiff
path: root/gas/as.c
diff options
context:
space:
mode:
authorJohn Darrington <john@darrington.wattle.id.au>2018-04-12 15:07:02 +0100
committerNick Clifton <nickc@redhat.com>2018-04-12 15:08:59 +0100
commit67f846b59b32f3d704c601669409c2584383fea9 (patch)
treef81ced14535cd14aa5ce69718ef1d174d7161431 /gas/as.c
parent73a05be215ce8ccd7a6623f9a24d86223dd7d2f3 (diff)
downloadgdb-67f846b59b32f3d704c601669409c2584383fea9.zip
gdb-67f846b59b32f3d704c601669409c2584383fea9.tar.gz
gdb-67f846b59b32f3d704c601669409c2584383fea9.tar.bz2
Stop the assembler from overwriting its output file.
* as.c (main): Fail if the output is the same as one of the input files. * testsuite/gas/all/gas.exp: Test the new feature.
Diffstat (limited to 'gas/as.c')
-rw-r--r--gas/as.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/gas/as.c b/gas/as.c
index f6da1b1..6e8ec56 100644
--- a/gas/as.c
+++ b/gas/as.c
@@ -1171,6 +1171,7 @@ int
main (int argc, char ** argv)
{
char ** argv_orig = argv;
+ struct stat sob;
int macro_strip_at;
@@ -1218,6 +1219,27 @@ main (int argc, char ** argv)
/* Call parse_args before any of the init/begin functions
so that switches like --hash-size can be honored. */
parse_args (&argc, &argv);
+
+ if (argc > 1 && stat (out_file_name, &sob) == 0)
+ {
+ int i;
+
+ for (i = 1; i < argc; ++i)
+ {
+ struct stat sib;
+
+ if (stat (argv[i], &sib) == 0)
+ {
+ if (sib.st_ino == sob.st_ino)
+ {
+ /* Don't let as_fatal remove the output file! */
+ out_file_name = NULL;
+ as_fatal (_("The input and output files must be distinct"));
+ }
+ }
+ }
+ }
+
symbol_begin ();
frag_init ();
subsegs_begin ();