]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Error on ld output file name matching input file name
authorAlan Modra <amodra@gmail.com>
Tue, 7 Dec 2021 01:56:55 +0000 (12:26 +1030)
committerAlan Modra <amodra@gmail.com>
Tue, 7 Dec 2021 05:40:22 +0000 (16:10 +1030)
It's not foolproof, for example we don't catch output to a linker
script, to a library specified with -l, or to an element of a thin
archive.

* ldlang.c (open_output): Exit with error on output file matching
an input file.
* testsuite/ld-misc/just-symbols.exp: Adjust ld -r test to suit.

ld/ldlang.c
ld/testsuite/ld-misc/just-symbols.exp

index acd90fa8f4227587feb2fea30743111fd03dc69b..64a8f602093065c9af7ac12dec734a630600fa58 100644 (file)
@@ -3392,6 +3392,22 @@ lang_get_output_target (void)
 static void
 open_output (const char *name)
 {
+  lang_input_statement_type *f;
+  char *out = lrealpath (name);
+
+  for (f = (void *) input_file_chain.head;
+       f != NULL;
+       f = f->next_real_file)
+    if (f->flags.real)
+      {
+       char *in = lrealpath (f->filename);
+       if (filename_cmp (in, out) == 0)
+         einfo (_("%F%P: input file '%s' is the same as output file\n"),
+                f->filename);
+       free (in);
+      }
+  free (out);
+
   output_target = lang_get_output_target ();
 
   /* Has the user requested a particular endianness on the command
index 510291473cad0882c41ea6fe3b6e9b93f174e5c6..6cfbd34eda9af4014ed50fd6071c1d2ca639562d 100644 (file)
@@ -44,7 +44,7 @@ run_ld_link_tests [list \
      "" \
      {just-symbols-0.s} \
      {} \
-     "just-symbols-0.o"] \
+     "just-symbols-r"] \
     [list "Executable for --just-symbols test" \
      "$LDFLAGS -e 0 -T just-symbols.ld" "" \
      "" \