* incremental-dump.cc (dump_incremental_inputs): Print dynamic reloc
[deliverable/binutils-gdb.git] / gold / incremental.cc
1 // inremental.cc -- incremental linking support for gold
2
3 // Copyright 2009, 2010 Free Software Foundation, Inc.
4 // Written by Mikolaj Zalewski <mikolajz@google.com>.
5
6 // This file is part of gold.
7
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.
12
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.
17
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.
22
23 #include "gold.h"
24
25 #include <cstdarg>
26 #include "libiberty.h"
27
28 #include "elfcpp.h"
29 #include "options.h"
30 #include "output.h"
31 #include "symtab.h"
32 #include "incremental.h"
33 #include "archive.h"
34 #include "object.h"
35 #include "output.h"
36 #include "target-select.h"
37 #include "target.h"
38 #include "fileread.h"
39 #include "script.h"
40
41 namespace gold {
42
43 // Version information. Will change frequently during the development, later
44 // we could think about backward (and forward?) compatibility.
45 const unsigned int INCREMENTAL_LINK_VERSION = 1;
46
47 // This class manages the .gnu_incremental_inputs section, which holds
48 // the header information, a directory of input files, and separate
49 // entries for each input file.
50
51 template<int size, bool big_endian>
52 class Output_section_incremental_inputs : public Output_section_data
53 {
54 public:
55 Output_section_incremental_inputs(const Incremental_inputs* inputs,
56 const Symbol_table* symtab)
57 : Output_section_data(size / 8), inputs_(inputs), symtab_(symtab)
58 { }
59
60 protected:
61 // This is called to update the section size prior to assigning
62 // the address and file offset.
63 void
64 update_data_size()
65 { this->set_final_data_size(); }
66
67 // Set the final data size.
68 void
69 set_final_data_size();
70
71 // Write the data to the file.
72 void
73 do_write(Output_file*);
74
75 // Write to a map file.
76 void
77 do_print_to_mapfile(Mapfile* mapfile) const
78 { mapfile->print_output_data(this, _("** incremental_inputs")); }
79
80 private:
81 // Write the section header.
82 unsigned char*
83 write_header(unsigned char* pov, unsigned int input_file_count,
84 section_offset_type command_line_offset);
85
86 // Write the input file entries.
87 unsigned char*
88 write_input_files(unsigned char* oview, unsigned char* pov,
89 Stringpool* strtab);
90
91 // Write the supplemental information blocks.
92 unsigned char*
93 write_info_blocks(unsigned char* oview, unsigned char* pov,
94 Stringpool* strtab, unsigned int* global_syms,
95 unsigned int global_sym_count);
96
97 // Write the contents of the .gnu_incremental_symtab section.
98 void
99 write_symtab(unsigned char* pov, unsigned int* global_syms,
100 unsigned int global_sym_count);
101
102 // Write the contents of the .gnu_incremental_got_plt section.
103 void
104 write_got_plt(unsigned char* pov, off_t view_size);
105
106 // Typedefs for writing the data to the output sections.
107 typedef elfcpp::Swap<size, big_endian> Swap;
108 typedef elfcpp::Swap<16, big_endian> Swap16;
109 typedef elfcpp::Swap<32, big_endian> Swap32;
110 typedef elfcpp::Swap<64, big_endian> Swap64;
111
112 // Sizes of various structures.
113 static const int sizeof_addr = size / 8;
114 static const int header_size = 16;
115 static const int input_entry_size = 24;
116
117 // The Incremental_inputs object.
118 const Incremental_inputs* inputs_;
119
120 // The symbol table.
121 const Symbol_table* symtab_;
122 };
123
124 // Inform the user why we don't do an incremental link. Not called in
125 // the obvious case of missing output file. TODO: Is this helpful?
126
127 void
128 vexplain_no_incremental(const char* format, va_list args)
129 {
130 char* buf = NULL;
131 if (vasprintf(&buf, format, args) < 0)
132 gold_nomem();
133 gold_info(_("the link might take longer: "
134 "cannot perform incremental link: %s"), buf);
135 free(buf);
136 }
137
138 void
139 explain_no_incremental(const char* format, ...)
140 {
141 va_list args;
142 va_start(args, format);
143 vexplain_no_incremental(format, args);
144 va_end(args);
145 }
146
147 // Report an error.
148
149 void
150 Incremental_binary::error(const char* format, ...) const
151 {
152 va_list args;
153 va_start(args, format);
154 // Current code only checks if the file can be used for incremental linking,
155 // so errors shouldn't fail the build, but only result in a fallback to a
156 // full build.
157 // TODO: when we implement incremental editing of the file, we may need a
158 // flag that will cause errors to be treated seriously.
159 vexplain_no_incremental(format, args);
160 va_end(args);
161 }
162
163 // Find the .gnu_incremental_inputs section and related sections.
164
165 template<int size, bool big_endian>
166 bool
167 Sized_incremental_binary<size, big_endian>::find_incremental_inputs_sections(
168 unsigned int* p_inputs_shndx,
169 unsigned int* p_symtab_shndx,
170 unsigned int* p_relocs_shndx,
171 unsigned int* p_got_plt_shndx,
172 unsigned int* p_strtab_shndx)
173 {
174 unsigned int inputs_shndx =
175 this->elf_file_.find_section_by_type(elfcpp::SHT_GNU_INCREMENTAL_INPUTS);
176 if (inputs_shndx == elfcpp::SHN_UNDEF) // Not found.
177 return false;
178
179 unsigned int symtab_shndx =
180 this->elf_file_.find_section_by_type(elfcpp::SHT_GNU_INCREMENTAL_SYMTAB);
181 if (symtab_shndx == elfcpp::SHN_UNDEF) // Not found.
182 return false;
183 if (this->elf_file_.section_link(symtab_shndx) != inputs_shndx)
184 return false;
185
186 unsigned int relocs_shndx =
187 this->elf_file_.find_section_by_type(elfcpp::SHT_GNU_INCREMENTAL_RELOCS);
188 if (relocs_shndx == elfcpp::SHN_UNDEF) // Not found.
189 return false;
190 if (this->elf_file_.section_link(relocs_shndx) != inputs_shndx)
191 return false;
192
193 unsigned int got_plt_shndx =
194 this->elf_file_.find_section_by_type(elfcpp::SHT_GNU_INCREMENTAL_GOT_PLT);
195 if (got_plt_shndx == elfcpp::SHN_UNDEF) // Not found.
196 return false;
197 if (this->elf_file_.section_link(got_plt_shndx) != inputs_shndx)
198 return false;
199
200 unsigned int strtab_shndx = this->elf_file_.section_link(inputs_shndx);
201 if (strtab_shndx == elfcpp::SHN_UNDEF
202 || strtab_shndx > this->elf_file_.shnum()
203 || this->elf_file_.section_type(strtab_shndx) != elfcpp::SHT_STRTAB)
204 return false;
205
206 if (p_inputs_shndx != NULL)
207 *p_inputs_shndx = inputs_shndx;
208 if (p_symtab_shndx != NULL)
209 *p_symtab_shndx = symtab_shndx;
210 if (p_relocs_shndx != NULL)
211 *p_relocs_shndx = relocs_shndx;
212 if (p_got_plt_shndx != NULL)
213 *p_got_plt_shndx = got_plt_shndx;
214 if (p_strtab_shndx != NULL)
215 *p_strtab_shndx = strtab_shndx;
216 return true;
217 }
218
219 // Set up the readers into the incremental info sections.
220
221 template<int size, bool big_endian>
222 void
223 Sized_incremental_binary<size, big_endian>::setup_readers()
224 {
225 unsigned int inputs_shndx;
226 unsigned int symtab_shndx;
227 unsigned int relocs_shndx;
228 unsigned int got_plt_shndx;
229 unsigned int strtab_shndx;
230
231 if (!this->find_incremental_inputs_sections(&inputs_shndx, &symtab_shndx,
232 &relocs_shndx, &got_plt_shndx,
233 &strtab_shndx))
234 return;
235
236 Location inputs_location(this->elf_file_.section_contents(inputs_shndx));
237 Location symtab_location(this->elf_file_.section_contents(symtab_shndx));
238 Location relocs_location(this->elf_file_.section_contents(relocs_shndx));
239 Location got_plt_location(this->elf_file_.section_contents(got_plt_shndx));
240 Location strtab_location(this->elf_file_.section_contents(strtab_shndx));
241
242 View inputs_view = this->view(inputs_location);
243 View symtab_view = this->view(symtab_location);
244 View relocs_view = this->view(relocs_location);
245 View got_plt_view = this->view(got_plt_location);
246 View strtab_view = this->view(strtab_location);
247
248 elfcpp::Elf_strtab strtab(strtab_view.data(), strtab_location.data_size);
249
250 this->inputs_reader_ =
251 Incremental_inputs_reader<size, big_endian>(inputs_view.data(), strtab);
252 this->symtab_reader_ =
253 Incremental_symtab_reader<big_endian>(symtab_view.data(),
254 symtab_location.data_size);
255 this->relocs_reader_ =
256 Incremental_relocs_reader<size, big_endian>(relocs_view.data(),
257 relocs_location.data_size);
258 this->got_plt_reader_ =
259 Incremental_got_plt_reader<big_endian>(got_plt_view.data());
260
261 // Find the main symbol table.
262 unsigned int main_symtab_shndx =
263 this->elf_file_.find_section_by_type(elfcpp::SHT_SYMTAB);
264 gold_assert(main_symtab_shndx != elfcpp::SHN_UNDEF);
265 this->main_symtab_loc_ = this->elf_file_.section_contents(main_symtab_shndx);
266
267 // Find the main symbol string table.
268 unsigned int main_strtab_shndx =
269 this->elf_file_.section_link(main_symtab_shndx);
270 gold_assert(main_strtab_shndx != elfcpp::SHN_UNDEF
271 && main_strtab_shndx < this->elf_file_.shnum());
272 this->main_strtab_loc_ = this->elf_file_.section_contents(main_strtab_shndx);
273
274 // Walk the list of input files (a) to setup an Input_reader for each
275 // input file, and (b) to record maps of files added from archive
276 // libraries and scripts.
277 Incremental_inputs_reader<size, big_endian>& inputs = this->inputs_reader_;
278 unsigned int count = inputs.input_file_count();
279 this->input_objects_.resize(count);
280 this->input_entry_readers_.reserve(count);
281 this->library_map_.resize(count);
282 this->script_map_.resize(count);
283 for (unsigned int i = 0; i < count; i++)
284 {
285 Input_entry_reader input_file = inputs.input_file(i);
286 this->input_entry_readers_.push_back(Sized_input_reader(input_file));
287 switch (input_file.type())
288 {
289 case INCREMENTAL_INPUT_OBJECT:
290 case INCREMENTAL_INPUT_ARCHIVE_MEMBER:
291 case INCREMENTAL_INPUT_SHARED_LIBRARY:
292 // No special treatment necessary.
293 break;
294 case INCREMENTAL_INPUT_ARCHIVE:
295 {
296 Incremental_library* lib =
297 new Incremental_library(input_file.filename(), i,
298 &this->input_entry_readers_[i]);
299 this->library_map_[i] = lib;
300 unsigned int member_count = input_file.get_member_count();
301 for (unsigned int j = 0; j < member_count; j++)
302 {
303 int member_offset = input_file.get_member_offset(j);
304 int member_index = inputs.input_file_index(member_offset);
305 this->library_map_[member_index] = lib;
306 }
307 }
308 break;
309 case INCREMENTAL_INPUT_SCRIPT:
310 {
311 Script_info* script = new Script_info(input_file.filename());
312 this->script_map_[i] = script;
313 unsigned int object_count = input_file.get_object_count();
314 for (unsigned int j = 0; j < object_count; j++)
315 {
316 int object_offset = input_file.get_object_offset(j);
317 int object_index = inputs.input_file_index(object_offset);
318 this->script_map_[object_index] = script;
319 }
320 }
321 break;
322 default:
323 gold_unreachable();
324 }
325 }
326
327 // Initialize the map of global symbols.
328 unsigned int nglobals = this->symtab_reader_.symbol_count();
329 this->symbol_map_.resize(nglobals);
330
331 this->has_incremental_info_ = true;
332 }
333
334 // Walk the list of input files given on the command line, and build
335 // a direct map of file index to the corresponding input argument.
336
337 void
338 check_input_args(std::vector<const Input_argument*>& input_args_map,
339 Input_arguments::const_iterator begin,
340 Input_arguments::const_iterator end)
341 {
342 for (Input_arguments::const_iterator p = begin;
343 p != end;
344 ++p)
345 {
346 if (p->is_group())
347 {
348 const Input_file_group* group = p->group();
349 check_input_args(input_args_map, group->begin(), group->end());
350 }
351 else if (p->is_lib())
352 {
353 const Input_file_lib* lib = p->lib();
354 check_input_args(input_args_map, lib->begin(), lib->end());
355 }
356 else
357 {
358 gold_assert(p->is_file());
359 unsigned int arg_serial = p->file().arg_serial();
360 if (arg_serial > 0)
361 {
362 gold_assert(arg_serial <= input_args_map.size());
363 gold_assert(input_args_map[arg_serial - 1] == 0);
364 input_args_map[arg_serial - 1] = &*p;
365 }
366 }
367 }
368 }
369
370 // Determine whether an incremental link based on the existing output file
371 // can be done.
372
373 template<int size, bool big_endian>
374 bool
375 Sized_incremental_binary<size, big_endian>::do_check_inputs(
376 const Command_line& cmdline,
377 Incremental_inputs* incremental_inputs)
378 {
379 Incremental_inputs_reader<size, big_endian>& inputs = this->inputs_reader_;
380
381 if (!this->has_incremental_info_)
382 {
383 explain_no_incremental(_("no incremental data from previous build"));
384 return false;
385 }
386
387 if (inputs.version() != INCREMENTAL_LINK_VERSION)
388 {
389 explain_no_incremental(_("different version of incremental build data"));
390 return false;
391 }
392
393 if (incremental_inputs->command_line() != inputs.command_line())
394 {
395 explain_no_incremental(_("command line changed"));
396 return false;
397 }
398
399 // Walk the list of input files given on the command line, and build
400 // a direct map of argument serial numbers to the corresponding input
401 // arguments.
402 this->input_args_map_.resize(cmdline.number_of_input_files());
403 check_input_args(this->input_args_map_, cmdline.begin(), cmdline.end());
404
405 // Walk the list of input files to check for conditions that prevent
406 // an incremental update link.
407 unsigned int count = inputs.input_file_count();
408 for (unsigned int i = 0; i < count; i++)
409 {
410 Input_entry_reader input_file = inputs.input_file(i);
411 switch (input_file.type())
412 {
413 case INCREMENTAL_INPUT_OBJECT:
414 case INCREMENTAL_INPUT_ARCHIVE_MEMBER:
415 case INCREMENTAL_INPUT_SHARED_LIBRARY:
416 case INCREMENTAL_INPUT_ARCHIVE:
417 // No special treatment necessary.
418 break;
419 case INCREMENTAL_INPUT_SCRIPT:
420 if (this->do_file_has_changed(i))
421 {
422 explain_no_incremental(_("%s: script file changed"),
423 input_file.filename());
424 return false;
425 }
426 break;
427 default:
428 gold_unreachable();
429 }
430 }
431
432 return true;
433 }
434
435 // Return TRUE if input file N has changed since the last incremental link.
436
437 template<int size, bool big_endian>
438 bool
439 Sized_incremental_binary<size, big_endian>::do_file_has_changed(
440 unsigned int n) const
441 {
442 Input_entry_reader input_file = this->inputs_reader_.input_file(n);
443 Incremental_disposition disp = INCREMENTAL_CHECK;
444 const Input_argument* input_argument = this->get_input_argument(n);
445 if (input_argument != NULL)
446 disp = input_argument->file().options().incremental_disposition();
447
448 if (disp != INCREMENTAL_CHECK)
449 return disp == INCREMENTAL_CHANGED;
450
451 const char* filename = input_file.filename();
452 Timespec old_mtime = input_file.get_mtime();
453 Timespec new_mtime;
454 if (!get_mtime(filename, &new_mtime))
455 {
456 // If we can't open get the current modification time, assume it has
457 // changed. If the file doesn't exist, we'll issue an error when we
458 // try to open it later.
459 return true;
460 }
461
462 if (new_mtime.seconds > old_mtime.seconds)
463 return true;
464 if (new_mtime.seconds == old_mtime.seconds
465 && new_mtime.nanoseconds > old_mtime.nanoseconds)
466 return true;
467 return false;
468 }
469
470 // Initialize the layout of the output file based on the existing
471 // output file.
472
473 template<int size, bool big_endian>
474 void
475 Sized_incremental_binary<size, big_endian>::do_init_layout(Layout* layout)
476 {
477 typedef elfcpp::Shdr<size, big_endian> Shdr;
478 const int shdr_size = elfcpp::Elf_sizes<size>::shdr_size;
479
480 // Get views of the section headers and the section string table.
481 const off_t shoff = this->elf_file_.shoff();
482 const unsigned int shnum = this->elf_file_.shnum();
483 const unsigned int shstrndx = this->elf_file_.shstrndx();
484 Location shdrs_location(shoff, shnum * shdr_size);
485 Location shstrndx_location(this->elf_file_.section_contents(shstrndx));
486 View shdrs_view = this->view(shdrs_location);
487 View shstrndx_view = this->view(shstrndx_location);
488 elfcpp::Elf_strtab shstrtab(shstrndx_view.data(),
489 shstrndx_location.data_size);
490
491 layout->set_incremental_base(this);
492
493 // Initialize the layout.
494 this->section_map_.resize(shnum);
495 const unsigned char* pshdr = shdrs_view.data() + shdr_size;
496 for (unsigned int i = 1; i < shnum; i++)
497 {
498 Shdr shdr(pshdr);
499 const char* name;
500 if (!shstrtab.get_c_string(shdr.get_sh_name(), &name))
501 name = NULL;
502 gold_debug(DEBUG_INCREMENTAL,
503 "Output section: %2d %08lx %08lx %08lx %3d %s",
504 i,
505 static_cast<long>(shdr.get_sh_addr()),
506 static_cast<long>(shdr.get_sh_offset()),
507 static_cast<long>(shdr.get_sh_size()),
508 shdr.get_sh_type(), name ? name : "<null>");
509 this->section_map_[i] = layout->init_fixed_output_section(name, shdr);
510 pshdr += shdr_size;
511 }
512 }
513
514 // Mark regions of the input file that must be kept unchanged.
515
516 template<int size, bool big_endian>
517 void
518 Sized_incremental_binary<size, big_endian>::do_reserve_layout(
519 unsigned int input_file_index)
520 {
521 Input_entry_reader input_file =
522 this->inputs_reader_.input_file(input_file_index);
523
524 if (input_file.type() == INCREMENTAL_INPUT_SHARED_LIBRARY)
525 return;
526
527 unsigned int shnum = input_file.get_input_section_count();
528 for (unsigned int i = 0; i < shnum; i++)
529 {
530 typename Input_entry_reader::Input_section_info sect =
531 input_file.get_input_section(i);
532 if (sect.output_shndx == 0 || sect.sh_offset == -1)
533 continue;
534 Output_section* os = this->section_map_[sect.output_shndx];
535 gold_assert(os != NULL);
536 os->reserve(sect.sh_offset, sect.sh_size);
537 }
538 }
539
540 // Process the GOT and PLT entries from the existing output file.
541
542 template<int size, bool big_endian>
543 void
544 Sized_incremental_binary<size, big_endian>::do_process_got_plt(
545 Symbol_table* symtab,
546 Layout* layout)
547 {
548 Incremental_got_plt_reader<big_endian> got_plt_reader(this->got_plt_reader());
549 Sized_target<size, big_endian>* target =
550 parameters->sized_target<size, big_endian>();
551
552 // Get the number of symbols in the main symbol table and in the
553 // incremental symbol table. The difference between the two counts
554 // is the index of the first forced-local or global symbol in the
555 // main symbol table.
556 unsigned int symtab_count =
557 this->main_symtab_loc_.data_size / elfcpp::Elf_sizes<size>::sym_size;
558 unsigned int isym_count = this->symtab_reader_.symbol_count();
559 unsigned int first_global = symtab_count - isym_count;
560
561 // Tell the target how big the GOT and PLT sections are.
562 unsigned int got_count = got_plt_reader.get_got_entry_count();
563 unsigned int plt_count = got_plt_reader.get_plt_entry_count();
564 Output_data_got<size, big_endian>* got =
565 target->init_got_plt_for_update(symtab, layout, got_count, plt_count);
566
567 // Read the GOT entries from the base file and build the outgoing GOT.
568 for (unsigned int i = 0; i < got_count; ++i)
569 {
570 unsigned int got_type = got_plt_reader.get_got_type(i);
571 if ((got_type & 0x7f) == 0x7f)
572 {
573 // This is the second entry of a pair.
574 got->reserve_slot(i);
575 continue;
576 }
577 unsigned int symndx = got_plt_reader.get_got_symndx(i);
578 if (got_type & 0x80)
579 {
580 // This is an entry for a local symbol. Ignore this entry if
581 // the object file was replaced.
582 unsigned int input_index = got_plt_reader.get_got_input_index(i);
583 gold_debug(DEBUG_INCREMENTAL,
584 "GOT entry %d, type %02x: (local symbol)",
585 i, got_type & 0x7f);
586 Sized_relobj_incr<size, big_endian>* obj =
587 this->input_object(input_index);
588 if (obj != NULL)
589 target->reserve_local_got_entry(i, obj, symndx, got_type & 0x7f);
590 }
591 else
592 {
593 // This is an entry for a global symbol. GOT_DESC is the symbol
594 // table index.
595 // FIXME: This should really be a fatal error (corrupt input).
596 gold_assert(symndx >= first_global && symndx < symtab_count);
597 Symbol* sym = this->global_symbol(symndx - first_global);
598 gold_debug(DEBUG_INCREMENTAL,
599 "GOT entry %d, type %02x: %s",
600 i, got_type, sym->name());
601 target->reserve_global_got_entry(i, sym, got_type);
602 }
603 }
604
605 // Read the PLT entries from the base file and pass each to the target.
606 for (unsigned int i = 0; i < plt_count; ++i)
607 {
608 unsigned int plt_desc = got_plt_reader.get_plt_desc(i);
609 // FIXME: This should really be a fatal error (corrupt input).
610 gold_assert(plt_desc >= first_global && plt_desc < symtab_count);
611 Symbol* sym = this->global_symbol(plt_desc - first_global);
612 gold_debug(DEBUG_INCREMENTAL,
613 "PLT entry %d: %s",
614 i, sym->name());
615 target->register_global_plt_entry(i, sym);
616 }
617 }
618
619 // Apply incremental relocations for symbols whose values have changed.
620
621 template<int size, bool big_endian>
622 void
623 Sized_incremental_binary<size, big_endian>::do_apply_incremental_relocs(
624 const Symbol_table* symtab,
625 Layout* layout,
626 Output_file* of)
627 {
628 typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
629 typedef typename elfcpp::Elf_types<size>::Elf_Swxword Addend;
630 Incremental_symtab_reader<big_endian> isymtab(this->symtab_reader());
631 Incremental_relocs_reader<size, big_endian> irelocs(this->relocs_reader());
632 unsigned int nglobals = isymtab.symbol_count();
633 const unsigned int incr_reloc_size = irelocs.reloc_size;
634
635 Relocate_info<size, big_endian> relinfo;
636 relinfo.symtab = symtab;
637 relinfo.layout = layout;
638 relinfo.object = NULL;
639 relinfo.reloc_shndx = 0;
640 relinfo.reloc_shdr = NULL;
641 relinfo.data_shndx = 0;
642 relinfo.data_shdr = NULL;
643
644 Sized_target<size, big_endian>* target =
645 parameters->sized_target<size, big_endian>();
646
647 for (unsigned int i = 0; i < nglobals; i++)
648 {
649 const Symbol* gsym = this->global_symbol(i);
650
651 // If the symbol is not referenced from any unchanged input files,
652 // we do not need to reapply any of its relocations.
653 if (gsym == NULL)
654 continue;
655
656 // If the symbol is defined in an unchanged file, we do not need to
657 // reapply any of its relocations.
658 if (gsym->source() == Symbol::FROM_OBJECT
659 && gsym->object()->is_incremental())
660 continue;
661
662 gold_debug(DEBUG_INCREMENTAL,
663 "Applying incremental relocations for global symbol %s [%d]",
664 gsym->name(), i);
665
666 // Follow the linked list of input symbol table entries for this symbol.
667 // We don't bother to figure out whether the symbol table entry belongs
668 // to a changed or unchanged file because it's easier just to apply all
669 // the relocations -- although we might scribble over an area that has
670 // been reallocated, we do this before copying any new data into the
671 // output file.
672 unsigned int offset = isymtab.get_list_head(i);
673 while (offset > 0)
674 {
675 Incremental_global_symbol_reader<big_endian> sym_info =
676 this->inputs_reader().global_symbol_reader_at_offset(offset);
677 unsigned int r_base = sym_info.reloc_offset();
678 unsigned int r_count = sym_info.reloc_count();
679
680 // Apply each relocation for this symbol table entry.
681 for (unsigned int j = 0; j < r_count;
682 ++j, r_base += incr_reloc_size)
683 {
684 unsigned int r_type = irelocs.get_r_type(r_base);
685 unsigned int r_shndx = irelocs.get_r_shndx(r_base);
686 Address r_offset = irelocs.get_r_offset(r_base);
687 Addend r_addend = irelocs.get_r_addend(r_base);
688 Output_section* os = this->output_section(r_shndx);
689 Address address = os->address();
690 off_t section_offset = os->offset();
691 size_t view_size = os->data_size();
692 unsigned char* const view = of->get_output_view(section_offset,
693 view_size);
694
695 gold_debug(DEBUG_INCREMENTAL,
696 " %08lx: %s + %d: type %d addend %ld",
697 (long)(section_offset + r_offset),
698 os->name(),
699 (int)r_offset,
700 r_type,
701 (long)r_addend);
702
703 target->apply_relocation(&relinfo, r_offset, r_type, r_addend,
704 gsym, view, address, view_size);
705
706 // FIXME: Do something more efficient if write_output_view
707 // ever becomes more than a no-op.
708 of->write_output_view(section_offset, view_size, view);
709 }
710 offset = sym_info.next_offset();
711 }
712 }
713 }
714
715 // Get a view of the main symbol table and the symbol string table.
716
717 template<int size, bool big_endian>
718 void
719 Sized_incremental_binary<size, big_endian>::get_symtab_view(
720 View* symtab_view,
721 unsigned int* nsyms,
722 elfcpp::Elf_strtab* strtab)
723 {
724 *symtab_view = this->view(this->main_symtab_loc_);
725 *nsyms = this->main_symtab_loc_.data_size / elfcpp::Elf_sizes<size>::sym_size;
726
727 View strtab_view(this->view(this->main_strtab_loc_));
728 *strtab = elfcpp::Elf_strtab(strtab_view.data(),
729 this->main_strtab_loc_.data_size);
730 }
731
732 namespace
733 {
734
735 // Create a Sized_incremental_binary object of the specified size and
736 // endianness. Fails if the target architecture is not supported.
737
738 template<int size, bool big_endian>
739 Incremental_binary*
740 make_sized_incremental_binary(Output_file* file,
741 const elfcpp::Ehdr<size, big_endian>& ehdr)
742 {
743 Target* target = select_target(ehdr.get_e_machine(), size, big_endian,
744 ehdr.get_e_ident()[elfcpp::EI_OSABI],
745 ehdr.get_e_ident()[elfcpp::EI_ABIVERSION]);
746 if (target == NULL)
747 {
748 explain_no_incremental(_("unsupported ELF machine number %d"),
749 ehdr.get_e_machine());
750 return NULL;
751 }
752
753 if (!parameters->target_valid())
754 set_parameters_target(target);
755 else if (target != &parameters->target())
756 gold_error(_("%s: incompatible target"), file->filename());
757
758 return new Sized_incremental_binary<size, big_endian>(file, ehdr, target);
759 }
760
761 } // End of anonymous namespace.
762
763 // Create an Incremental_binary object for FILE. Returns NULL is this is not
764 // possible, e.g. FILE is not an ELF file or has an unsupported target. FILE
765 // should be opened.
766
767 Incremental_binary*
768 open_incremental_binary(Output_file* file)
769 {
770 off_t filesize = file->filesize();
771 int want = elfcpp::Elf_recognizer::max_header_size;
772 if (filesize < want)
773 want = filesize;
774
775 const unsigned char* p = file->get_input_view(0, want);
776 if (!elfcpp::Elf_recognizer::is_elf_file(p, want))
777 {
778 explain_no_incremental(_("output is not an ELF file."));
779 return NULL;
780 }
781
782 int size = 0;
783 bool big_endian = false;
784 std::string error;
785 if (!elfcpp::Elf_recognizer::is_valid_header(p, want, &size, &big_endian,
786 &error))
787 {
788 explain_no_incremental(error.c_str());
789 return NULL;
790 }
791
792 Incremental_binary* result = NULL;
793 if (size == 32)
794 {
795 if (big_endian)
796 {
797 #ifdef HAVE_TARGET_32_BIG
798 result = make_sized_incremental_binary<32, true>(
799 file, elfcpp::Ehdr<32, true>(p));
800 #else
801 explain_no_incremental(_("unsupported file: 32-bit, big-endian"));
802 #endif
803 }
804 else
805 {
806 #ifdef HAVE_TARGET_32_LITTLE
807 result = make_sized_incremental_binary<32, false>(
808 file, elfcpp::Ehdr<32, false>(p));
809 #else
810 explain_no_incremental(_("unsupported file: 32-bit, little-endian"));
811 #endif
812 }
813 }
814 else if (size == 64)
815 {
816 if (big_endian)
817 {
818 #ifdef HAVE_TARGET_64_BIG
819 result = make_sized_incremental_binary<64, true>(
820 file, elfcpp::Ehdr<64, true>(p));
821 #else
822 explain_no_incremental(_("unsupported file: 64-bit, big-endian"));
823 #endif
824 }
825 else
826 {
827 #ifdef HAVE_TARGET_64_LITTLE
828 result = make_sized_incremental_binary<64, false>(
829 file, elfcpp::Ehdr<64, false>(p));
830 #else
831 explain_no_incremental(_("unsupported file: 64-bit, little-endian"));
832 #endif
833 }
834 }
835 else
836 gold_unreachable();
837
838 return result;
839 }
840
841 // Class Incremental_inputs.
842
843 // Add the command line to the string table, setting
844 // command_line_key_. In incremental builds, the command line is
845 // stored in .gnu_incremental_inputs so that the next linker run can
846 // check if the command line options didn't change.
847
848 void
849 Incremental_inputs::report_command_line(int argc, const char* const* argv)
850 {
851 // Always store 'gold' as argv[0] to avoid a full relink if the user used a
852 // different path to the linker.
853 std::string args("gold");
854 // Copied from collect_argv in main.cc.
855 for (int i = 1; i < argc; ++i)
856 {
857 // Adding/removing these options should not result in a full relink.
858 if (strcmp(argv[i], "--incremental") == 0
859 || strcmp(argv[i], "--incremental-full") == 0
860 || strcmp(argv[i], "--incremental-update") == 0
861 || strcmp(argv[i], "--incremental-changed") == 0
862 || strcmp(argv[i], "--incremental-unchanged") == 0
863 || strcmp(argv[i], "--incremental-unknown") == 0
864 || is_prefix_of("--debug=", argv[i]))
865 continue;
866
867 args.append(" '");
868 // Now append argv[i], but with all single-quotes escaped
869 const char* argpos = argv[i];
870 while (1)
871 {
872 const int len = strcspn(argpos, "'");
873 args.append(argpos, len);
874 if (argpos[len] == '\0')
875 break;
876 args.append("'\"'\"'");
877 argpos += len + 1;
878 }
879 args.append("'");
880 }
881
882 this->command_line_ = args;
883 this->strtab_->add(this->command_line_.c_str(), false,
884 &this->command_line_key_);
885 }
886
887 // Record the input archive file ARCHIVE. This is called by the
888 // Add_archive_symbols task before determining which archive members
889 // to include. We create the Incremental_archive_entry here and
890 // attach it to the Archive, but we do not add it to the list of
891 // input objects until report_archive_end is called.
892
893 void
894 Incremental_inputs::report_archive_begin(Library_base* arch,
895 unsigned int arg_serial,
896 Script_info* script_info)
897 {
898 Stringpool::Key filename_key;
899 Timespec mtime = arch->get_mtime();
900
901 // For a file loaded from a script, don't record its argument serial number.
902 if (script_info != NULL)
903 arg_serial = 0;
904
905 this->strtab_->add(arch->filename().c_str(), false, &filename_key);
906 Incremental_archive_entry* entry =
907 new Incremental_archive_entry(filename_key, arg_serial, mtime);
908 arch->set_incremental_info(entry);
909
910 if (script_info != NULL)
911 {
912 Incremental_script_entry* script_entry = script_info->incremental_info();
913 gold_assert(script_entry != NULL);
914 script_entry->add_object(entry);
915 }
916 }
917
918 // Visitor class for processing the unused global symbols in a library.
919 // An instance of this class is passed to the library's
920 // for_all_unused_symbols() iterator, which will call the visit()
921 // function for each global symbol defined in each unused library
922 // member. We add those symbol names to the incremental info for the
923 // library.
924
925 class Unused_symbol_visitor : public Library_base::Symbol_visitor_base
926 {
927 public:
928 Unused_symbol_visitor(Incremental_archive_entry* entry, Stringpool* strtab)
929 : entry_(entry), strtab_(strtab)
930 { }
931
932 void
933 visit(const char* sym)
934 {
935 Stringpool::Key symbol_key;
936 this->strtab_->add(sym, true, &symbol_key);
937 this->entry_->add_unused_global_symbol(symbol_key);
938 }
939
940 private:
941 Incremental_archive_entry* entry_;
942 Stringpool* strtab_;
943 };
944
945 // Finish recording the input archive file ARCHIVE. This is called by the
946 // Add_archive_symbols task after determining which archive members
947 // to include.
948
949 void
950 Incremental_inputs::report_archive_end(Library_base* arch)
951 {
952 Incremental_archive_entry* entry = arch->incremental_info();
953
954 gold_assert(entry != NULL);
955 this->inputs_.push_back(entry);
956
957 // Collect unused global symbols.
958 Unused_symbol_visitor v(entry, this->strtab_);
959 arch->for_all_unused_symbols(&v);
960 }
961
962 // Record the input object file OBJ. If ARCH is not NULL, attach
963 // the object file to the archive. This is called by the
964 // Add_symbols task after finding out the type of the file.
965
966 void
967 Incremental_inputs::report_object(Object* obj, unsigned int arg_serial,
968 Library_base* arch, Script_info* script_info)
969 {
970 Stringpool::Key filename_key;
971 Timespec mtime = obj->get_mtime();
972
973 // For a file loaded from a script, don't record its argument serial number.
974 if (script_info != NULL)
975 arg_serial = 0;
976
977 this->strtab_->add(obj->name().c_str(), false, &filename_key);
978 Incremental_object_entry* obj_entry =
979 new Incremental_object_entry(filename_key, obj, arg_serial, mtime);
980 if (obj->is_in_system_directory())
981 obj_entry->set_is_in_system_directory();
982 this->inputs_.push_back(obj_entry);
983
984 if (arch != NULL)
985 {
986 Incremental_archive_entry* arch_entry = arch->incremental_info();
987 gold_assert(arch_entry != NULL);
988 arch_entry->add_object(obj_entry);
989 }
990
991 if (script_info != NULL)
992 {
993 Incremental_script_entry* script_entry = script_info->incremental_info();
994 gold_assert(script_entry != NULL);
995 script_entry->add_object(obj_entry);
996 }
997
998 this->current_object_ = obj;
999 this->current_object_entry_ = obj_entry;
1000 }
1001
1002 // Record the input object file OBJ. If ARCH is not NULL, attach
1003 // the object file to the archive. This is called by the
1004 // Add_symbols task after finding out the type of the file.
1005
1006 void
1007 Incremental_inputs::report_input_section(Object* obj, unsigned int shndx,
1008 const char* name, off_t sh_size)
1009 {
1010 Stringpool::Key key = 0;
1011
1012 if (name != NULL)
1013 this->strtab_->add(name, true, &key);
1014
1015 gold_assert(obj == this->current_object_);
1016 this->current_object_entry_->add_input_section(shndx, key, sh_size);
1017 }
1018
1019 // Record that the input argument INPUT is a script SCRIPT. This is
1020 // called by read_script after parsing the script and reading the list
1021 // of inputs added by this script.
1022
1023 void
1024 Incremental_inputs::report_script(Script_info* script,
1025 unsigned int arg_serial,
1026 Timespec mtime)
1027 {
1028 Stringpool::Key filename_key;
1029
1030 this->strtab_->add(script->filename().c_str(), false, &filename_key);
1031 Incremental_script_entry* entry =
1032 new Incremental_script_entry(filename_key, arg_serial, script, mtime);
1033 this->inputs_.push_back(entry);
1034 script->set_incremental_info(entry);
1035 }
1036
1037 // Finalize the incremental link information. Called from
1038 // Layout::finalize.
1039
1040 void
1041 Incremental_inputs::finalize()
1042 {
1043 // Finalize the string table.
1044 this->strtab_->set_string_offsets();
1045 }
1046
1047 // Create the .gnu_incremental_inputs, _symtab, and _relocs input sections.
1048
1049 void
1050 Incremental_inputs::create_data_sections(Symbol_table* symtab)
1051 {
1052 switch (parameters->size_and_endianness())
1053 {
1054 #ifdef HAVE_TARGET_32_LITTLE
1055 case Parameters::TARGET_32_LITTLE:
1056 this->inputs_section_ =
1057 new Output_section_incremental_inputs<32, false>(this, symtab);
1058 break;
1059 #endif
1060 #ifdef HAVE_TARGET_32_BIG
1061 case Parameters::TARGET_32_BIG:
1062 this->inputs_section_ =
1063 new Output_section_incremental_inputs<32, true>(this, symtab);
1064 break;
1065 #endif
1066 #ifdef HAVE_TARGET_64_LITTLE
1067 case Parameters::TARGET_64_LITTLE:
1068 this->inputs_section_ =
1069 new Output_section_incremental_inputs<64, false>(this, symtab);
1070 break;
1071 #endif
1072 #ifdef HAVE_TARGET_64_BIG
1073 case Parameters::TARGET_64_BIG:
1074 this->inputs_section_ =
1075 new Output_section_incremental_inputs<64, true>(this, symtab);
1076 break;
1077 #endif
1078 default:
1079 gold_unreachable();
1080 }
1081 this->symtab_section_ = new Output_data_space(4, "** incremental_symtab");
1082 this->relocs_section_ = new Output_data_space(4, "** incremental_relocs");
1083 this->got_plt_section_ = new Output_data_space(4, "** incremental_got_plt");
1084 }
1085
1086 // Return the sh_entsize value for the .gnu_incremental_relocs section.
1087 unsigned int
1088 Incremental_inputs::relocs_entsize() const
1089 {
1090 return 8 + 2 * parameters->target().get_size() / 8;
1091 }
1092
1093 // Class Output_section_incremental_inputs.
1094
1095 // Finalize the offsets for each input section and supplemental info block,
1096 // and set the final data size of the incremental output sections.
1097
1098 template<int size, bool big_endian>
1099 void
1100 Output_section_incremental_inputs<size, big_endian>::set_final_data_size()
1101 {
1102 const Incremental_inputs* inputs = this->inputs_;
1103 const unsigned int sizeof_addr = size / 8;
1104 const unsigned int rel_size = 8 + 2 * sizeof_addr;
1105
1106 // Offset of each input entry.
1107 unsigned int input_offset = this->header_size;
1108
1109 // Offset of each supplemental info block.
1110 unsigned int file_index = 0;
1111 unsigned int info_offset = this->header_size;
1112 info_offset += this->input_entry_size * inputs->input_file_count();
1113
1114 // Count each input file and its supplemental information block.
1115 for (Incremental_inputs::Input_list::const_iterator p =
1116 inputs->input_files().begin();
1117 p != inputs->input_files().end();
1118 ++p)
1119 {
1120 // Set the index and offset of the input file entry.
1121 (*p)->set_offset(file_index, input_offset);
1122 ++file_index;
1123 input_offset += this->input_entry_size;
1124
1125 // Set the offset of the supplemental info block.
1126 switch ((*p)->type())
1127 {
1128 case INCREMENTAL_INPUT_SCRIPT:
1129 {
1130 Incremental_script_entry *entry = (*p)->script_entry();
1131 gold_assert(entry != NULL);
1132 (*p)->set_info_offset(info_offset);
1133 // Object count.
1134 info_offset += 4;
1135 // Each member.
1136 info_offset += (entry->get_object_count() * 4);
1137 }
1138 break;
1139 case INCREMENTAL_INPUT_OBJECT:
1140 case INCREMENTAL_INPUT_ARCHIVE_MEMBER:
1141 {
1142 Incremental_object_entry* entry = (*p)->object_entry();
1143 gold_assert(entry != NULL);
1144 (*p)->set_info_offset(info_offset);
1145 // Input section count, global symbol count, local symbol offset,
1146 // local symbol count, first dynamic reloc, dynamic reloc count.
1147 info_offset += 24;
1148 // Each input section.
1149 info_offset += (entry->get_input_section_count()
1150 * (8 + 2 * sizeof_addr));
1151 // Each global symbol.
1152 const Object::Symbols* syms = entry->object()->get_global_symbols();
1153 info_offset += syms->size() * 20;
1154 }
1155 break;
1156 case INCREMENTAL_INPUT_SHARED_LIBRARY:
1157 {
1158 Incremental_object_entry* entry = (*p)->object_entry();
1159 gold_assert(entry != NULL);
1160 (*p)->set_info_offset(info_offset);
1161 // Global symbol count.
1162 info_offset += 4;
1163 // Each global symbol.
1164 const Object::Symbols* syms = entry->object()->get_global_symbols();
1165 gold_assert(syms != NULL);
1166 unsigned int nsyms = syms->size();
1167 unsigned int nsyms_out = 0;
1168 for (unsigned int i = 0; i < nsyms; ++i)
1169 {
1170 const Symbol* sym = (*syms)[i];
1171 if (sym == NULL)
1172 continue;
1173 if (sym->is_forwarder())
1174 sym = this->symtab_->resolve_forwards(sym);
1175 if (sym->symtab_index() != -1U)
1176 ++nsyms_out;
1177 }
1178 info_offset += nsyms_out * 4;
1179 }
1180 break;
1181 case INCREMENTAL_INPUT_ARCHIVE:
1182 {
1183 Incremental_archive_entry* entry = (*p)->archive_entry();
1184 gold_assert(entry != NULL);
1185 (*p)->set_info_offset(info_offset);
1186 // Member count + unused global symbol count.
1187 info_offset += 8;
1188 // Each member.
1189 info_offset += (entry->get_member_count() * 4);
1190 // Each global symbol.
1191 info_offset += (entry->get_unused_global_symbol_count() * 4);
1192 }
1193 break;
1194 default:
1195 gold_unreachable();
1196 }
1197 }
1198
1199 this->set_data_size(info_offset);
1200
1201 // Set the size of the .gnu_incremental_symtab section.
1202 inputs->symtab_section()->set_current_data_size(this->symtab_->output_count()
1203 * sizeof(unsigned int));
1204
1205 // Set the size of the .gnu_incremental_relocs section.
1206 inputs->relocs_section()->set_current_data_size(inputs->get_reloc_count()
1207 * rel_size);
1208
1209 // Set the size of the .gnu_incremental_got_plt section.
1210 Sized_target<size, big_endian>* target =
1211 parameters->sized_target<size, big_endian>();
1212 unsigned int got_count = target->got_entry_count();
1213 unsigned int plt_count = target->plt_entry_count();
1214 unsigned int got_plt_size = 8; // GOT entry count, PLT entry count.
1215 got_plt_size = (got_plt_size + got_count + 3) & ~3; // GOT type array.
1216 got_plt_size += got_count * 8 + plt_count * 4; // GOT array, PLT array.
1217 inputs->got_plt_section()->set_current_data_size(got_plt_size);
1218 }
1219
1220 // Write the contents of the .gnu_incremental_inputs and
1221 // .gnu_incremental_symtab sections.
1222
1223 template<int size, bool big_endian>
1224 void
1225 Output_section_incremental_inputs<size, big_endian>::do_write(Output_file* of)
1226 {
1227 const Incremental_inputs* inputs = this->inputs_;
1228 Stringpool* strtab = inputs->get_stringpool();
1229
1230 // Get a view into the .gnu_incremental_inputs section.
1231 const off_t off = this->offset();
1232 const off_t oview_size = this->data_size();
1233 unsigned char* const oview = of->get_output_view(off, oview_size);
1234 unsigned char* pov = oview;
1235
1236 // Get a view into the .gnu_incremental_symtab section.
1237 const off_t symtab_off = inputs->symtab_section()->offset();
1238 const off_t symtab_size = inputs->symtab_section()->data_size();
1239 unsigned char* const symtab_view = of->get_output_view(symtab_off,
1240 symtab_size);
1241
1242 // Allocate an array of linked list heads for the .gnu_incremental_symtab
1243 // section. Each element corresponds to a global symbol in the output
1244 // symbol table, and points to the head of the linked list that threads
1245 // through the object file input entries. The value of each element
1246 // is the section-relative offset to a global symbol entry in a
1247 // supplemental information block.
1248 unsigned int global_sym_count = this->symtab_->output_count();
1249 unsigned int* global_syms = new unsigned int[global_sym_count];
1250 memset(global_syms, 0, global_sym_count * sizeof(unsigned int));
1251
1252 // Write the section header.
1253 Stringpool::Key command_line_key = inputs->command_line_key();
1254 pov = this->write_header(pov, inputs->input_file_count(),
1255 strtab->get_offset_from_key(command_line_key));
1256
1257 // Write the list of input files.
1258 pov = this->write_input_files(oview, pov, strtab);
1259
1260 // Write the supplemental information blocks for each input file.
1261 pov = this->write_info_blocks(oview, pov, strtab, global_syms,
1262 global_sym_count);
1263
1264 gold_assert(pov - oview == oview_size);
1265
1266 // Write the .gnu_incremental_symtab section.
1267 gold_assert(global_sym_count * 4 == symtab_size);
1268 this->write_symtab(symtab_view, global_syms, global_sym_count);
1269
1270 delete[] global_syms;
1271
1272 // Write the .gnu_incremental_got_plt section.
1273 const off_t got_plt_off = inputs->got_plt_section()->offset();
1274 const off_t got_plt_size = inputs->got_plt_section()->data_size();
1275 unsigned char* const got_plt_view = of->get_output_view(got_plt_off,
1276 got_plt_size);
1277 this->write_got_plt(got_plt_view, got_plt_size);
1278
1279 of->write_output_view(off, oview_size, oview);
1280 of->write_output_view(symtab_off, symtab_size, symtab_view);
1281 of->write_output_view(got_plt_off, got_plt_size, got_plt_view);
1282 }
1283
1284 // Write the section header: version, input file count, offset of command line
1285 // in the string table, and 4 bytes of padding.
1286
1287 template<int size, bool big_endian>
1288 unsigned char*
1289 Output_section_incremental_inputs<size, big_endian>::write_header(
1290 unsigned char* pov,
1291 unsigned int input_file_count,
1292 section_offset_type command_line_offset)
1293 {
1294 Swap32::writeval(pov, INCREMENTAL_LINK_VERSION);
1295 Swap32::writeval(pov + 4, input_file_count);
1296 Swap32::writeval(pov + 8, command_line_offset);
1297 Swap32::writeval(pov + 12, 0);
1298 return pov + this->header_size;
1299 }
1300
1301 // Write the input file entries.
1302
1303 template<int size, bool big_endian>
1304 unsigned char*
1305 Output_section_incremental_inputs<size, big_endian>::write_input_files(
1306 unsigned char* oview,
1307 unsigned char* pov,
1308 Stringpool* strtab)
1309 {
1310 const Incremental_inputs* inputs = this->inputs_;
1311
1312 for (Incremental_inputs::Input_list::const_iterator p =
1313 inputs->input_files().begin();
1314 p != inputs->input_files().end();
1315 ++p)
1316 {
1317 gold_assert(static_cast<unsigned int>(pov - oview) == (*p)->get_offset());
1318 section_offset_type filename_offset =
1319 strtab->get_offset_from_key((*p)->get_filename_key());
1320 const Timespec& mtime = (*p)->get_mtime();
1321 unsigned int flags = (*p)->type();
1322 if ((*p)->is_in_system_directory())
1323 flags |= INCREMENTAL_INPUT_IN_SYSTEM_DIR;
1324 Swap32::writeval(pov, filename_offset);
1325 Swap32::writeval(pov + 4, (*p)->get_info_offset());
1326 Swap64::writeval(pov + 8, mtime.seconds);
1327 Swap32::writeval(pov + 16, mtime.nanoseconds);
1328 Swap16::writeval(pov + 20, flags);
1329 Swap16::writeval(pov + 22, (*p)->arg_serial());
1330 pov += this->input_entry_size;
1331 }
1332 return pov;
1333 }
1334
1335 // Write the supplemental information blocks.
1336
1337 template<int size, bool big_endian>
1338 unsigned char*
1339 Output_section_incremental_inputs<size, big_endian>::write_info_blocks(
1340 unsigned char* oview,
1341 unsigned char* pov,
1342 Stringpool* strtab,
1343 unsigned int* global_syms,
1344 unsigned int global_sym_count)
1345 {
1346 const Incremental_inputs* inputs = this->inputs_;
1347 unsigned int first_global_index = this->symtab_->first_global_index();
1348
1349 for (Incremental_inputs::Input_list::const_iterator p =
1350 inputs->input_files().begin();
1351 p != inputs->input_files().end();
1352 ++p)
1353 {
1354 switch ((*p)->type())
1355 {
1356 case INCREMENTAL_INPUT_SCRIPT:
1357 {
1358 gold_assert(static_cast<unsigned int>(pov - oview)
1359 == (*p)->get_info_offset());
1360 Incremental_script_entry* entry = (*p)->script_entry();
1361 gold_assert(entry != NULL);
1362
1363 // Write the object count.
1364 unsigned int nobjects = entry->get_object_count();
1365 Swap32::writeval(pov, nobjects);
1366 pov += 4;
1367
1368 // For each object, write the offset to its input file entry.
1369 for (unsigned int i = 0; i < nobjects; ++i)
1370 {
1371 Incremental_input_entry* obj = entry->get_object(i);
1372 Swap32::writeval(pov, obj->get_offset());
1373 pov += 4;
1374 }
1375 }
1376 break;
1377
1378 case INCREMENTAL_INPUT_OBJECT:
1379 case INCREMENTAL_INPUT_ARCHIVE_MEMBER:
1380 {
1381 gold_assert(static_cast<unsigned int>(pov - oview)
1382 == (*p)->get_info_offset());
1383 Incremental_object_entry* entry = (*p)->object_entry();
1384 gold_assert(entry != NULL);
1385 const Object* obj = entry->object();
1386 const Relobj* relobj = static_cast<const Relobj*>(obj);
1387 const Object::Symbols* syms = obj->get_global_symbols();
1388 // Write the input section count and global symbol count.
1389 unsigned int nsections = entry->get_input_section_count();
1390 unsigned int nsyms = syms->size();
1391 off_t locals_offset = relobj->local_symbol_offset();
1392 unsigned int nlocals = relobj->output_local_symbol_count();
1393 unsigned int first_dynrel = relobj->first_dyn_reloc();
1394 unsigned int ndynrel = relobj->dyn_reloc_count();
1395 Swap32::writeval(pov, nsections);
1396 Swap32::writeval(pov + 4, nsyms);
1397 Swap32::writeval(pov + 8, static_cast<unsigned int>(locals_offset));
1398 Swap32::writeval(pov + 12, nlocals);
1399 Swap32::writeval(pov + 16, first_dynrel);
1400 Swap32::writeval(pov + 20, ndynrel);
1401 pov += 24;
1402
1403 // Build a temporary array to map input section indexes
1404 // from the original object file index to the index in the
1405 // incremental info table.
1406 unsigned int* index_map = new unsigned int[obj->shnum()];
1407 memset(index_map, 0, obj->shnum() * sizeof(unsigned int));
1408
1409 // For each input section, write the name, output section index,
1410 // offset within output section, and input section size.
1411 for (unsigned int i = 0; i < nsections; i++)
1412 {
1413 unsigned int shndx = entry->get_input_section_index(i);
1414 index_map[shndx] = i + 1;
1415 Stringpool::Key key = entry->get_input_section_name_key(i);
1416 off_t name_offset = 0;
1417 if (key != 0)
1418 name_offset = strtab->get_offset_from_key(key);
1419 int out_shndx = 0;
1420 off_t out_offset = 0;
1421 off_t sh_size = 0;
1422 Output_section* os = obj->output_section(shndx);
1423 if (os != NULL)
1424 {
1425 out_shndx = os->out_shndx();
1426 out_offset = obj->output_section_offset(shndx);
1427 sh_size = entry->get_input_section_size(i);
1428 }
1429 Swap32::writeval(pov, name_offset);
1430 Swap32::writeval(pov + 4, out_shndx);
1431 Swap::writeval(pov + 8, out_offset);
1432 Swap::writeval(pov + 8 + sizeof_addr, sh_size);
1433 pov += 8 + 2 * sizeof_addr;
1434 }
1435
1436 // For each global symbol, write its associated relocations,
1437 // add it to the linked list of globals, then write the
1438 // supplemental information: global symbol table index,
1439 // input section index, linked list chain pointer, relocation
1440 // count, and offset to the relocations.
1441 for (unsigned int i = 0; i < nsyms; i++)
1442 {
1443 const Symbol* sym = (*syms)[i];
1444 if (sym->is_forwarder())
1445 sym = this->symtab_->resolve_forwards(sym);
1446 unsigned int shndx = 0;
1447 if (sym->source() == Symbol::FROM_OBJECT
1448 && sym->object() == obj
1449 && sym->is_defined())
1450 {
1451 bool is_ordinary;
1452 unsigned int orig_shndx = sym->shndx(&is_ordinary);
1453 if (is_ordinary)
1454 shndx = index_map[orig_shndx];
1455 }
1456 unsigned int symtab_index = sym->symtab_index();
1457 unsigned int chain = 0;
1458 unsigned int first_reloc = 0;
1459 unsigned int nrelocs = obj->get_incremental_reloc_count(i);
1460 if (nrelocs > 0)
1461 {
1462 gold_assert(symtab_index != -1U
1463 && (symtab_index - first_global_index
1464 < global_sym_count));
1465 first_reloc = obj->get_incremental_reloc_base(i);
1466 chain = global_syms[symtab_index - first_global_index];
1467 global_syms[symtab_index - first_global_index] =
1468 pov - oview;
1469 }
1470 Swap32::writeval(pov, symtab_index);
1471 Swap32::writeval(pov + 4, shndx);
1472 Swap32::writeval(pov + 8, chain);
1473 Swap32::writeval(pov + 12, nrelocs);
1474 Swap32::writeval(pov + 16, first_reloc * 3 * sizeof_addr);
1475 pov += 20;
1476 }
1477
1478 delete[] index_map;
1479 }
1480 break;
1481
1482 case INCREMENTAL_INPUT_SHARED_LIBRARY:
1483 {
1484 gold_assert(static_cast<unsigned int>(pov - oview)
1485 == (*p)->get_info_offset());
1486 Incremental_object_entry* entry = (*p)->object_entry();
1487 gold_assert(entry != NULL);
1488 const Object* obj = entry->object();
1489 const Object::Symbols* syms = obj->get_global_symbols();
1490
1491 // Skip the global symbol count for now.
1492 unsigned char* orig_pov = pov;
1493 pov += 4;
1494
1495 // For each global symbol, write the global symbol table index.
1496 unsigned int nsyms = syms->size();
1497 unsigned int nsyms_out = 0;
1498 for (unsigned int i = 0; i < nsyms; i++)
1499 {
1500 const Symbol* sym = (*syms)[i];
1501 if (sym == NULL)
1502 continue;
1503 if (sym->is_forwarder())
1504 sym = this->symtab_->resolve_forwards(sym);
1505 if (sym->symtab_index() == -1U)
1506 continue;
1507 unsigned int def_flag = 0;
1508 if (sym->source() == Symbol::FROM_OBJECT
1509 && sym->object() == obj
1510 && sym->is_defined())
1511 def_flag = 1U << 31;
1512 Swap32::writeval(pov, sym->symtab_index() | def_flag);
1513 pov += 4;
1514 ++nsyms_out;
1515 }
1516
1517 // Now write the global symbol count.
1518 Swap32::writeval(orig_pov, nsyms_out);
1519 }
1520 break;
1521
1522 case INCREMENTAL_INPUT_ARCHIVE:
1523 {
1524 gold_assert(static_cast<unsigned int>(pov - oview)
1525 == (*p)->get_info_offset());
1526 Incremental_archive_entry* entry = (*p)->archive_entry();
1527 gold_assert(entry != NULL);
1528
1529 // Write the member count and unused global symbol count.
1530 unsigned int nmembers = entry->get_member_count();
1531 unsigned int nsyms = entry->get_unused_global_symbol_count();
1532 Swap32::writeval(pov, nmembers);
1533 Swap32::writeval(pov + 4, nsyms);
1534 pov += 8;
1535
1536 // For each member, write the offset to its input file entry.
1537 for (unsigned int i = 0; i < nmembers; ++i)
1538 {
1539 Incremental_object_entry* member = entry->get_member(i);
1540 Swap32::writeval(pov, member->get_offset());
1541 pov += 4;
1542 }
1543
1544 // For each global symbol, write the name offset.
1545 for (unsigned int i = 0; i < nsyms; ++i)
1546 {
1547 Stringpool::Key key = entry->get_unused_global_symbol(i);
1548 Swap32::writeval(pov, strtab->get_offset_from_key(key));
1549 pov += 4;
1550 }
1551 }
1552 break;
1553
1554 default:
1555 gold_unreachable();
1556 }
1557 }
1558 return pov;
1559 }
1560
1561 // Write the contents of the .gnu_incremental_symtab section.
1562
1563 template<int size, bool big_endian>
1564 void
1565 Output_section_incremental_inputs<size, big_endian>::write_symtab(
1566 unsigned char* pov,
1567 unsigned int* global_syms,
1568 unsigned int global_sym_count)
1569 {
1570 for (unsigned int i = 0; i < global_sym_count; ++i)
1571 {
1572 Swap32::writeval(pov, global_syms[i]);
1573 pov += 4;
1574 }
1575 }
1576
1577 // This struct holds the view information needed to write the
1578 // .gnu_incremental_got_plt section.
1579
1580 struct Got_plt_view_info
1581 {
1582 // Start of the GOT type array in the output view.
1583 unsigned char* got_type_p;
1584 // Start of the GOT descriptor array in the output view.
1585 unsigned char* got_desc_p;
1586 // Start of the PLT descriptor array in the output view.
1587 unsigned char* plt_desc_p;
1588 // Number of GOT entries.
1589 unsigned int got_count;
1590 // Number of PLT entries.
1591 unsigned int plt_count;
1592 // Offset of the first non-reserved PLT entry (this is a target-dependent value).
1593 unsigned int first_plt_entry_offset;
1594 // Size of a PLT entry (this is a target-dependent value).
1595 unsigned int plt_entry_size;
1596 // Symbol index to write in the GOT descriptor array. For global symbols,
1597 // this is the global symbol table index; for local symbols, it is the
1598 // local symbol table index.
1599 unsigned int sym_index;
1600 // Input file index to write in the GOT descriptor array. For global
1601 // symbols, this is 0; for local symbols, it is the index of the input
1602 // file entry in the .gnu_incremental_inputs section.
1603 unsigned int input_index;
1604 };
1605
1606 // Functor class for processing a GOT offset list for local symbols.
1607 // Writes the GOT type and symbol index into the GOT type and descriptor
1608 // arrays in the output section.
1609
1610 template<int size, bool big_endian>
1611 class Local_got_offset_visitor : public Got_offset_list::Visitor
1612 {
1613 public:
1614 Local_got_offset_visitor(struct Got_plt_view_info& info)
1615 : info_(info)
1616 { }
1617
1618 void
1619 visit(unsigned int got_type, unsigned int got_offset)
1620 {
1621 unsigned int got_index = got_offset / this->got_entry_size_;
1622 gold_assert(got_index < this->info_.got_count);
1623 // We can only handle GOT entry types in the range 0..0x7e
1624 // because we use a byte array to store them, and we use the
1625 // high bit to flag a local symbol.
1626 gold_assert(got_type < 0x7f);
1627 this->info_.got_type_p[got_index] = got_type | 0x80;
1628 unsigned char* pov = this->info_.got_desc_p + got_index * 8;
1629 elfcpp::Swap<32, big_endian>::writeval(pov, this->info_.sym_index);
1630 elfcpp::Swap<32, big_endian>::writeval(pov + 4, this->info_.input_index);
1631 }
1632
1633 private:
1634 static const unsigned int got_entry_size_ = size / 8;
1635 struct Got_plt_view_info& info_;
1636 };
1637
1638 // Functor class for processing a GOT offset list. Writes the GOT type
1639 // and symbol index into the GOT type and descriptor arrays in the output
1640 // section.
1641
1642 template<int size, bool big_endian>
1643 class Global_got_offset_visitor : public Got_offset_list::Visitor
1644 {
1645 public:
1646 Global_got_offset_visitor(struct Got_plt_view_info& info)
1647 : info_(info)
1648 { }
1649
1650 void
1651 visit(unsigned int got_type, unsigned int got_offset)
1652 {
1653 unsigned int got_index = got_offset / this->got_entry_size_;
1654 gold_assert(got_index < this->info_.got_count);
1655 // We can only handle GOT entry types in the range 0..0x7e
1656 // because we use a byte array to store them, and we use the
1657 // high bit to flag a local symbol.
1658 gold_assert(got_type < 0x7f);
1659 this->info_.got_type_p[got_index] = got_type;
1660 unsigned char* pov = this->info_.got_desc_p + got_index * 8;
1661 elfcpp::Swap<32, big_endian>::writeval(pov, this->info_.sym_index);
1662 elfcpp::Swap<32, big_endian>::writeval(pov + 4, 0);
1663 }
1664
1665 private:
1666 static const unsigned int got_entry_size_ = size / 8;
1667 struct Got_plt_view_info& info_;
1668 };
1669
1670 // Functor class for processing the global symbol table. Processes the
1671 // GOT offset list for the symbol, and writes the symbol table index
1672 // into the PLT descriptor array in the output section.
1673
1674 template<int size, bool big_endian>
1675 class Global_symbol_visitor_got_plt
1676 {
1677 public:
1678 Global_symbol_visitor_got_plt(struct Got_plt_view_info& info)
1679 : info_(info)
1680 { }
1681
1682 void
1683 operator()(const Sized_symbol<size>* sym)
1684 {
1685 typedef Global_got_offset_visitor<size, big_endian> Got_visitor;
1686 const Got_offset_list* got_offsets = sym->got_offset_list();
1687 if (got_offsets != NULL)
1688 {
1689 this->info_.sym_index = sym->symtab_index();
1690 this->info_.input_index = 0;
1691 Got_visitor v(this->info_);
1692 got_offsets->for_all_got_offsets(&v);
1693 }
1694 if (sym->has_plt_offset())
1695 {
1696 unsigned int plt_index =
1697 ((sym->plt_offset() - this->info_.first_plt_entry_offset)
1698 / this->info_.plt_entry_size);
1699 gold_assert(plt_index < this->info_.plt_count);
1700 unsigned char* pov = this->info_.plt_desc_p + plt_index * 4;
1701 elfcpp::Swap<32, big_endian>::writeval(pov, sym->symtab_index());
1702 }
1703 }
1704
1705 private:
1706 struct Got_plt_view_info& info_;
1707 };
1708
1709 // Write the contents of the .gnu_incremental_got_plt section.
1710
1711 template<int size, bool big_endian>
1712 void
1713 Output_section_incremental_inputs<size, big_endian>::write_got_plt(
1714 unsigned char* pov,
1715 off_t view_size)
1716 {
1717 Sized_target<size, big_endian>* target =
1718 parameters->sized_target<size, big_endian>();
1719
1720 // Set up the view information for the functors.
1721 struct Got_plt_view_info view_info;
1722 view_info.got_count = target->got_entry_count();
1723 view_info.plt_count = target->plt_entry_count();
1724 view_info.first_plt_entry_offset = target->first_plt_entry_offset();
1725 view_info.plt_entry_size = target->plt_entry_size();
1726 view_info.got_type_p = pov + 8;
1727 view_info.got_desc_p = (view_info.got_type_p
1728 + ((view_info.got_count + 3) & ~3));
1729 view_info.plt_desc_p = view_info.got_desc_p + view_info.got_count * 8;
1730
1731 gold_assert(pov + view_size ==
1732 view_info.plt_desc_p + view_info.plt_count * 4);
1733
1734 // Write the section header.
1735 Swap32::writeval(pov, view_info.got_count);
1736 Swap32::writeval(pov + 4, view_info.plt_count);
1737
1738 // Initialize the GOT type array to 0xff (reserved).
1739 memset(view_info.got_type_p, 0xff, view_info.got_count);
1740
1741 // Write the incremental GOT descriptors for local symbols.
1742 typedef Local_got_offset_visitor<size, big_endian> Got_visitor;
1743 for (Incremental_inputs::Input_list::const_iterator p =
1744 this->inputs_->input_files().begin();
1745 p != this->inputs_->input_files().end();
1746 ++p)
1747 {
1748 if ((*p)->type() != INCREMENTAL_INPUT_OBJECT
1749 && (*p)->type() != INCREMENTAL_INPUT_ARCHIVE_MEMBER)
1750 continue;
1751 Incremental_object_entry* entry = (*p)->object_entry();
1752 gold_assert(entry != NULL);
1753 const Object* obj = entry->object();
1754 gold_assert(obj != NULL);
1755 view_info.input_index = (*p)->get_file_index();
1756 Got_visitor v(view_info);
1757 obj->for_all_local_got_entries(&v);
1758 }
1759
1760 // Write the incremental GOT and PLT descriptors for global symbols.
1761 typedef Global_symbol_visitor_got_plt<size, big_endian> Symbol_visitor;
1762 symtab_->for_all_symbols<size, Symbol_visitor>(Symbol_visitor(view_info));
1763 }
1764
1765 // Class Sized_relobj_incr. Most of these methods are not used for
1766 // Incremental objects, but are required to be implemented by the
1767 // base class Object.
1768
1769 template<int size, bool big_endian>
1770 Sized_relobj_incr<size, big_endian>::Sized_relobj_incr(
1771 const std::string& name,
1772 Sized_incremental_binary<size, big_endian>* ibase,
1773 unsigned int input_file_index)
1774 : Sized_relobj<size, big_endian>(name, NULL), ibase_(ibase),
1775 input_file_index_(input_file_index),
1776 input_reader_(ibase->inputs_reader().input_file(input_file_index)),
1777 local_symbol_count_(0), output_local_dynsym_count_(0),
1778 local_symbol_index_(0), local_symbol_offset_(0), local_dynsym_offset_(0),
1779 symbols_(), incr_reloc_offset_(-1U), incr_reloc_count_(0),
1780 incr_reloc_output_index_(0), incr_relocs_(NULL), local_symbols_()
1781 {
1782 if (this->input_reader_.is_in_system_directory())
1783 this->set_is_in_system_directory();
1784 const unsigned int shnum = this->input_reader_.get_input_section_count() + 1;
1785 this->set_shnum(shnum);
1786 ibase->set_input_object(input_file_index, this);
1787 }
1788
1789 // Read the symbols.
1790
1791 template<int size, bool big_endian>
1792 void
1793 Sized_relobj_incr<size, big_endian>::do_read_symbols(Read_symbols_data*)
1794 {
1795 gold_unreachable();
1796 }
1797
1798 // Lay out the input sections.
1799
1800 template<int size, bool big_endian>
1801 void
1802 Sized_relobj_incr<size, big_endian>::do_layout(
1803 Symbol_table*,
1804 Layout* layout,
1805 Read_symbols_data*)
1806 {
1807 const unsigned int shnum = this->shnum();
1808 Incremental_inputs* incremental_inputs = layout->incremental_inputs();
1809 gold_assert(incremental_inputs != NULL);
1810 Output_sections& out_sections(this->output_sections());
1811 out_sections.resize(shnum);
1812 this->section_offsets().resize(shnum);
1813 for (unsigned int i = 1; i < shnum; i++)
1814 {
1815 typename Input_entry_reader::Input_section_info sect =
1816 this->input_reader_.get_input_section(i - 1);
1817 // Add the section to the incremental inputs layout.
1818 incremental_inputs->report_input_section(this, i, sect.name,
1819 sect.sh_size);
1820 if (sect.output_shndx == 0 || sect.sh_offset == -1)
1821 continue;
1822 Output_section* os = this->ibase_->output_section(sect.output_shndx);
1823 gold_assert(os != NULL);
1824 out_sections[i] = os;
1825 this->section_offsets()[i] = static_cast<Address>(sect.sh_offset);
1826 }
1827 }
1828
1829 // Layout sections whose layout was deferred while waiting for
1830 // input files from a plugin.
1831 template<int size, bool big_endian>
1832 void
1833 Sized_relobj_incr<size, big_endian>::do_layout_deferred_sections(Layout*)
1834 {
1835 }
1836
1837 // Add the symbols to the symbol table.
1838
1839 template<int size, bool big_endian>
1840 void
1841 Sized_relobj_incr<size, big_endian>::do_add_symbols(
1842 Symbol_table* symtab,
1843 Read_symbols_data*,
1844 Layout*)
1845 {
1846 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
1847 unsigned char symbuf[sym_size];
1848 elfcpp::Sym<size, big_endian> sym(symbuf);
1849 elfcpp::Sym_write<size, big_endian> osym(symbuf);
1850
1851 typedef typename elfcpp::Elf_types<size>::Elf_WXword Elf_size_type;
1852
1853 unsigned int nsyms = this->input_reader_.get_global_symbol_count();
1854 this->symbols_.resize(nsyms);
1855
1856 Incremental_binary::View symtab_view(NULL);
1857 unsigned int symtab_count;
1858 elfcpp::Elf_strtab strtab(NULL, 0);
1859 this->ibase_->get_symtab_view(&symtab_view, &symtab_count, &strtab);
1860
1861 Incremental_symtab_reader<big_endian> isymtab(this->ibase_->symtab_reader());
1862 unsigned int isym_count = isymtab.symbol_count();
1863 unsigned int first_global = symtab_count - isym_count;
1864
1865 const unsigned char* sym_p;
1866 for (unsigned int i = 0; i < nsyms; ++i)
1867 {
1868 Incremental_global_symbol_reader<big_endian> info =
1869 this->input_reader_.get_global_symbol_reader(i);
1870 unsigned int output_symndx = info.output_symndx();
1871 sym_p = symtab_view.data() + output_symndx * sym_size;
1872 elfcpp::Sym<size, big_endian> gsym(sym_p);
1873 const char* name;
1874 if (!strtab.get_c_string(gsym.get_st_name(), &name))
1875 name = "";
1876
1877 typename elfcpp::Elf_types<size>::Elf_Addr v = gsym.get_st_value();
1878 unsigned int shndx = gsym.get_st_shndx();
1879 elfcpp::STB st_bind = gsym.get_st_bind();
1880 elfcpp::STT st_type = gsym.get_st_type();
1881
1882 // Local hidden symbols start out as globals, but get converted to
1883 // to local during output.
1884 if (st_bind == elfcpp::STB_LOCAL)
1885 st_bind = elfcpp::STB_GLOBAL;
1886
1887 unsigned int input_shndx = info.shndx();
1888 if (input_shndx == 0)
1889 {
1890 shndx = elfcpp::SHN_UNDEF;
1891 v = 0;
1892 }
1893 else if (shndx != elfcpp::SHN_ABS)
1894 {
1895 // Find the input section and calculate the section-relative value.
1896 gold_assert(shndx != elfcpp::SHN_UNDEF);
1897 Output_section* os = this->ibase_->output_section(shndx);
1898 gold_assert(os != NULL && os->has_fixed_layout());
1899 typename Input_entry_reader::Input_section_info sect =
1900 this->input_reader_.get_input_section(input_shndx - 1);
1901 gold_assert(sect.output_shndx == shndx);
1902 if (st_type != elfcpp::STT_TLS)
1903 v -= os->address();
1904 v -= sect.sh_offset;
1905 shndx = input_shndx;
1906 }
1907
1908 osym.put_st_name(0);
1909 osym.put_st_value(v);
1910 osym.put_st_size(gsym.get_st_size());
1911 osym.put_st_info(st_bind, st_type);
1912 osym.put_st_other(gsym.get_st_other());
1913 osym.put_st_shndx(shndx);
1914
1915 this->symbols_[i] =
1916 symtab->add_from_incrobj(this, name, NULL, &sym);
1917 this->ibase_->add_global_symbol(output_symndx - first_global,
1918 this->symbols_[i]);
1919 }
1920 }
1921
1922 // Return TRUE if we should include this object from an archive library.
1923
1924 template<int size, bool big_endian>
1925 Archive::Should_include
1926 Sized_relobj_incr<size, big_endian>::do_should_include_member(
1927 Symbol_table*,
1928 Layout*,
1929 Read_symbols_data*,
1930 std::string*)
1931 {
1932 gold_unreachable();
1933 }
1934
1935 // Iterate over global symbols, calling a visitor class V for each.
1936
1937 template<int size, bool big_endian>
1938 void
1939 Sized_relobj_incr<size, big_endian>::do_for_all_global_symbols(
1940 Read_symbols_data*,
1941 Library_base::Symbol_visitor_base*)
1942 {
1943 // This routine is not used for incremental objects.
1944 }
1945
1946 // Get the size of a section.
1947
1948 template<int size, bool big_endian>
1949 uint64_t
1950 Sized_relobj_incr<size, big_endian>::do_section_size(unsigned int)
1951 {
1952 gold_unreachable();
1953 }
1954
1955 // Get the name of a section.
1956
1957 template<int size, bool big_endian>
1958 std::string
1959 Sized_relobj_incr<size, big_endian>::do_section_name(unsigned int)
1960 {
1961 gold_unreachable();
1962 }
1963
1964 // Return a view of the contents of a section.
1965
1966 template<int size, bool big_endian>
1967 Object::Location
1968 Sized_relobj_incr<size, big_endian>::do_section_contents(unsigned int)
1969 {
1970 gold_unreachable();
1971 }
1972
1973 // Return section flags.
1974
1975 template<int size, bool big_endian>
1976 uint64_t
1977 Sized_relobj_incr<size, big_endian>::do_section_flags(unsigned int)
1978 {
1979 gold_unreachable();
1980 }
1981
1982 // Return section entsize.
1983
1984 template<int size, bool big_endian>
1985 uint64_t
1986 Sized_relobj_incr<size, big_endian>::do_section_entsize(unsigned int)
1987 {
1988 gold_unreachable();
1989 }
1990
1991 // Return section address.
1992
1993 template<int size, bool big_endian>
1994 uint64_t
1995 Sized_relobj_incr<size, big_endian>::do_section_address(unsigned int)
1996 {
1997 gold_unreachable();
1998 }
1999
2000 // Return section type.
2001
2002 template<int size, bool big_endian>
2003 unsigned int
2004 Sized_relobj_incr<size, big_endian>::do_section_type(unsigned int)
2005 {
2006 gold_unreachable();
2007 }
2008
2009 // Return the section link field.
2010
2011 template<int size, bool big_endian>
2012 unsigned int
2013 Sized_relobj_incr<size, big_endian>::do_section_link(unsigned int)
2014 {
2015 gold_unreachable();
2016 }
2017
2018 // Return the section link field.
2019
2020 template<int size, bool big_endian>
2021 unsigned int
2022 Sized_relobj_incr<size, big_endian>::do_section_info(unsigned int)
2023 {
2024 gold_unreachable();
2025 }
2026
2027 // Return the section alignment.
2028
2029 template<int size, bool big_endian>
2030 uint64_t
2031 Sized_relobj_incr<size, big_endian>::do_section_addralign(unsigned int)
2032 {
2033 gold_unreachable();
2034 }
2035
2036 // Return the Xindex structure to use.
2037
2038 template<int size, bool big_endian>
2039 Xindex*
2040 Sized_relobj_incr<size, big_endian>::do_initialize_xindex()
2041 {
2042 gold_unreachable();
2043 }
2044
2045 // Get symbol counts.
2046
2047 template<int size, bool big_endian>
2048 void
2049 Sized_relobj_incr<size, big_endian>::do_get_global_symbol_counts(
2050 const Symbol_table*, size_t*, size_t*) const
2051 {
2052 gold_unreachable();
2053 }
2054
2055 // Read the relocs.
2056
2057 template<int size, bool big_endian>
2058 void
2059 Sized_relobj_incr<size, big_endian>::do_read_relocs(Read_relocs_data*)
2060 {
2061 }
2062
2063 // Process the relocs to find list of referenced sections. Used only
2064 // during garbage collection.
2065
2066 template<int size, bool big_endian>
2067 void
2068 Sized_relobj_incr<size, big_endian>::do_gc_process_relocs(Symbol_table*,
2069 Layout*,
2070 Read_relocs_data*)
2071 {
2072 gold_unreachable();
2073 }
2074
2075 // Scan the relocs and adjust the symbol table.
2076
2077 template<int size, bool big_endian>
2078 void
2079 Sized_relobj_incr<size, big_endian>::do_scan_relocs(Symbol_table*,
2080 Layout* layout,
2081 Read_relocs_data*)
2082 {
2083 // Count the incremental relocations for this object.
2084 unsigned int nsyms = this->input_reader_.get_global_symbol_count();
2085 this->allocate_incremental_reloc_counts();
2086 for (unsigned int i = 0; i < nsyms; i++)
2087 {
2088 Incremental_global_symbol_reader<big_endian> sym =
2089 this->input_reader_.get_global_symbol_reader(i);
2090 unsigned int reloc_count = sym.reloc_count();
2091 if (reloc_count > 0 && this->incr_reloc_offset_ == -1U)
2092 this->incr_reloc_offset_ = sym.reloc_offset();
2093 this->incr_reloc_count_ += reloc_count;
2094 for (unsigned int j = 0; j < reloc_count; j++)
2095 this->count_incremental_reloc(i);
2096 }
2097 this->incr_reloc_output_index_ =
2098 layout->incremental_inputs()->get_reloc_count();
2099 this->finalize_incremental_relocs(layout, false);
2100
2101 // The incoming incremental relocations may not end up in the same
2102 // location after the incremental update, because the incremental info
2103 // is regenerated in each link. Because the new location may overlap
2104 // with other data in the updated output file, we need to copy the
2105 // relocations into a buffer so that we can still read them safely
2106 // after we start writing updates to the output file.
2107 if (this->incr_reloc_count_ > 0)
2108 {
2109 const Incremental_relocs_reader<size, big_endian>& relocs_reader =
2110 this->ibase_->relocs_reader();
2111 const unsigned int incr_reloc_size = relocs_reader.reloc_size;
2112 unsigned int len = this->incr_reloc_count_ * incr_reloc_size;
2113 this->incr_relocs_ = new unsigned char[len];
2114 memcpy(this->incr_relocs_,
2115 relocs_reader.data(this->incr_reloc_offset_),
2116 len);
2117 }
2118 }
2119
2120 // Count the local symbols.
2121
2122 template<int size, bool big_endian>
2123 void
2124 Sized_relobj_incr<size, big_endian>::do_count_local_symbols(
2125 Stringpool_template<char>* pool,
2126 Stringpool_template<char>*)
2127 {
2128 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
2129
2130 // Set the count of local symbols based on the incremental info.
2131 unsigned int nlocals = this->input_reader_.get_local_symbol_count();
2132 this->local_symbol_count_ = nlocals;
2133 this->local_symbols_.reserve(nlocals);
2134
2135 // Get views of the base file's symbol table and string table.
2136 Incremental_binary::View symtab_view(NULL);
2137 unsigned int symtab_count;
2138 elfcpp::Elf_strtab strtab(NULL, 0);
2139 this->ibase_->get_symtab_view(&symtab_view, &symtab_count, &strtab);
2140
2141 // Read the local symbols from the base file's symbol table.
2142 off_t off = this->input_reader_.get_local_symbol_offset();
2143 const unsigned char* symp = symtab_view.data() + off;
2144 for (unsigned int i = 0; i < nlocals; ++i, symp += sym_size)
2145 {
2146 elfcpp::Sym<size, big_endian> sym(symp);
2147 const char* name;
2148 if (!strtab.get_c_string(sym.get_st_name(), &name))
2149 name = "";
2150 gold_debug(DEBUG_INCREMENTAL, "Local symbol %d: %s", i, name);
2151 name = pool->add(name, true, NULL);
2152 this->local_symbols_.push_back(Local_symbol(name,
2153 sym.get_st_value(),
2154 sym.get_st_size(),
2155 sym.get_st_shndx(),
2156 sym.get_st_type(),
2157 false));
2158 }
2159 }
2160
2161 // Finalize the local symbols.
2162
2163 template<int size, bool big_endian>
2164 unsigned int
2165 Sized_relobj_incr<size, big_endian>::do_finalize_local_symbols(
2166 unsigned int index,
2167 off_t off,
2168 Symbol_table*)
2169 {
2170 this->local_symbol_index_ = index;
2171 this->local_symbol_offset_ = off;
2172 return index + this->local_symbol_count_;
2173 }
2174
2175 // Set the offset where local dynamic symbol information will be stored.
2176
2177 template<int size, bool big_endian>
2178 unsigned int
2179 Sized_relobj_incr<size, big_endian>::do_set_local_dynsym_indexes(
2180 unsigned int index)
2181 {
2182 // FIXME: set local dynsym indexes.
2183 return index;
2184 }
2185
2186 // Set the offset where local dynamic symbol information will be stored.
2187
2188 template<int size, bool big_endian>
2189 unsigned int
2190 Sized_relobj_incr<size, big_endian>::do_set_local_dynsym_offset(off_t)
2191 {
2192 return 0;
2193 }
2194
2195 // Relocate the input sections and write out the local symbols.
2196 // We don't actually do any relocation here. For unchanged input files,
2197 // we reapply relocations only for symbols that have changed; that happens
2198 // in queue_final_tasks. We do need to rewrite the incremental relocations
2199 // for this object.
2200
2201 template<int size, bool big_endian>
2202 void
2203 Sized_relobj_incr<size, big_endian>::do_relocate(const Symbol_table*,
2204 const Layout* layout,
2205 Output_file* of)
2206 {
2207 if (this->incr_reloc_count_ == 0)
2208 return;
2209
2210 const unsigned int incr_reloc_size =
2211 Incremental_relocs_reader<size, big_endian>::reloc_size;
2212
2213 // Get a view for the .gnu_incremental_relocs section.
2214 Incremental_inputs* inputs = layout->incremental_inputs();
2215 gold_assert(inputs != NULL);
2216 const off_t relocs_off = inputs->relocs_section()->offset();
2217 const off_t relocs_size = inputs->relocs_section()->data_size();
2218 unsigned char* const view = of->get_output_view(relocs_off, relocs_size);
2219
2220 // Copy the relocations from the buffer.
2221 off_t off = this->incr_reloc_output_index_ * incr_reloc_size;
2222 unsigned int len = this->incr_reloc_count_ * incr_reloc_size;
2223 memcpy(view + off, this->incr_relocs_, len);
2224
2225 // The output section table may have changed, so we need to map
2226 // the old section index to the new section index for each relocation.
2227 for (unsigned int i = 0; i < this->incr_reloc_count_; ++i)
2228 {
2229 unsigned char* pov = view + off + i * incr_reloc_size;
2230 unsigned int shndx = elfcpp::Swap<32, big_endian>::readval(pov + 4);
2231 Output_section* os = this->ibase_->output_section(shndx);
2232 gold_assert(os != NULL);
2233 shndx = os->out_shndx();
2234 elfcpp::Swap<32, big_endian>::writeval(pov + 4, shndx);
2235 }
2236
2237 of->write_output_view(off, len, view);
2238
2239 // Get views into the output file for the portions of the symbol table
2240 // and the dynamic symbol table that we will be writing.
2241 off_t symtab_off = layout->symtab_section()->offset();
2242 off_t output_size = this->local_symbol_count_ * This::sym_size;
2243 unsigned char* oview = NULL;
2244 if (output_size > 0)
2245 oview = of->get_output_view(symtab_off + this->local_symbol_offset_,
2246 output_size);
2247
2248 off_t dyn_output_size = this->output_local_dynsym_count_ * sym_size;
2249 unsigned char* dyn_oview = NULL;
2250 if (dyn_output_size > 0)
2251 dyn_oview = of->get_output_view(this->local_dynsym_offset_,
2252 dyn_output_size);
2253
2254 // Write the local symbols.
2255 unsigned char* ov = oview;
2256 unsigned char* dyn_ov = dyn_oview;
2257 const Stringpool* sympool = layout->sympool();
2258 const Stringpool* dynpool = layout->dynpool();
2259 Output_symtab_xindex* symtab_xindex = layout->symtab_xindex();
2260 Output_symtab_xindex* dynsym_xindex = layout->dynsym_xindex();
2261 for (unsigned int i = 0; i < this->local_symbol_count_; ++i)
2262 {
2263 Local_symbol& lsym(this->local_symbols_[i]);
2264
2265 bool is_ordinary;
2266 unsigned int st_shndx = this->adjust_sym_shndx(i, lsym.st_shndx,
2267 &is_ordinary);
2268 if (is_ordinary)
2269 {
2270 Output_section* os = this->ibase_->output_section(st_shndx);
2271 st_shndx = os->out_shndx();
2272 if (st_shndx >= elfcpp::SHN_LORESERVE)
2273 {
2274 symtab_xindex->add(this->local_symbol_index_ + i, st_shndx);
2275 if (lsym.needs_dynsym_entry)
2276 dynsym_xindex->add(lsym.output_dynsym_index, st_shndx);
2277 st_shndx = elfcpp::SHN_XINDEX;
2278 }
2279 }
2280
2281 // Write the symbol to the output symbol table.
2282 {
2283 elfcpp::Sym_write<size, big_endian> osym(ov);
2284 osym.put_st_name(sympool->get_offset(lsym.name));
2285 osym.put_st_value(lsym.st_value);
2286 osym.put_st_size(lsym.st_size);
2287 osym.put_st_info(elfcpp::STB_LOCAL,
2288 static_cast<elfcpp::STT>(lsym.st_type));
2289 osym.put_st_other(0);
2290 osym.put_st_shndx(st_shndx);
2291 ov += sym_size;
2292 }
2293
2294 // Write the symbol to the output dynamic symbol table.
2295 if (lsym.needs_dynsym_entry)
2296 {
2297 gold_assert(dyn_ov < dyn_oview + dyn_output_size);
2298 elfcpp::Sym_write<size, big_endian> osym(dyn_ov);
2299 osym.put_st_name(dynpool->get_offset(lsym.name));
2300 osym.put_st_value(lsym.st_value);
2301 osym.put_st_size(lsym.st_size);
2302 osym.put_st_info(elfcpp::STB_LOCAL,
2303 static_cast<elfcpp::STT>(lsym.st_type));
2304 osym.put_st_other(0);
2305 osym.put_st_shndx(st_shndx);
2306 dyn_ov += sym_size;
2307 }
2308 }
2309
2310 if (output_size > 0)
2311 {
2312 gold_assert(ov - oview == output_size);
2313 of->write_output_view(symtab_off + this->local_symbol_offset_,
2314 output_size, oview);
2315 }
2316
2317 if (dyn_output_size > 0)
2318 {
2319 gold_assert(dyn_ov - dyn_oview == dyn_output_size);
2320 of->write_output_view(this->local_dynsym_offset_, dyn_output_size,
2321 dyn_oview);
2322 }
2323 }
2324
2325 // Set the offset of a section.
2326
2327 template<int size, bool big_endian>
2328 void
2329 Sized_relobj_incr<size, big_endian>::do_set_section_offset(unsigned int,
2330 uint64_t)
2331 {
2332 }
2333
2334 // Class Sized_incr_dynobj. Most of these methods are not used for
2335 // Incremental objects, but are required to be implemented by the
2336 // base class Object.
2337
2338 template<int size, bool big_endian>
2339 Sized_incr_dynobj<size, big_endian>::Sized_incr_dynobj(
2340 const std::string& name,
2341 Sized_incremental_binary<size, big_endian>* ibase,
2342 unsigned int input_file_index)
2343 : Dynobj(name, NULL), ibase_(ibase),
2344 input_file_index_(input_file_index),
2345 input_reader_(ibase->inputs_reader().input_file(input_file_index)),
2346 symbols_()
2347 {
2348 if (this->input_reader_.is_in_system_directory())
2349 this->set_is_in_system_directory();
2350 this->set_shnum(0);
2351 }
2352
2353 // Read the symbols.
2354
2355 template<int size, bool big_endian>
2356 void
2357 Sized_incr_dynobj<size, big_endian>::do_read_symbols(Read_symbols_data*)
2358 {
2359 gold_unreachable();
2360 }
2361
2362 // Lay out the input sections.
2363
2364 template<int size, bool big_endian>
2365 void
2366 Sized_incr_dynobj<size, big_endian>::do_layout(
2367 Symbol_table*,
2368 Layout*,
2369 Read_symbols_data*)
2370 {
2371 }
2372
2373 // Add the symbols to the symbol table.
2374
2375 template<int size, bool big_endian>
2376 void
2377 Sized_incr_dynobj<size, big_endian>::do_add_symbols(
2378 Symbol_table* symtab,
2379 Read_symbols_data*,
2380 Layout*)
2381 {
2382 const int sym_size = elfcpp::Elf_sizes<size>::sym_size;
2383 unsigned char symbuf[sym_size];
2384 elfcpp::Sym<size, big_endian> sym(symbuf);
2385 elfcpp::Sym_write<size, big_endian> osym(symbuf);
2386
2387 typedef typename elfcpp::Elf_types<size>::Elf_WXword Elf_size_type;
2388
2389 unsigned int nsyms = this->input_reader_.get_global_symbol_count();
2390 this->symbols_.resize(nsyms);
2391
2392 Incremental_binary::View symtab_view(NULL);
2393 unsigned int symtab_count;
2394 elfcpp::Elf_strtab strtab(NULL, 0);
2395 this->ibase_->get_symtab_view(&symtab_view, &symtab_count, &strtab);
2396
2397 Incremental_symtab_reader<big_endian> isymtab(this->ibase_->symtab_reader());
2398 unsigned int isym_count = isymtab.symbol_count();
2399 unsigned int first_global = symtab_count - isym_count;
2400
2401 const unsigned char* sym_p;
2402 for (unsigned int i = 0; i < nsyms; ++i)
2403 {
2404 bool is_def;
2405 unsigned int output_symndx =
2406 this->input_reader_.get_output_symbol_index(i, &is_def);
2407 sym_p = symtab_view.data() + output_symndx * sym_size;
2408 elfcpp::Sym<size, big_endian> gsym(sym_p);
2409 const char* name;
2410 if (!strtab.get_c_string(gsym.get_st_name(), &name))
2411 name = "";
2412
2413 typename elfcpp::Elf_types<size>::Elf_Addr v;
2414 unsigned int shndx;
2415 elfcpp::STB st_bind = gsym.get_st_bind();
2416 elfcpp::STT st_type = gsym.get_st_type();
2417
2418 // Local hidden symbols start out as globals, but get converted to
2419 // to local during output.
2420 if (st_bind == elfcpp::STB_LOCAL)
2421 st_bind = elfcpp::STB_GLOBAL;
2422
2423 if (!is_def)
2424 {
2425 shndx = elfcpp::SHN_UNDEF;
2426 v = 0;
2427 }
2428 else
2429 {
2430 // For a symbol defined in a shared object, the section index
2431 // is meaningless, as long as it's not SHN_UNDEF.
2432 shndx = 1;
2433 v = gsym.get_st_value();
2434 }
2435
2436 osym.put_st_name(0);
2437 osym.put_st_value(v);
2438 osym.put_st_size(gsym.get_st_size());
2439 osym.put_st_info(st_bind, st_type);
2440 osym.put_st_other(gsym.get_st_other());
2441 osym.put_st_shndx(shndx);
2442
2443 this->symbols_[i] =
2444 symtab->add_from_incrobj<size, big_endian>(this, name, NULL, &sym);
2445 this->ibase_->add_global_symbol(output_symndx - first_global,
2446 this->symbols_[i]);
2447 }
2448 }
2449
2450 // Return TRUE if we should include this object from an archive library.
2451
2452 template<int size, bool big_endian>
2453 Archive::Should_include
2454 Sized_incr_dynobj<size, big_endian>::do_should_include_member(
2455 Symbol_table*,
2456 Layout*,
2457 Read_symbols_data*,
2458 std::string*)
2459 {
2460 gold_unreachable();
2461 }
2462
2463 // Iterate over global symbols, calling a visitor class V for each.
2464
2465 template<int size, bool big_endian>
2466 void
2467 Sized_incr_dynobj<size, big_endian>::do_for_all_global_symbols(
2468 Read_symbols_data*,
2469 Library_base::Symbol_visitor_base*)
2470 {
2471 // This routine is not used for dynamic libraries.
2472 }
2473
2474 // Iterate over local symbols, calling a visitor class V for each GOT offset
2475 // associated with a local symbol.
2476
2477 template<int size, bool big_endian>
2478 void
2479 Sized_incr_dynobj<size, big_endian>::do_for_all_local_got_entries(
2480 Got_offset_list::Visitor*) const
2481 {
2482 }
2483
2484 // Get the size of a section.
2485
2486 template<int size, bool big_endian>
2487 uint64_t
2488 Sized_incr_dynobj<size, big_endian>::do_section_size(unsigned int)
2489 {
2490 gold_unreachable();
2491 }
2492
2493 // Get the name of a section.
2494
2495 template<int size, bool big_endian>
2496 std::string
2497 Sized_incr_dynobj<size, big_endian>::do_section_name(unsigned int)
2498 {
2499 gold_unreachable();
2500 }
2501
2502 // Return a view of the contents of a section.
2503
2504 template<int size, bool big_endian>
2505 Object::Location
2506 Sized_incr_dynobj<size, big_endian>::do_section_contents(unsigned int)
2507 {
2508 gold_unreachable();
2509 }
2510
2511 // Return section flags.
2512
2513 template<int size, bool big_endian>
2514 uint64_t
2515 Sized_incr_dynobj<size, big_endian>::do_section_flags(unsigned int)
2516 {
2517 gold_unreachable();
2518 }
2519
2520 // Return section entsize.
2521
2522 template<int size, bool big_endian>
2523 uint64_t
2524 Sized_incr_dynobj<size, big_endian>::do_section_entsize(unsigned int)
2525 {
2526 gold_unreachable();
2527 }
2528
2529 // Return section address.
2530
2531 template<int size, bool big_endian>
2532 uint64_t
2533 Sized_incr_dynobj<size, big_endian>::do_section_address(unsigned int)
2534 {
2535 gold_unreachable();
2536 }
2537
2538 // Return section type.
2539
2540 template<int size, bool big_endian>
2541 unsigned int
2542 Sized_incr_dynobj<size, big_endian>::do_section_type(unsigned int)
2543 {
2544 gold_unreachable();
2545 }
2546
2547 // Return the section link field.
2548
2549 template<int size, bool big_endian>
2550 unsigned int
2551 Sized_incr_dynobj<size, big_endian>::do_section_link(unsigned int)
2552 {
2553 gold_unreachable();
2554 }
2555
2556 // Return the section link field.
2557
2558 template<int size, bool big_endian>
2559 unsigned int
2560 Sized_incr_dynobj<size, big_endian>::do_section_info(unsigned int)
2561 {
2562 gold_unreachable();
2563 }
2564
2565 // Return the section alignment.
2566
2567 template<int size, bool big_endian>
2568 uint64_t
2569 Sized_incr_dynobj<size, big_endian>::do_section_addralign(unsigned int)
2570 {
2571 gold_unreachable();
2572 }
2573
2574 // Return the Xindex structure to use.
2575
2576 template<int size, bool big_endian>
2577 Xindex*
2578 Sized_incr_dynobj<size, big_endian>::do_initialize_xindex()
2579 {
2580 gold_unreachable();
2581 }
2582
2583 // Get symbol counts.
2584
2585 template<int size, bool big_endian>
2586 void
2587 Sized_incr_dynobj<size, big_endian>::do_get_global_symbol_counts(
2588 const Symbol_table*, size_t*, size_t*) const
2589 {
2590 gold_unreachable();
2591 }
2592
2593 // Allocate an incremental object of the appropriate size and endianness.
2594
2595 Object*
2596 make_sized_incremental_object(
2597 Incremental_binary* ibase,
2598 unsigned int input_file_index,
2599 Incremental_input_type input_type,
2600 const Incremental_binary::Input_reader* input_reader)
2601 {
2602 Object* obj = NULL;
2603 std::string name(input_reader->filename());
2604
2605 switch (parameters->size_and_endianness())
2606 {
2607 #ifdef HAVE_TARGET_32_LITTLE
2608 case Parameters::TARGET_32_LITTLE:
2609 {
2610 Sized_incremental_binary<32, false>* sized_ibase =
2611 static_cast<Sized_incremental_binary<32, false>*>(ibase);
2612 if (input_type == INCREMENTAL_INPUT_SHARED_LIBRARY)
2613 obj = new Sized_incr_dynobj<32, false>(name, sized_ibase,
2614 input_file_index);
2615 else
2616 obj = new Sized_relobj_incr<32, false>(name, sized_ibase,
2617 input_file_index);
2618 }
2619 break;
2620 #endif
2621 #ifdef HAVE_TARGET_32_BIG
2622 case Parameters::TARGET_32_BIG:
2623 {
2624 Sized_incremental_binary<32, true>* sized_ibase =
2625 static_cast<Sized_incremental_binary<32, true>*>(ibase);
2626 if (input_type == INCREMENTAL_INPUT_SHARED_LIBRARY)
2627 obj = new Sized_incr_dynobj<32, true>(name, sized_ibase,
2628 input_file_index);
2629 else
2630 obj = new Sized_relobj_incr<32, true>(name, sized_ibase,
2631 input_file_index);
2632 }
2633 break;
2634 #endif
2635 #ifdef HAVE_TARGET_64_LITTLE
2636 case Parameters::TARGET_64_LITTLE:
2637 {
2638 Sized_incremental_binary<64, false>* sized_ibase =
2639 static_cast<Sized_incremental_binary<64, false>*>(ibase);
2640 if (input_type == INCREMENTAL_INPUT_SHARED_LIBRARY)
2641 obj = new Sized_incr_dynobj<64, false>(name, sized_ibase,
2642 input_file_index);
2643 else
2644 obj = new Sized_relobj_incr<64, false>(name, sized_ibase,
2645 input_file_index);
2646 }
2647 break;
2648 #endif
2649 #ifdef HAVE_TARGET_64_BIG
2650 case Parameters::TARGET_64_BIG:
2651 {
2652 Sized_incremental_binary<64, true>* sized_ibase =
2653 static_cast<Sized_incremental_binary<64, true>*>(ibase);
2654 if (input_type == INCREMENTAL_INPUT_SHARED_LIBRARY)
2655 obj = new Sized_incr_dynobj<64, true>(name, sized_ibase,
2656 input_file_index);
2657 else
2658 obj = new Sized_relobj_incr<64, true>(name, sized_ibase,
2659 input_file_index);
2660 }
2661 break;
2662 #endif
2663 default:
2664 gold_unreachable();
2665 }
2666
2667 gold_assert(obj != NULL);
2668 return obj;
2669 }
2670
2671 // Copy the unused symbols from the incremental input info.
2672 // We need to do this because we may be overwriting the incremental
2673 // input info in the base file before we write the new incremental
2674 // info.
2675 void
2676 Incremental_library::copy_unused_symbols()
2677 {
2678 unsigned int symcount = this->input_reader_->get_unused_symbol_count();
2679 this->unused_symbols_.reserve(symcount);
2680 for (unsigned int i = 0; i < symcount; ++i)
2681 {
2682 std::string name(this->input_reader_->get_unused_symbol(i));
2683 this->unused_symbols_.push_back(name);
2684 }
2685 }
2686
2687 // Iterator for unused global symbols in the library.
2688 void
2689 Incremental_library::do_for_all_unused_symbols(Symbol_visitor_base* v) const
2690 {
2691 for (Symbol_list::const_iterator p = this->unused_symbols_.begin();
2692 p != this->unused_symbols_.end();
2693 ++p)
2694 v->visit(p->c_str());
2695 }
2696
2697 // Instantiate the templates we need.
2698
2699 #ifdef HAVE_TARGET_32_LITTLE
2700 template
2701 class Sized_incremental_binary<32, false>;
2702
2703 template
2704 class Sized_relobj_incr<32, false>;
2705
2706 template
2707 class Sized_incr_dynobj<32, false>;
2708 #endif
2709
2710 #ifdef HAVE_TARGET_32_BIG
2711 template
2712 class Sized_incremental_binary<32, true>;
2713
2714 template
2715 class Sized_relobj_incr<32, true>;
2716
2717 template
2718 class Sized_incr_dynobj<32, true>;
2719 #endif
2720
2721 #ifdef HAVE_TARGET_64_LITTLE
2722 template
2723 class Sized_incremental_binary<64, false>;
2724
2725 template
2726 class Sized_relobj_incr<64, false>;
2727
2728 template
2729 class Sized_incr_dynobj<64, false>;
2730 #endif
2731
2732 #ifdef HAVE_TARGET_64_BIG
2733 template
2734 class Sized_incremental_binary<64, true>;
2735
2736 template
2737 class Sized_relobj_incr<64, true>;
2738
2739 template
2740 class Sized_incr_dynobj<64, true>;
2741 #endif
2742
2743 } // End namespace gold.
This page took 0.087382 seconds and 5 git commands to generate.