This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [gold patch rfa] print "error: " in front of error messages
On Thu, Feb 5, 2009 at 00:29, Ian Lance Taylor <iant@google.com> wrote:
> Thanks for the background. Let's add "error" where needed.
> Errors::fatal should use "fatal error", by analogy with gcc.
Fixing undefined_symbol turned out to be a bit more fun that I'd
hoped, because there's on location that rolled its own similar message
using gold_error. Since that would put the 'error: ' in the wrong
place, ... Once I changed error_at_location and undefined_symbol, I
also had to update some tests. Anyway, new changelog below and patch
attached.
I overloaded a function here. If you'd rather avoid overloads, or
want the refactored functions ... refactored differently, let me know.
(I'm not sure what c++ coding style you here. I didn't see any
guidance in the GNU coding style that specifically mentioned
overloads.)
built/tested i686-linux, no failures.
chris
----
2009-02-05 Chris Demetriou <cgd@google.com>
* gold.h (gold_undefined_symbol): Add an overload that takes
only the symbol (i.e., doesn't take relocation information).
Document arguments.
* errors.h (Errors::undefined_symbol): Change to take location
as a string, rather than calculating it from a relocation.
* errors.cc (Errors::fatal): Print "fatal error:" before the
formatted message.
(Errors::error, Errors::error_at_location): Print "error: "
before the formatted message.
(Errors::undefined_symbol): Change to take a string which
contains location information.
(gold_undefined_symbol): Add overload that takes only the
undefined symbol. Change the overloads which take relocation
information to calculate location before passing to
Errors::undefined_symbol.
* symtab.cc (Symbol_table::warn_about_undefined_dynobj_symbol):
Call gold_undefined_symbol rather than gold_error to report
undefined symbols.
* testsuite/debug_msg.sh: Update for changed error messages.
* testsuite/undef_symbol.sh: Likewise.
2009-02-05 Chris Demetriou <cgd@google.com>
* gold.h (gold_undefined_symbol): Add an overload that takes
only the symbol (i.e., doesn't take relocation information).
Document arguments.
* errors.h (Errors::undefined_symbol): Change to take location
as a string, rather than calculating it from a relocation.
* errors.cc (Errors::fatal): Print "fatal error:" before the
formatted message.
(Errors::error, Errors::error_at_location): Print "error: "
before the formatted message.
(Errors::undefined_symbol): Change to take a string which
contains location information.
(gold_undefined_symbol): Add overload that takes only the
undefined symbol. Change the overloads which take relocation
information to calculate location before passing to
Errors::undefined_symbol.
* symtab.cc (Symbol_table::warn_about_undefined_dynobj_symbol):
Call gold_undefined_symbol rather than gold_error to report
undefined symbols.
* testsuite/debug_msg.sh: Update for changed error messages.
* testsuite/undef_symbol.sh: Likewise.
Index: errors.cc
===================================================================
RCS file: /cvs/src/src/gold/errors.cc,v
retrieving revision 1.7
diff -u -u -p -r1.7 errors.cc
--- errors.cc 17 Apr 2008 22:45:47 -0000 1.7
+++ errors.cc 6 Feb 2009 00:01:27 -0000
@@ -80,7 +80,7 @@ Errors::increment_counter(int *counter)
void
Errors::fatal(const char* format, va_list args)
{
- fprintf(stderr, "%s: ", this->program_name_);
+ fprintf(stderr, _("%s: fatal error: "), this->program_name_);
vfprintf(stderr, format, args);
fputc('\n', stderr);
gold_exit(false);
@@ -91,7 +91,7 @@ Errors::fatal(const char* format, va_lis
void
Errors::error(const char* format, va_list args)
{
- fprintf(stderr, "%s: ", this->program_name_);
+ fprintf(stderr, _("%s: error: "), this->program_name_);
vfprintf(stderr, format, args);
fputc('\n', stderr);
@@ -127,7 +127,7 @@ Errors::error_at_location(const Relocate
size_t relnum, off_t reloffset,
const char* format, va_list args)
{
- fprintf(stderr, "%s: %s: ", this->program_name_,
+ fprintf(stderr, _("%s: %s: error: "), this->program_name_,
relinfo->location(relnum, reloffset).c_str());
vfprintf(stderr, format, args);
fputc('\n', stderr);
@@ -153,11 +153,8 @@ Errors::warning_at_location(const Reloca
// Issue an undefined symbol error.
-template<int size, bool big_endian>
void
-Errors::undefined_symbol(const Symbol* sym,
- const Relocate_info<size, big_endian>* relinfo,
- size_t relnum, off_t reloffset)
+Errors::undefined_symbol(const Symbol* sym, const std::string& location)
{
bool initialized = this->initialize_lock();
gold_assert(initialized);
@@ -169,12 +166,13 @@ Errors::undefined_symbol(const Symbol* s
}
const char* const version = sym->version();
if (version == NULL)
- fprintf(stderr, _("%s: %s: undefined reference to '%s'\n"),
- this->program_name_, relinfo->location(relnum, reloffset).c_str(),
+ fprintf(stderr, _("%s: %s: error: undefined reference to '%s'\n"),
+ this->program_name_, location.c_str(),
sym->demangled_name().c_str());
else
- fprintf(stderr, _("%s: %s: undefined reference to '%s', version '%s'\n"),
- this->program_name_, relinfo->location(relnum, reloffset).c_str(),
+ fprintf(stderr,
+ _("%s: %s: error: undefined reference to '%s', version '%s'\n"),
+ this->program_name_, location.c_str(),
sym->demangled_name().c_str(), version);
}
@@ -271,13 +269,20 @@ gold_warning_at_location(const Relocate_
// Report an undefined symbol.
+void
+gold_undefined_symbol(const Symbol* sym)
+{
+ parameters->errors()->undefined_symbol(sym, sym->object()->name().c_str());
+}
+
template<int size, bool big_endian>
void
gold_undefined_symbol(const Symbol* sym,
const Relocate_info<size, big_endian>* relinfo,
size_t relnum, off_t reloffset)
{
- parameters->errors()->undefined_symbol(sym, relinfo, relnum, reloffset);
+ parameters->errors()->undefined_symbol(sym,
+ relinfo->location(relnum, reloffset));
}
#ifdef HAVE_TARGET_32_LITTLE
Index: errors.h
===================================================================
RCS file: /cvs/src/src/gold/errors.h,v
retrieving revision 1.6
diff -u -u -p -r1.6 errors.h
--- errors.h 6 May 2008 18:32:38 -0000 1.6
+++ errors.h 6 Feb 2009 00:01:27 -0000
@@ -75,14 +75,10 @@ class Errors
size_t relnum, off_t reloffset,
const char* format, va_list);
- // Issue an undefined symbol error. SYM is the undefined symbol.
- // RELINFO is the general relocation info. RELNUM is the number of
- // the reloc, and RELOFFSET is the reloc's offset.
- template<int size, bool big_endian>
+ // Issue an undefined symbol error. LOCATION is the location of
+ // the error (typically an object file name or relocation info).
void
- undefined_symbol(const Symbol* sym,
- const Relocate_info<size, big_endian>* relinfo,
- size_t relnum, off_t reloffset);
+ undefined_symbol(const Symbol* sym, const std::string& location);
// Report a debugging message.
void
Index: gold.h
===================================================================
RCS file: /cvs/src/src/gold/gold.h,v
retrieving revision 1.30
diff -u -u -p -r1.30 gold.h
--- gold.h 28 Jan 2009 20:09:18 -0000 1.30
+++ gold.h 6 Feb 2009 00:01:27 -0000
@@ -202,7 +202,16 @@ gold_warning_at_location(const Relocate_
size_t, off_t, const char* format, ...)
TEMPLATE_ATTRIBUTE_PRINTF_4;
-// This function is called to report an undefined symbol.
+// This function is called to report an undefined symbol without
+// a relocation (e.g., referenced by a dynamic object). SYM is
+// the undefined symbol.
+extern void
+gold_undefined_symbol(const Symbol*);
+
+// This function is called to report an undefined symbol resulting
+// from a relocation. SYM is the undefined symbol. RELINFO is the
+// general relocation info. RELNUM is the number of the reloc,
+// and RELOFFSET is the reloc's offset.
template<int size, bool big_endian>
extern void
gold_undefined_symbol(const Symbol*,
Index: symtab.cc
===================================================================
RCS file: /cvs/src/src/gold/symtab.cc,v
retrieving revision 1.113
diff -u -u -p -r1.113 symtab.cc
--- symtab.cc 28 Jan 2009 02:25:33 -0000 1.113
+++ symtab.cc 6 Feb 2009 00:01:27 -0000
@@ -2634,17 +2634,7 @@ Symbol_table::warn_about_undefined_dynob
// A very ugly cast.
Dynobj* dynobj = static_cast<Dynobj*>(sym->object());
if (!dynobj->has_unknown_needed_entries())
- {
- if (sym->version())
- gold_error(_("%s: undefined reference to '%s', version '%s'"),
- sym->object()->name().c_str(),
- sym->demangled_name().c_str(),
- sym->version());
- else
- gold_error(_("%s: undefined reference to '%s'"),
- sym->object()->name().c_str(),
- sym->demangled_name().c_str());
- }
+ gold_undefined_symbol(sym);
}
}
Index: testsuite/debug_msg.sh
===================================================================
RCS file: /cvs/src/src/gold/testsuite/debug_msg.sh,v
retrieving revision 1.6
diff -u -u -p -r1.6 debug_msg.sh
--- testsuite/debug_msg.sh 13 Mar 2008 21:04:21 -0000 1.6
+++ testsuite/debug_msg.sh 6 Feb 2009 00:01:27 -0000
@@ -55,18 +55,18 @@ 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]*): 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]*): undefined reference to 'undef_fn2()'"
-check debug_msg.err "debug_msg.o: in function badref1:debug_msg.cc(.data+0x[0-9a-fA-F]*): undefined reference to 'undef_int'"
+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: in function Base::virtfn():${srcdir}/debug_msg.cc:50: undefined reference to 'undef_fn1()'"
-check debug_msg.err "debug_msg.o: in function Derived::virtfn():${srcdir}/debug_msg.cc:55: undefined reference to 'undef_fn2()'"
-check debug_msg.err "debug_msg.o: in function int testfn<int>(int):${srcdir}/debug_msg.cc:43: undefined reference to 'undef_fn1()'"
-check debug_msg.err "debug_msg.o: in function int testfn<int>(int):${srcdir}/debug_msg.cc:44: undefined reference to 'undef_fn2()'"
-check debug_msg.err "debug_msg.o: in function int testfn<int>(int):${srcdir}/debug_msg.cc:45: undefined reference to 'undef_int'"
-check debug_msg.err "debug_msg.o: in function int testfn<double>(double):${srcdir}/debug_msg.cc:43: undefined reference to 'undef_fn1()'"
-check debug_msg.err "debug_msg.o: in function int testfn<double>(double):${srcdir}/debug_msg.cc:44: undefined reference to 'undef_fn2()'"
-check debug_msg.err "debug_msg.o: in function int testfn<double>(double):${srcdir}/debug_msg.cc:45: undefined reference to 'undef_int'"
+check debug_msg.err "debug_msg.o: in function Base::virtfn():${srcdir}/debug_msg.cc:50: error: undefined reference to 'undef_fn1()'"
+check debug_msg.err "debug_msg.o: in function Derived::virtfn():${srcdir}/debug_msg.cc:55: error: undefined reference to 'undef_fn2()'"
+check debug_msg.err "debug_msg.o: in function int testfn<int>(int):${srcdir}/debug_msg.cc:43: error: undefined reference to 'undef_fn1()'"
+check debug_msg.err "debug_msg.o: in function int testfn<int>(int):${srcdir}/debug_msg.cc:44: error: undefined reference to 'undef_fn2()'"
+check debug_msg.err "debug_msg.o: in function int testfn<int>(int):${srcdir}/debug_msg.cc:45: error: undefined reference to 'undef_int'"
+check debug_msg.err "debug_msg.o: in function int testfn<double>(double):${srcdir}/debug_msg.cc:43: error: undefined reference to 'undef_fn1()'"
+check debug_msg.err "debug_msg.o: in function int testfn<double>(double):${srcdir}/debug_msg.cc:44: error: undefined reference to 'undef_fn2()'"
+check debug_msg.err "debug_msg.o: in function int testfn<double>(double):${srcdir}/debug_msg.cc:45: 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):"
@@ -75,17 +75,17 @@ check debug_msg.err "odr_violation2.cc:5
# When linking together .so's, we don't catch the line numbers, but we
# still find all the undefined variables, and the ODR violation.
-check debug_msg_so.err "debug_msg.so: undefined reference to 'undef_fn1()'"
-check debug_msg_so.err "debug_msg.so: undefined reference to 'undef_fn2()'"
-check debug_msg_so.err "debug_msg.so: undefined reference to 'undef_int'"
+check debug_msg_so.err "debug_msg.so: error: undefined reference to 'undef_fn1()'"
+check debug_msg_so.err "debug_msg.so: error: undefined reference to 'undef_fn2()'"
+check debug_msg_so.err "debug_msg.so: error: undefined reference to 'undef_int'"
check debug_msg_so.err ": symbol 'Ordering::operator()(int, int)' defined in multiple places (possible ODR violation):"
check debug_msg_so.err "odr_violation1.cc:5"
check debug_msg_so.err "odr_violation2.cc:5"
# These messages shouldn't need any debug info to detect:
-check debug_msg_ndebug.err "debug_msg_ndebug.so: undefined reference to 'undef_fn1()'"
-check debug_msg_ndebug.err "debug_msg_ndebug.so: undefined reference to 'undef_fn2()'"
-check debug_msg_ndebug.err "debug_msg_ndebug.so: undefined reference to 'undef_int'"
+check debug_msg_ndebug.err "debug_msg_ndebug.so: error: undefined reference to 'undef_fn1()'"
+check debug_msg_ndebug.err "debug_msg_ndebug.so: error: undefined reference to 'undef_fn2()'"
+check debug_msg_ndebug.err "debug_msg_ndebug.so: error: undefined reference to 'undef_int'"
# However, we shouldn't detect or declare any ODR violation
check_missing debug_msg_ndebug.err "(possible ODR violation)"
Index: testsuite/undef_symbol.sh
===================================================================
RCS file: /cvs/src/src/gold/testsuite/undef_symbol.sh,v
retrieving revision 1.2
diff -u -u -p -r1.2 undef_symbol.sh
--- testsuite/undef_symbol.sh 13 Mar 2008 21:04:21 -0000 1.2
+++ testsuite/undef_symbol.sh 6 Feb 2009 00:01:27 -0000
@@ -40,6 +40,6 @@ check()
fi
}
-check "undef_symbol.so: undefined reference to 'a'"
+check "undef_symbol.so: error: undefined reference to 'a'"
exit 0