From cbd6a3d32ef696186a170923dc6df697dd27843b Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Mon, 7 Oct 2002 16:08:21 +0000 Subject: [PATCH] Abort if the filename to be added matches the linker output filename. --- ld/ChangeLog | 9 +++++++++ ld/ldlang.c | 52 +++++++++++++++++++++++++++++++++++++++------------- ld/ldlang.h | 1 + ld/lexsup.c | 32 +++++++++++++++++--------------- 4 files changed, 66 insertions(+), 28 deletions(-) diff --git a/ld/ChangeLog b/ld/ChangeLog index ca7506a24..7961079ad 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,12 @@ +2002-10-05 Elias Athanasopoulos + + * ldlang.c (lang_file_exist): New function. + (new_afile): Abort if the filename to be added matches the linker + output filename. + * ldlang.h: Add prototype for lang_file_exist. + * lexsup.c (parse_args): Abort if the output filename matches + one of the input filenames. + 2002-10-02 Alan Modra * emulparams/elf64ppc.sh (MAXPAGESIZE): Set to 0x10000. diff --git a/ld/ldlang.c b/ld/ldlang.c index 6f85945d1..a7a393298 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -3,22 +3,22 @@ 2001, 2002 Free Software Foundation, Inc. -This file is part of GLD, the Gnu Linker. + This file is part of GLD, the Gnu Linker. -GLD is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. + GLD is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. -GLD is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GLD is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GLD; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA -02111-1307, USA. */ + You should have received a copy of the GNU General Public License + along with GLD; see the file COPYING. If not, write to the Free + Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. */ #include "bfd.h" #include "sysdep.h" @@ -459,6 +459,27 @@ lang_list_init (list) list->tail = &list->head; } +/* Check if a file exist in the input_file_chain list. */ + +boolean +lang_file_exists (name) + const char *name; +{ + lang_input_statement_type *p; + + if (name == NULL) + return false; + + for (p = (lang_input_statement_type *) input_file_chain.head; + p != (lang_input_statement_type *) NULL; + p = (lang_input_statement_type *) p->next_real_file) + if (p->filename != (char *) NULL + && strcmp (p->filename, name) == 0) + return true; + + return false; +} + /* Build a new statement node for the parse tree. */ static lang_statement_union_type * @@ -494,6 +515,11 @@ new_afile (name, file_type, target, add_to_list) { lang_input_statement_type *p; + /* We abort if an input file name is identical with the output file name. */ + if (name != NULL && output_filename != NULL + && !strcmp (name, output_filename)) + einfo ("%P%F: input file %s is also the output file!\n", name); + if (add_to_list) p = new_stat (lang_input_statement, stat_ptr); else diff --git a/ld/ldlang.h b/ld/ldlang.h index cb4b6d332..e587d67c8 100644 --- a/ld/ldlang.h +++ b/ld/ldlang.h @@ -483,5 +483,6 @@ extern void lang_register_vers_node struct bfd_elf_version_deps *)); boolean unique_section_p PARAMS ((const char *)); extern void lang_add_unique PARAMS ((const char *)); +extern boolean lang_file_exists PARAMS ((const char *)); #endif diff --git a/ld/lexsup.c b/ld/lexsup.c index 4acb4fd6a..69b1af28b 100644 --- a/ld/lexsup.c +++ b/ld/lexsup.c @@ -3,22 +3,22 @@ 2001, 2002 Free Software Foundation, Inc. -This file is part of GLD, the Gnu Linker. + This file is part of GLD, the Gnu Linker. -GLD is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. + GLD is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. -GLD is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GLD is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GLD; see the file COPYING. If not, write to the Free -Software Foundation, 59 Temple Place - Suite 330, Boston, MA -02111-1307, USA. */ + You should have received a copy of the GNU General Public License + along with GLD; see the file COPYING. If not, write to the Free + Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. */ #include "bfd.h" #include "sysdep.h" @@ -54,8 +54,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #endif static int is_num PARAMS ((const char *, int, int, int)); -static void set_default_dirlist PARAMS ((char *dirlist_ptr)); -static void set_section_start PARAMS ((char *sect, char *valstr)); +static void set_default_dirlist PARAMS ((char *)); +static void set_section_start PARAMS ((char *, char *)); static void help PARAMS ((void)); /* Non-zero if we are processing a --defsym from the command line. */ @@ -796,6 +796,8 @@ parse_args (argc, argv) link_info.optimize = strtoul (optarg, NULL, 0) ? true : false; break; case 'o': + if (lang_file_exists (optarg)) + einfo ("%P%F: output file %s is also an input file!\n", optarg); lang_add_output (optarg, 0); break; case OPTION_OFORMAT: -- 2.11.4.GIT