1 // cref.cc -- cross reference for gold
3 // Copyright 2008 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
39 // Class Cref_inputs. This is used to hold the list of input files
40 // for cross referencing.
46 : objects_(), archives_(), current_(&this->objects_
)
49 // Add an input object file.
51 add_object(Object
* object
);
53 // Start adding an archive. We support nested archives for future
56 add_archive_start(Archive
*);
58 // Finish adding an archive.
60 add_archive_stop(Archive
*);
62 // Report symbol counts.
64 print_symbol_counts(const Symbol_table
*, FILE*) const;
67 // A list of input objects.
68 typedef std::vector
<Object
*> Objects
;
70 // Information we record for an archive.
75 // List of objects included from the archive.
77 // Number of archive members.
81 // A mapping from the name of an archive to the list of objects in
83 typedef std::map
<std::string
, Archive_info
> Archives
;
85 // Report symbol counts for a list of Objects.
87 print_objects_symbol_counts(const Symbol_table
*, FILE*, const Objects
*) const;
89 // Report symbol counts for an object.
91 print_object_symbol_counts(const Symbol_table
*, FILE*, const Object
*) const;
93 // List of input objects.
95 // List of input archives. This is a mapping from the archive file
96 // name to the list of objects.
98 // The list to which we are currently adding objects.
105 Cref_inputs::add_object(Object
* object
)
107 this->current_
->push_back(object
);
110 // Start adding an archive.
113 Cref_inputs::add_archive_start(Archive
* archive
)
115 gold_assert(this->current_
== &this->objects_
);
116 if (this->archives_
.find(archive
->name()) == this->archives_
.end())
118 Archive_info
* pai
= &this->archives_
[archive
->name()];
119 pai
->name
= archive
->filename();
120 pai
->objects
= new Objects();
121 pai
->member_count
= archive
->count_members();
123 this->current_
= this->archives_
[archive
->name()].objects
;
126 // Stop adding an archive.
129 Cref_inputs::add_archive_stop(Archive
*)
131 gold_assert(this->current_
!= &this->objects_
);
132 this->current_
= &this->objects_
;
135 // Report symbol counts for an object.
138 Cref_inputs::print_object_symbol_counts(const Symbol_table
* symtab
,
140 const Object
* object
) const
142 size_t defined
, used
;
143 object
->get_global_symbol_counts(symtab
, &defined
, &used
);
144 fprintf(f
, "symbols %s %zu %zu\n", object
->name().c_str(), defined
, used
);
147 // Report symbol counts for a list of Inputs.
150 Cref_inputs::print_objects_symbol_counts(const Symbol_table
* symtab
,
152 const Objects
* objects
) const
154 for (Objects::const_iterator p
= objects
->begin();
157 this->print_object_symbol_counts(symtab
, f
, *p
);
160 // Print symbol counts. This implements --print-symbol-counts. This
161 // is intended to be easily read by a program. This outputs a series
162 // of lines. There are two different types of lines.
164 // The first is "symbols FILENAME DEFINED USED". FILENAME is the name
165 // of an object file included in the link; for an archive, this will
166 // be ARCHIVEFILENAME(MEMBERNAME). DEFINED is the number of symbols
167 // which the object file defines. USED is the number of symbols which
168 // are used in the final output; this is the number of symbols which
169 // appear in the final output table as having been defined by this
170 // object. These numbers will be different when weak symbols are
171 // used, and they will be different for dynamic objects.
173 // The second is "archives FILENAME MEMBERS USED". FILENAME is the
174 // name of an archive file included in the link. MEMBERS is the
175 // number of members of the archive. USED is the number of archive
176 // members included in the link.
179 Cref_inputs::print_symbol_counts(const Symbol_table
* symtab
, FILE* f
) const
181 this->print_objects_symbol_counts(symtab
, f
, &this->objects_
);
182 for (Archives::const_iterator p
= this->archives_
.begin();
183 p
!= this->archives_
.end();
186 fprintf(f
, "archive %s %zu %zu\n", p
->second
.name
.c_str(),
187 p
->second
.member_count
, p
->second
.objects
->size());
188 this->print_objects_symbol_counts(symtab
, f
, p
->second
.objects
);
194 // Make sure the Cref_inputs object has been created.
199 if (this->inputs_
== NULL
)
200 this->inputs_
= new Cref_inputs();
203 // Add an input object file.
206 Cref::add_object(Object
* object
)
209 this->inputs_
->add_object(object
);
212 // Start adding an archive.
215 Cref::add_archive_start(Archive
* archive
)
218 this->inputs_
->add_archive_start(archive
);
221 // Stop adding an archive.
224 Cref::add_archive_stop(Archive
* archive
)
226 this->inputs_
->add_archive_stop(archive
);
229 // Print symbol counts.
232 Cref::print_symbol_counts(const Symbol_table
* symtab
) const
234 if (parameters
->options().user_set_print_symbol_counts()
235 && this->inputs_
!= NULL
)
238 if (strcmp(parameters
->options().print_symbol_counts(), "-") == 0)
242 f
= fopen(parameters
->options().print_symbol_counts(), "w");
244 gold_error(_("cannot open symbol count file %s: %s"),
245 parameters
->options().print_symbol_counts(),
249 this->inputs_
->print_symbol_counts(symtab
, f
);
253 } // End namespace gold.
This page took 0.034437 seconds and 4 git commands to generate.