* gold patch committed: Better error message locations
@ 2011-04-18 5:40 Ian Lance Taylor
0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2011-04-18 5:40 UTC (permalink / raw)
To: binutils
[-- Attachment #1: Type: text/plain, Size: 1702 bytes --]
The test that gold printed for an error message location was overly
verbose. This patch changes it. Now if there is file/lineno available,
we just print that. Otherwise we print the object name, and either
filename/function or section+offset. In all cases we omit the program
name.
Without debug info:
Old gold:
gold/ld-new: foo2.o: in function main:foo2.cc(.text+0x5): error: undefined reference to 'bar()'
gold/ld-new: foo2.o:(.eh_frame+0x12): error: undefined reference to '__gxx_personality_v0'
New gold:
foo2.o:foo2.cc:function main: error: undefined reference to 'bar()'
foo2.o(.eh_frame+0x12): error: undefined reference to '__gxx_personality_v0'
GNU ld:
foo2.o: In function `main':
foo2.cc:(.text+0x5): undefined reference to `bar()'
foo2.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
With debug info:
Old gold:
gold/ld-new: foo2.o: in function main:/home/iant/foo2.cc:3: error: undefined reference to 'bar()'
gold/ld-new: foo2.o:(.eh_frame+0x12): error: undefined reference to '__gxx_personality_v0'
New gold:
/home/iant/foo2.cc:3: error: undefined reference to 'bar()'
foo2.o(.eh_frame+0x12): error: undefined reference to '__gxx_personality_v0'
GNU ld:
foo2.o: In function `main':
/home/iant/foo2.cc:3: undefined reference to `bar()'
foo2.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
Committed to mainline.
Ian
2011-04-17 Ian Lance Taylor <iant@google.com>
* object.cc (Relocate_info::location): Simplify location string.
* errors.cc (Errors::error_at_location): Don't print program
name.
(Errors::warning_at_location): Likewise.
(Errors::undefined_symbol): Likewise.
* testsuite/debug_msg.sh: Update accordingly.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 8592 bytes --]
Index: object.cc
===================================================================
RCS file: /cvs/src/src/gold/object.cc,v
retrieving revision 1.137
diff -p -u -r1.137 object.cc
--- object.cc 12 Apr 2011 00:44:48 -0000 1.137
+++ object.cc 18 Apr 2011 05:30:36 -0000
@@ -1,6 +1,6 @@
// object.cc -- support for an object file for linking in gold
-// Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
// Written by Ian Lance Taylor <iant@google.com>.
// This file is part of gold.
@@ -2621,46 +2621,43 @@ Input_objects::print_cref(const Symbol_t
// Relocate_info methods.
-// Return a string describing the location of a relocation. This is
-// only used in error messages.
+// Return a string describing the location of a relocation when file
+// and lineno information is not available. This is only used in
+// error messages.
template<int size, bool big_endian>
std::string
Relocate_info<size, big_endian>::location(size_t, off_t offset) const
{
- // See if we can get line-number information from debugging sections.
- std::string filename;
- std::string file_and_lineno; // Better than filename-only, if available.
-
Sized_dwarf_line_info<size, big_endian> line_info(this->object);
- // This will be "" if we failed to parse the debug info for any reason.
- file_and_lineno = line_info.addr2line(this->data_shndx, offset, NULL);
+ std::string ret = line_info.addr2line(this->data_shndx, offset, NULL);
+ if (!ret.empty())
+ return ret;
+
+ ret = this->object->name();
- std::string ret(this->object->name());
- ret += ':';
Symbol_location_info info;
if (this->object->get_symbol_location_info(this->data_shndx, offset, &info))
{
- ret += " in function ";
- ret += info.enclosing_symbol_name;
- ret += ":";
- filename = info.source_file;
- }
-
- if (!file_and_lineno.empty())
- ret += file_and_lineno;
- else
- {
- if (!filename.empty())
- ret += filename;
- ret += "(";
- ret += this->object->section_name(this->data_shndx);
- char buf[100];
- // Offsets into sections have to be positive.
- snprintf(buf, sizeof(buf), "+0x%lx", static_cast<long>(offset));
+ if (!info.source_file.empty())
+ {
+ ret += ":";
+ ret += info.source_file;
+ }
+ size_t len = info.enclosing_symbol_name.length() + 100;
+ char* buf = new char[len];
+ snprintf(buf, len, _(":function %s"),
+ info.enclosing_symbol_name.c_str());
ret += buf;
- ret += ")";
+ delete[] buf;
+ return ret;
}
+
+ ret += "(";
+ ret += this->object->section_name(this->data_shndx);
+ char buf[100];
+ snprintf(buf, sizeof buf, "+0x%lx)", static_cast<long>(offset));
+ ret += buf;
return ret;
}
Index: errors.cc
===================================================================
RCS file: /cvs/src/src/gold/errors.cc,v
retrieving revision 1.12
diff -p -u -r1.12 errors.cc
--- errors.cc 7 Jan 2010 18:31:30 -0000 1.12
+++ errors.cc 18 Apr 2011 05:30:36 -0000
@@ -1,6 +1,6 @@
// errors.cc -- handle errors for gold
-// Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
// Written by Ian Lance Taylor <iant@google.com>.
// This file is part of gold.
@@ -125,7 +125,7 @@ Errors::error_at_location(const Relocate
size_t relnum, off_t reloffset,
const char* format, va_list args)
{
- fprintf(stderr, _("%s: %s: error: "), this->program_name_,
+ fprintf(stderr, _("%s: error: "),
relinfo->location(relnum, reloffset).c_str());
vfprintf(stderr, format, args);
fputc('\n', stderr);
@@ -141,7 +141,7 @@ Errors::warning_at_location(const Reloca
size_t relnum, off_t reloffset,
const char* format, va_list args)
{
- fprintf(stderr, _("%s: %s: warning: "), this->program_name_,
+ fprintf(stderr, _("%s: warning: "),
relinfo->location(relnum, reloffset).c_str());
vfprintf(stderr, format, args);
fputc('\n', stderr);
@@ -176,14 +176,12 @@ Errors::undefined_symbol(const Symbol* s
const char* const version = sym->version();
if (version == NULL)
- fprintf(stderr, _("%s: %s: %s: undefined reference to '%s'\n"),
- this->program_name_, location.c_str(), zmsg,
- sym->demangled_name().c_str());
+ fprintf(stderr, _("%s: %s: undefined reference to '%s'\n"),
+ location.c_str(), zmsg, sym->demangled_name().c_str());
else
fprintf(stderr,
- _("%s: %s: %s: undefined reference to '%s', version '%s'\n"),
- this->program_name_, location.c_str(), zmsg,
- sym->demangled_name().c_str(), version);
+ _("%s: %s: undefined reference to '%s', version '%s'\n"),
+ location.c_str(), zmsg, sym->demangled_name().c_str(), version);
}
// Issue a debugging message.
Index: testsuite/debug_msg.sh
===================================================================
RCS file: /cvs/src/src/gold/testsuite/debug_msg.sh,v
retrieving revision 1.12
diff -p -u -r1.12 debug_msg.sh
--- testsuite/debug_msg.sh 11 Mar 2011 21:42:12 -0000 1.12
+++ testsuite/debug_msg.sh 18 Apr 2011 05:30:36 -0000
@@ -2,7 +2,7 @@
# debug_msg.sh -- a test case for printing debug info for missing symbols.
-# Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
+# Copyright 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
# Written by Ian Lance Taylor <iant@google.com>.
# This file is part of gold.
@@ -55,21 +55,21 @@ check_missing()
# We don't know how the compiler might order these variables, so we
# can't test for the actual offset from .data, hence the regexp.
-check debug_msg.err "debug_msg.o: in function fn_array:debug_msg.cc(.data+0x[0-9a-fA-F]*): error: undefined reference to 'undef_fn1()'"
-check debug_msg.err "debug_msg.o: in function fn_array:debug_msg.cc(.data+0x[0-9a-fA-F]*): error: undefined reference to 'undef_fn2()'"
-check debug_msg.err "debug_msg.o: in function badref1:debug_msg.cc(.data+0x[0-9a-fA-F]*): error: undefined reference to 'undef_int'"
+check debug_msg.err "debug_msg.o:debug_msg.cc:function fn_array: error: undefined reference to 'undef_fn1()'"
+check debug_msg.err "debug_msg.o:debug_msg.cc:function fn_array: error: undefined reference to 'undef_fn2()'"
+check debug_msg.err "debug_msg.o:debug_msg.cc:function badref1: error: undefined reference to 'undef_int'"
# These tests check only for the source file's file name (not the complete
# path) because use of -fdebug-prefix-map may change the path to the source
# file recorded in the objects.
-check debug_msg.err "debug_msg.o: in function Base::virtfn():.*/debug_msg.cc:50: error: undefined reference to 'undef_fn1()'"
-check debug_msg.err "debug_msg.o: in function Derived::virtfn():.*/debug_msg.cc:55: error: undefined reference to 'undef_fn2()'"
-check debug_msg.err "debug_msg.o: in function int testfn<int>(int):.*/debug_msg.cc:43: error: undefined reference to 'undef_fn1()'"
-check debug_msg.err "debug_msg.o: in function int testfn<int>(int):.*/debug_msg.cc:44: error: undefined reference to 'undef_fn2()'"
-check debug_msg.err "debug_msg.o: in function int testfn<int>(int):.*/debug_msg.cc:.*: error: undefined reference to 'undef_int'"
-check debug_msg.err "debug_msg.o: in function int testfn<double>(double):.*/debug_msg.cc:43: error: undefined reference to 'undef_fn1()'"
-check debug_msg.err "debug_msg.o: in function int testfn<double>(double):.*/debug_msg.cc:44: error: undefined reference to 'undef_fn2()'"
-check debug_msg.err "debug_msg.o: in function int testfn<double>(double):.*/debug_msg.cc:.*: error: undefined reference to 'undef_int'"
+check debug_msg.err ".*/debug_msg.cc:50: error: undefined reference to 'undef_fn1()'"
+check debug_msg.err ".*/debug_msg.cc:55: error: undefined reference to 'undef_fn2()'"
+check debug_msg.err ".*/debug_msg.cc:43: error: undefined reference to 'undef_fn1()'"
+check debug_msg.err ".*/debug_msg.cc:44: error: undefined reference to 'undef_fn2()'"
+check debug_msg.err ".*/debug_msg.cc:.*: error: undefined reference to 'undef_int'"
+check debug_msg.err ".*/debug_msg.cc:43: error: undefined reference to 'undef_fn1()'"
+check debug_msg.err ".*/debug_msg.cc:44: error: undefined reference to 'undef_fn2()'"
+check debug_msg.err ".*/debug_msg.cc:.*: error: undefined reference to 'undef_int'"
# Check we detected the ODR (One Definition Rule) violation.
check debug_msg.err ": symbol 'Ordering::operator()(int, int)' defined in multiple places (possible ODR violation):"
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-04-18 5:40 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-18 5:40 gold patch committed: Better error message locations Ian Lance Taylor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).