ld error message %C format

Alan Modra amodra@gmail.com
Wed May 18 15:48:00 GMT 2011


How do people feel about extending typical linker error messages like
the following
	tmpdir/dump0.o: In function `foo':
	./compressed1.c:13: undefined reference to `bar'
to always include the section and offset information?
	tmpdir/dump0.o: In function `foo':
	./compressed1.c:13:(.text+0x8): undefined reference to `bar'

When debugging toolchain problems, the section and offset is often
more useful than the source information.  I've checked that this
change doesn't seem to break emacs parsing of error messages.

	* ldmisc.c (vfinfo <%C>): Always print section+offset.

Index: ld/ldmisc.c
===================================================================
RCS file: /cvs/src/src/ld/ldmisc.c,v
retrieving revision 1.39
diff -u -p -r1.39 ldmisc.c
--- ld/ldmisc.c	28 Feb 2011 18:34:52 -0000	1.39
+++ ld/ldmisc.c	14 May 2011 11:32:38 -0000
@@ -276,6 +276,7 @@ vfinfo (FILE *fp, const char *fmt, va_li
 		const char *functionname;
 		unsigned int linenumber;
 		bfd_boolean discard_last;
+		bfd_boolean done;
 
 		abfd = va_arg (arg, bfd *);
 		section = va_arg (arg, asection *);
@@ -343,15 +344,21 @@ vfinfo (FILE *fp, const char *fmt, va_li
 		    if (filename != NULL)
 		      fprintf (fp, "%s:", filename);
 
+		    done = fmt[-1] != 'C';
 		    if (functionname != NULL && fmt[-1] == 'G')
 		      lfinfo (fp, "%T", functionname);
 		    else if (filename != NULL && linenumber != 0)
-		      fprintf (fp, "%u", linenumber);
+		      fprintf (fp, "%u%s", linenumber, ":" + done);
 		    else
-		      lfinfo (fp, "(%A+0x%v)", section, offset);
+		      done = FALSE;
 		  }
 		else
-		  lfinfo (fp, "%B:(%A+0x%v)", abfd, section, offset);
+		  {
+		    lfinfo (fp, "%B:", abfd);
+		    done = FALSE;
+		  }
+		if (!done)
+		  lfinfo (fp, "(%A+0x%v)", section, offset);
 
 		if (discard_last)
 		  {
Index: ld/testsuite/ld-cris/undef2.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-cris/undef2.d,v
retrieving revision 1.1
diff -u -p -r1.1 undef2.d
--- ld/testsuite/ld-cris/undef2.d	7 Feb 2005 02:53:32 -0000	1.1
+++ ld/testsuite/ld-cris/undef2.d	14 May 2011 10:41:43 -0000
@@ -3,4 +3,4 @@
 # target: cris-*-*elf* cris-*-*aout*
 # as: --em=crisaout
 # ld: -mcrisaout
-# error: .o:/blah/foo.c:96: undefined reference to `globsym1'$
+# error: .o:/blah/foo.c:96:\(\.text\+0x4\): undefined reference to `globsym1'$
Index: ld/testsuite/ld-cris/undef3.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-cris/undef3.d,v
retrieving revision 1.1
diff -u -p -r1.1 undef3.d
--- ld/testsuite/ld-cris/undef3.d	7 Feb 2005 02:53:32 -0000	1.1
+++ ld/testsuite/ld-cris/undef3.d	14 May 2011 10:41:43 -0000
@@ -3,4 +3,4 @@
 #target: cris-*-*elf* cris-*-*aout*
 #as: --em=criself
 #ld: -mcriself
-#error: .o:/blah/foo.c:96: undefined reference to `globsym1'$
+#error: .o:/blah/foo.c:96:\(\.text\+0x4\): undefined reference to `globsym1'$
Index: ld/testsuite/ld-i386/compressed1.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-i386/compressed1.d,v
retrieving revision 1.1
diff -u -p -r1.1 compressed1.d
--- ld/testsuite/ld-i386/compressed1.d	15 Jul 2010 00:42:23 -0000	1.1
+++ ld/testsuite/ld-i386/compressed1.d	14 May 2011 10:41:44 -0000
@@ -1,7 +1,7 @@
 #name: undefined symbol with compressed debug sections
 #as: --32
 #ld: -e foo -melf_i386 --noinhibit-exec
-#warning: .*/compressed1.c:13: undefined reference to .bar.
+#warning: .*/compressed1.c:13.*: undefined reference to .bar.
 #nm: -n
 
 #...
Index: ld/testsuite/ld-ia64/line.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-ia64/line.exp,v
retrieving revision 1.1
diff -u -p -r1.1 line.exp
--- ld/testsuite/ld-ia64/line.exp	2 Sep 2007 13:29:20 -0000	1.1
+++ ld/testsuite/ld-ia64/line.exp	14 May 2011 10:41:44 -0000
@@ -52,6 +52,6 @@ proc checkund { string testname } {
     }
 }
 
-set ml "undefined.c:9: undefined reference to `*this_function_is_not_defined'"
+set ml "undefined.c:9*: undefined reference to `*this_function_is_not_defined'"
 
 checkund $ml $testline
Index: ld/testsuite/ld-undefined/undefined.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-undefined/undefined.exp,v
retrieving revision 1.32
diff -u -p -r1.32 undefined.exp
--- ld/testsuite/ld-undefined/undefined.exp	6 Apr 2011 17:09:56 -0000	1.32
+++ ld/testsuite/ld-undefined/undefined.exp	14 May 2011 10:41:44 -0000
@@ -90,7 +90,7 @@ if ![is_elf_format] {
     #setup_xfail "arm*-*-pe*"
 }
 
-set ml "undefined.c:9: undefined reference to `*this_function_is_not_defined'"
+set ml "undefined.c:9*: undefined reference to `*this_function_is_not_defined'"
 # With targets that use elf/dwarf2, such as the arm-elf
 # toolchain, the code in bfd/elf.c:_bfd_elf_find_nearest_line() is called
 # in order to locate the file name/line number where the undefined
Index: ld/testsuite/ld-x86-64/compressed1.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-x86-64/compressed1.d,v
retrieving revision 1.1
diff -u -p -r1.1 compressed1.d
--- ld/testsuite/ld-x86-64/compressed1.d	15 Jul 2010 00:42:23 -0000	1.1
+++ ld/testsuite/ld-x86-64/compressed1.d	14 May 2011 10:41:44 -0000
@@ -1,7 +1,7 @@
 #name: undefined symbol with compressed debug sections
 #as: --64
 #ld: -e foo -melf_x86_64 --noinhibit-exec
-#warning: .*/compressed1.c:13: undefined reference to .bar.
+#warning: .*/compressed1.c:13.*: undefined reference to .bar.
 #nm: -n
 
 #...
Index: ld/testsuite/ld-x86-64/line.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-x86-64/line.exp,v
retrieving revision 1.2
diff -u -p -r1.2 line.exp
--- ld/testsuite/ld-x86-64/line.exp	2 Sep 2007 13:29:20 -0000	1.2
+++ ld/testsuite/ld-x86-64/line.exp	14 May 2011 10:41:44 -0000
@@ -52,6 +52,6 @@ proc checkund { string testname } {
     }
 }
 
-set ml "undefined.c:9: undefined reference to `*this_function_is_not_defined'"
+set ml "undefined.c:9*: undefined reference to `*this_function_is_not_defined'"
 
 checkund $ml $testline

-- 
Alan Modra
Australia Development Lab, IBM



More information about the Binutils mailing list