aboutsummaryrefslogtreecommitdiff
path: root/ld/ldlang.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2021-12-07 12:26:55 +1030
committerAlan Modra <amodra@gmail.com>2021-12-07 16:10:22 +1030
commit43908c16539f486d0b1afc43329bf59d1c3cdd20 (patch)
tree916a93ce4f3c4248d99f6eff20036fde6444d7c6 /ld/ldlang.c
parent21ce5fa063563cb254e0560beb98bd4245b99fb1 (diff)
downloadgdb-43908c16539f486d0b1afc43329bf59d1c3cdd20.zip
gdb-43908c16539f486d0b1afc43329bf59d1c3cdd20.tar.gz
gdb-43908c16539f486d0b1afc43329bf59d1c3cdd20.tar.bz2
Error on ld output file name matching input file name
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.
Diffstat (limited to 'ld/ldlang.c')
-rw-r--r--ld/ldlang.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/ld/ldlang.c b/ld/ldlang.c
index acd90fa..64a8f60 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -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