PATCH: Revert the last ld change (Re: ld is broken)

H. J. Lu hjl@lucon.org
Tue Oct 8 09:17:00 GMT 2002


On Tue, Oct 08, 2002 at 09:04:28AM -0700, H. J. Lu wrote:
> On Tue, Oct 08, 2002 at 07:00:33AM -0700, H. J. Lu wrote:
> > I got
> > 
> > mipsel-linux-gcc -O2  -DPURE_TERMINFO -DSVR4_CURSES  -o ncurses ../obj_s/ncurses.o -L../lib -lform -lmenu -lpanel -lncurses    -Wl,-rpath,/export/redhat/rpms/BUILD/ncurses-5.2/lib  
> > /export/tools/lib/gcc-lib/mipsel-linux/2.96/collect2 -dynamic-linker /lib/ld.so.1 -o ncurses /export/tools/lib/gcc-lib/mipsel-linux/2.96/../../../../mipsel-linux/lib/crt1.o /export/tools/lib/gcc-lib/mipsel-linux/2.96/../../../../mipsel-linux/lib/crti.o /export/tools/lib/gcc-lib/mipsel-linux/2.96/crtbegin.o -L../lib -L/export/tools/lib/gcc-lib/mipsel-linux/2.96 -L/export/tools/lib/gcc-lib/mipsel-linux/2.96/../../../../mipsel-linux/lib ../obj_s/ncurses.o -lform -lmenu -lpanel -lncurses -rpath /export/redhat/rpms/BUILD/ncurses-5.2/lib -lgcc -lc -lgcc /export/tools/lib/gcc-lib/mipsel-linux/2.96/crtend.o /export/tools/lib/gcc-lib/mipsel-linux/2.96/../../../../mipsel-linux/lib/crtn.o
> > /export/tools/lib/gcc-lib/mipsel-linux/2.96/../../../../mipsel-linux/bin/ld: input file ncurses is also the output file!
> > collect2: ld returned 1 exit status
> > 
> > I will try to write a testcase for it.
> > 
> 
> This patch
> 
> http://sources.redhat.com/ml/binutils/2002-10/msg00129.html
> 
> is almost completely bogus. For one thing, the error message is very
> much misleading. There is no such a input file `ncurses' above. Also it
> doesn't check symlinks/hardlinks. Many targets, like Linux, may open
> some files for read implicitly via DT_NEEDED. I'd like to revert it
> now.
> 
> To do it right, you have to check every open against the output. Also
> comparing filename is not enough in that case.
> 

I am going to check in this patch shortly.


H.J.
-------------- next part --------------
2002-10-08  H.J. Lu <hjl@gnu.org>

	* ldlang.c (lang_file_exist): Removed.
	(new_afile): Revert the last change.
	* ldlang.h (lang_file_exist): Removed.
	* lexsup.c (parse_args): Revert the last change.

Index: ldlang.c
===================================================================
RCS file: /export//cvs/gnu/binutils/ld/ldlang.c,v
retrieving revision 1.1.1.71
retrieving revision 1.1.1.72
diff -u -p -r1.1.1.71 -r1.1.1.72
--- ldlang.c	25 Aug 2002 15:27:33 -0000	1.1.1.71
+++ ldlang.c	8 Oct 2002 05:25:18 -0000	1.1.1.72
@@ -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_
 {
   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
Index: ldlang.h
===================================================================
RCS file: /export//cvs/gnu/binutils/ld/ldlang.h,v
retrieving revision 1.1.1.19
retrieving revision 1.1.1.20
diff -u -p -r1.1.1.19 -r1.1.1.20
--- ldlang.h	5 Jul 2002 15:13:47 -0000	1.1.1.19
+++ ldlang.h	8 Oct 2002 05:25:18 -0000	1.1.1.20
@@ -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
Index: lexsup.c
===================================================================
RCS file: /export//cvs/gnu/binutils/ld/lexsup.c,v
retrieving revision 1.1.1.41
retrieving revision 1.1.1.42
diff -u -p -r1.1.1.41 -r1.1.1.42
--- lexsup.c	9 Aug 2002 04:51:12 -0000	1.1.1.41
+++ lexsup.c	8 Oct 2002 05:25:18 -0000	1.1.1.42
@@ -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:


More information about the Binutils mailing list