aboutsummaryrefslogtreecommitdiff
path: root/gold/object.cc
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@airs.com>2008-07-22 22:08:43 +0000
committerIan Lance Taylor <ian@airs.com>2008-07-22 22:08:43 +0000
commit92de84a60cbdb80b808c8571e709c1384c6ee6fc (patch)
tree850dc6691e2bef093d847da5d35241b98b04e2ea /gold/object.cc
parent3f7c5e1d995c658ef8709e5fae244f25434db931 (diff)
downloadgdb-92de84a60cbdb80b808c8571e709c1384c6ee6fc.zip
gdb-92de84a60cbdb80b808c8571e709c1384c6ee6fc.tar.gz
gdb-92de84a60cbdb80b808c8571e709c1384c6ee6fc.tar.bz2
* cref.cc: New file.
* cref.h: New file. * options.h (class General_options): Add --print-symbol-counts. * main.cc (main): Issue defined symbol report if requested. * archive.cc (Archive::interpret_header): Make into a const member function. (Archive::add_symbols): Call Input_objects::archive_start and archive_stop. (Archive::const_iterator): Define new class. (Archive::begin, Archive::end): New functions. (Archive::include_all_members): Rewrite to use iterator. (Archive::count_members): New function. * archive.h (class Archive): Update declarations. (Archive::filename): New function. * object.cc: Include "cref.h". (Sized_relobj::Sized_relobj): Initialize defined_count_. (Sized_relobj::do_get_global_symbol_counts): New function. (Input_objects::add_object): Add object to cross-referencer. (Input_objects::archive_start): New function. (Input_objects::archive_stop): New function. (Input_objects::print_symbol_counts): New function. * object.h: Declare Cref and Archive. (Object::get_global_symbol_counts): New function. (Object::do_get_global_symbol_counts): New pure virtual function. (class Sized_relobj): Add defined_count_ field. Update declarations. (class Input_objects): Add cref_ field. Update constructor. Update declarations. * dynobj.cc (Sized_dynobj::Sized_dynobj): Initialize symbols_ and defined_count_. (Sized_dynobj::do_add_symbols): Allocate symbols_ if printing symbol counts. (Sized_dynobj::do_get_global_symbol_counts): New function. * dynobj.h (class Sized_dynobj): Add fields symbols_ and defined_count_. Update declarations. Define Symbols typedef. * symtab.cc (Symbol_table::add_from_relobj): Add defined parameter. Change all callers. (Symbol_table::add_from_dynobj): Add sympointers and defined parameters. Change all callers. * symtab.h (class Symbol_table): Update declarations. * Makefile.am (CCFILES): Add cref.cc. (HFILES): Add cref.h. * Makefile.in: Rebuild.
Diffstat (limited to 'gold/object.cc')
-rw-r--r--gold/object.cc67
1 files changed, 66 insertions, 1 deletions
diff --git a/gold/object.cc b/gold/object.cc
index 2ecb8a9..d8f5ec8 100644
--- a/gold/object.cc
+++ b/gold/object.cc
@@ -33,6 +33,7 @@
#include "layout.h"
#include "output.h"
#include "symtab.h"
+#include "cref.h"
#include "reloc.h"
#include "object.h"
#include "dynobj.h"
@@ -245,6 +246,7 @@ Sized_relobj<size, big_endian>::Sized_relobj(
output_local_symbol_count_(0),
output_local_dynsym_count_(0),
symbols_(),
+ defined_count_(0),
local_symbol_offset_(0),
local_dynsym_offset_(0),
local_values_(),
@@ -1087,7 +1089,8 @@ Sized_relobj<size, big_endian>::do_add_symbols(Symbol_table* symtab,
sd->symbols->data() + sd->external_symbols_offset,
symcount, this->local_symbol_count_,
sym_names, sd->symbol_names_size,
- &this->symbols_);
+ &this->symbols_,
+ &this->defined_count_);
delete sd->symbols;
sd->symbols = NULL;
@@ -1577,6 +1580,28 @@ Sized_relobj<size, big_endian>::map_to_kept_section(
return 0;
}
+// Get symbol counts.
+
+template<int size, bool big_endian>
+void
+Sized_relobj<size, big_endian>::do_get_global_symbol_counts(
+ const Symbol_table*,
+ size_t* defined,
+ size_t* used) const
+{
+ *defined = this->defined_count_;
+ size_t count = 0;
+ for (Symbols::const_iterator p = this->symbols_.begin();
+ p != this->symbols_.end();
+ ++p)
+ if (*p != NULL
+ && (*p)->source() == Symbol::FROM_OBJECT
+ && (*p)->object() == this
+ && (*p)->is_defined())
+ ++count;
+ *used = count;
+}
+
// Input_objects methods.
// Add a regular relocatable object to the list. Return false if this
@@ -1631,6 +1656,14 @@ Input_objects::add_object(Object* obj)
}
}
+ // Add this object to the cross-referencer if requested.
+ if (parameters->options().user_set_print_symbol_counts())
+ {
+ if (this->cref_ == NULL)
+ this->cref_ = new Cref();
+ this->cref_->add_object(obj);
+ }
+
return true;
}
@@ -1671,6 +1704,38 @@ Input_objects::check_dynamic_dependencies() const
}
}
+// Start processing an archive.
+
+void
+Input_objects::archive_start(Archive* archive)
+{
+ if (parameters->options().user_set_print_symbol_counts())
+ {
+ if (this->cref_ == NULL)
+ this->cref_ = new Cref();
+ this->cref_->add_archive_start(archive);
+ }
+}
+
+// Stop processing an archive.
+
+void
+Input_objects::archive_stop(Archive* archive)
+{
+ if (parameters->options().user_set_print_symbol_counts())
+ this->cref_->add_archive_stop(archive);
+}
+
+// Print symbol counts
+
+void
+Input_objects::print_symbol_counts(const Symbol_table* symtab) const
+{
+ if (parameters->options().user_set_print_symbol_counts()
+ && this->cref_ != NULL)
+ this->cref_->print_symbol_counts(symtab);
+}
+
// Relocate_info methods.
// Return a string describing the location of a relocation. This is