aboutsummaryrefslogtreecommitdiff
path: root/gold/object.cc
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2007-11-02 03:28:52 +0000
committerIan Lance Taylor <iant@google.com>2007-11-02 03:28:52 +0000
commitf7e2ee482013bd5df3e3726305eab7c5ed5ce020 (patch)
tree769d43a72a997fd42bcebdacc315e1c938c3e5a6 /gold/object.cc
parent6a7eedfedcbe83b936a8be8abc489f0202205c7a (diff)
downloadgdb-f7e2ee482013bd5df3e3726305eab7c5ed5ce020.zip
gdb-f7e2ee482013bd5df3e3726305eab7c5ed5ce020.tar.gz
gdb-f7e2ee482013bd5df3e3726305eab7c5ed5ce020.tar.bz2
Reworked from Andrew Chatham: report error locations.
Diffstat (limited to 'gold/object.cc')
-rw-r--r--gold/object.cc84
1 files changed, 73 insertions, 11 deletions
diff --git a/gold/object.cc b/gold/object.cc
index 9e4b58d..269acc5 100644
--- a/gold/object.cc
+++ b/gold/object.cc
@@ -801,6 +801,62 @@ Sized_relobj<size, big_endian>::write_local_symbols(Output_file* of,
of->write_output_view(this->local_symbol_offset_, output_size, oview);
}
+// Set *INFO to symbolic information about the offset OFFSET in the
+// section SHNDX. Return true if we found something, false if we
+// found nothing.
+
+template<int size, bool big_endian>
+bool
+Sized_relobj<size, big_endian>::get_symbol_location_info(
+ unsigned int shndx,
+ off_t offset,
+ Symbol_location_info* info)
+{
+ if (this->symtab_shndx_ == 0)
+ return false;
+
+ off_t symbols_size;
+ const unsigned char* symbols = this->section_contents(this->symtab_shndx_,
+ &symbols_size,
+ false);
+
+ unsigned int symbol_names_shndx = this->section_link(this->symtab_shndx_);
+ off_t names_size;
+ const unsigned char* symbol_names_u =
+ this->section_contents(symbol_names_shndx, &names_size, false);
+ const char* symbol_names = reinterpret_cast<const char*>(symbol_names_u);
+
+ const int sym_size = This::sym_size;
+ const size_t count = symbols_size / sym_size;
+
+ const unsigned char* p = symbols;
+ for (size_t i = 0; i < count; ++i, p += sym_size)
+ {
+ elfcpp::Sym<size, big_endian> sym(p);
+
+ if (sym.get_st_type() == elfcpp::STT_FILE)
+ {
+ if (sym.get_st_name() >= names_size)
+ info->source_file = "(invalid)";
+ else
+ info->source_file = symbol_names + sym.get_st_name();
+ }
+ else if (sym.get_st_shndx() == shndx
+ && static_cast<off_t>(sym.get_st_value()) <= offset
+ && (static_cast<off_t>(sym.get_st_value() + sym.get_st_size())
+ >= offset))
+ {
+ if (sym.get_st_name() > names_size)
+ info->enclosing_symbol_name = "(invalid)";
+ else
+ info->enclosing_symbol_name = symbol_names + sym.get_st_name();
+ return true;
+ }
+ }
+
+ return false;
+}
+
// Input_objects methods.
// Add a regular relocatable object to the list. Return false if this
@@ -849,21 +905,27 @@ Input_objects::add_object(Object* obj)
template<int size, bool big_endian>
std::string
-Relocate_info<size, big_endian>::location(size_t relnum, off_t) const
+Relocate_info<size, big_endian>::location(size_t, off_t offset) const
{
+ // FIXME: We would like to print the following:
+ // /tmp/foo.o: in function 'fn':foo.c:12: undefined reference to 'xxx'
+ // We're missing line numbers.
std::string ret(this->object->name());
- ret += ": reloc ";
+ 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 += ":";
+ ret += info.source_file;
+ }
+ ret += "(";
+ ret += this->object->section_name(this->data_shndx);
char buf[100];
- snprintf(buf, sizeof buf, "%zu", relnum);
- ret += buf;
- ret += " in reloc section ";
- snprintf(buf, sizeof buf, "%u", this->reloc_shndx);
- ret += buf;
- ret += " (" + this->object->section_name(this->reloc_shndx);
- ret += ") for section ";
- snprintf(buf, sizeof buf, "%u", this->data_shndx);
+ // Offsets into sections have to be positive.
+ snprintf(buf, sizeof(buf), "+0x%lx)", static_cast<long>(offset));
ret += buf;
- ret += " (" + this->object->section_name(this->data_shndx) + ")";
return ret;
}