gold patch: --print-symbol-counts

Ian Lance Taylor iant@google.com
Tue Jul 22 22:12:00 GMT 2008
I committed a patch to add a new option to gold:
--print-symbol-counts=FILENAME.  This prints out information about how
many symbols are defined and used by each input file.  This is a first
step toward full cross reference information, and is useful by itself
to analyze a complicated build.

Sample output for hello world:

symbols /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crt1.o 5 5
symbols /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crti.o 2 2
symbols /usr/lib/gcc/i386-redhat-linux/4.1.2/crtbegin.o 1 1
symbols /home/iant/hello+.o 1 1
symbols /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.so 3159 5
symbols /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../libm.so 327 0
symbols /usr/lib/gcc/i386-redhat-linux/4.1.2/libgcc_s.so 94 0
symbols /lib/libc.so.6 2254 2
symbols /lib/ld-linux.so.2 28 0
symbols /usr/lib/gcc/i386-redhat-linux/4.1.2/crtend.o 1 1
symbols /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crtn.o 0 0
archive /usr/lib/libc_nonshared.a 14 1
symbols /usr/lib/libc_nonshared.a(elf-init.oS) 3 3
archive /usr/lib/gcc/i386-redhat-linux/4.1.2/libgcc.a 73 0

The "symbols" lines show symbols defined by the file and symbols used
from the file.  The "archive" lines show number of members in the
archive and numbers of members included.

Ian


2008-07-22  Ian Lance Taylor  <iant@google.com>

	* 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.patch
Type: text/x-patch
Size: 36394 bytes
Desc: Implement --print-symbol-counts
URL: <https://sourceware.org/pipermail/binutils/attachments/20080722/85766bac/attachment.bin>


More information about the Binutils mailing list