1 // inremental.cc -- incremental linking support for gold
3 // Copyright 2009, 2010 Free Software Foundation, Inc.
4 // Written by Mikolaj Zalewski <mikolajz@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.
26 #include "libiberty.h"
31 #include "incremental.h"
34 #include "target-select.h"
38 // Version information. Will change frequently during the development, later
39 // we could think about backward (and forward?) compatibility.
40 const unsigned int INCREMENTAL_LINK_VERSION
= 1;
42 // This class manages the .gnu_incremental_inputs section, which holds
43 // the header information, a directory of input files, and separate
44 // entries for each input file.
46 template<int size
, bool big_endian
>
47 class Output_section_incremental_inputs
: public Output_section_data
50 Output_section_incremental_inputs(const Incremental_inputs
* inputs
,
51 const Symbol_table
* symtab
)
52 : Output_section_data(size
/ 8), inputs_(inputs
), symtab_(symtab
)
56 // Set the final data size.
58 set_final_data_size();
60 // Write the data to the file.
62 do_write(Output_file
*);
64 // Write to a map file.
66 do_print_to_mapfile(Mapfile
* mapfile
) const
67 { mapfile
->print_output_data(this, _("** incremental_inputs")); }
70 // Write the section header.
72 write_header(unsigned char* pov
, unsigned int input_file_count
,
73 section_offset_type command_line_offset
);
75 // Write the input file entries.
77 write_input_files(unsigned char* oview
, unsigned char* pov
,
80 // Write the supplemental information blocks.
82 write_info_blocks(unsigned char* oview
, unsigned char* pov
,
83 Stringpool
* strtab
, unsigned int* global_syms
,
84 unsigned int global_sym_count
);
86 // Write the contents of the .gnu_incremental_symtab section.
88 write_symtab(unsigned char* pov
, unsigned int* global_syms
,
89 unsigned int global_sym_count
);
91 // Typedefs for writing the data to the output sections.
92 typedef elfcpp::Swap
<size
, big_endian
> Swap
;
93 typedef elfcpp::Swap
<16, big_endian
> Swap16
;
94 typedef elfcpp::Swap
<32, big_endian
> Swap32
;
95 typedef elfcpp::Swap
<64, big_endian
> Swap64
;
97 // Sizes of various structures.
98 static const int sizeof_addr
= size
/ 8;
99 static const int header_size
= 16;
100 static const int input_entry_size
= 24;
102 // The Incremental_inputs object.
103 const Incremental_inputs
* inputs_
;
106 const Symbol_table
* symtab_
;
109 // Inform the user why we don't do an incremental link. Not called in
110 // the obvious case of missing output file. TODO: Is this helpful?
113 vexplain_no_incremental(const char* format
, va_list args
)
116 if (vasprintf(&buf
, format
, args
) < 0)
118 gold_info(_("the link might take longer: "
119 "cannot perform incremental link: %s"), buf
);
124 explain_no_incremental(const char* format
, ...)
127 va_start(args
, format
);
128 vexplain_no_incremental(format
, args
);
135 Incremental_binary::error(const char* format
, ...) const
138 va_start(args
, format
);
139 // Current code only checks if the file can be used for incremental linking,
140 // so errors shouldn't fail the build, but only result in a fallback to a
142 // TODO: when we implement incremental editing of the file, we may need a
143 // flag that will cause errors to be treated seriously.
144 vexplain_no_incremental(format
, args
);
148 // Find the .gnu_incremental_inputs section and related sections.
150 template<int size
, bool big_endian
>
152 Sized_incremental_binary
<size
, big_endian
>::do_find_incremental_inputs_sections(
153 unsigned int* p_inputs_shndx
,
154 unsigned int* p_symtab_shndx
,
155 unsigned int* p_relocs_shndx
,
156 unsigned int* p_strtab_shndx
)
158 unsigned int inputs_shndx
=
159 this->elf_file_
.find_section_by_type(elfcpp::SHT_GNU_INCREMENTAL_INPUTS
);
160 if (inputs_shndx
== elfcpp::SHN_UNDEF
) // Not found.
163 unsigned int symtab_shndx
=
164 this->elf_file_
.find_section_by_type(elfcpp::SHT_GNU_INCREMENTAL_SYMTAB
);
165 if (symtab_shndx
== elfcpp::SHN_UNDEF
) // Not found.
167 if (this->elf_file_
.section_link(symtab_shndx
) != inputs_shndx
)
170 unsigned int relocs_shndx
=
171 this->elf_file_
.find_section_by_type(elfcpp::SHT_GNU_INCREMENTAL_RELOCS
);
172 if (relocs_shndx
== elfcpp::SHN_UNDEF
) // Not found.
174 if (this->elf_file_
.section_link(relocs_shndx
) != inputs_shndx
)
177 unsigned int strtab_shndx
= this->elf_file_
.section_link(inputs_shndx
);
178 if (strtab_shndx
== elfcpp::SHN_UNDEF
179 || strtab_shndx
> this->elf_file_
.shnum()
180 || this->elf_file_
.section_type(strtab_shndx
) != elfcpp::SHT_STRTAB
)
183 if (p_inputs_shndx
!= NULL
)
184 *p_inputs_shndx
= inputs_shndx
;
185 if (p_symtab_shndx
!= NULL
)
186 *p_symtab_shndx
= symtab_shndx
;
187 if (p_relocs_shndx
!= NULL
)
188 *p_relocs_shndx
= relocs_shndx
;
189 if (p_strtab_shndx
!= NULL
)
190 *p_strtab_shndx
= strtab_shndx
;
194 // Determine whether an incremental link based on the existing output file
197 template<int size
, bool big_endian
>
199 Sized_incremental_binary
<size
, big_endian
>::do_check_inputs(
200 Incremental_inputs
* incremental_inputs
)
202 unsigned int inputs_shndx
;
203 unsigned int symtab_shndx
;
204 unsigned int relocs_shndx
;
205 unsigned int strtab_shndx
;
207 if (!do_find_incremental_inputs_sections(&inputs_shndx
, &symtab_shndx
,
208 &relocs_shndx
, &strtab_shndx
))
210 explain_no_incremental(_("no incremental data from previous build"));
214 Location
inputs_location(this->elf_file_
.section_contents(inputs_shndx
));
215 Location
symtab_location(this->elf_file_
.section_contents(symtab_shndx
));
216 Location
relocs_location(this->elf_file_
.section_contents(relocs_shndx
));
217 Location
strtab_location(this->elf_file_
.section_contents(strtab_shndx
));
219 View
inputs_view(view(inputs_location
));
220 View
symtab_view(view(symtab_location
));
221 View
relocs_view(view(relocs_location
));
222 View
strtab_view(view(strtab_location
));
224 elfcpp::Elf_strtab
strtab(strtab_view
.data(), strtab_location
.data_size
);
226 Incremental_inputs_reader
<size
, big_endian
>
227 incoming_inputs(inputs_view
.data(), strtab
);
229 if (incoming_inputs
.version() != INCREMENTAL_LINK_VERSION
)
231 explain_no_incremental(_("different version of incremental build data"));
235 if (incremental_inputs
->command_line() != incoming_inputs
.command_line())
237 explain_no_incremental(_("command line changed"));
241 // TODO: compare incremental_inputs->inputs() with entries in data_view.
249 // Create a Sized_incremental_binary object of the specified size and
250 // endianness. Fails if the target architecture is not supported.
252 template<int size
, bool big_endian
>
254 make_sized_incremental_binary(Output_file
* file
,
255 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
257 Target
* target
= select_target(ehdr
.get_e_machine(), size
, big_endian
,
258 ehdr
.get_e_ident()[elfcpp::EI_OSABI
],
259 ehdr
.get_e_ident()[elfcpp::EI_ABIVERSION
]);
262 explain_no_incremental(_("unsupported ELF machine number %d"),
263 ehdr
.get_e_machine());
267 if (!parameters
->target_valid())
268 set_parameters_target(target
);
269 else if (target
!= ¶meters
->target())
270 gold_error(_("%s: incompatible target"), file
->filename());
272 return new Sized_incremental_binary
<size
, big_endian
>(file
, ehdr
, target
);
275 } // End of anonymous namespace.
277 // Create an Incremental_binary object for FILE. Returns NULL is this is not
278 // possible, e.g. FILE is not an ELF file or has an unsupported target. FILE
282 open_incremental_binary(Output_file
* file
)
284 off_t filesize
= file
->filesize();
285 int want
= elfcpp::Elf_recognizer::max_header_size
;
289 const unsigned char* p
= file
->get_input_view(0, want
);
290 if (!elfcpp::Elf_recognizer::is_elf_file(p
, want
))
292 explain_no_incremental(_("output is not an ELF file."));
297 bool big_endian
= false;
299 if (!elfcpp::Elf_recognizer::is_valid_header(p
, want
, &size
, &big_endian
,
302 explain_no_incremental(error
.c_str());
306 Incremental_binary
* result
= NULL
;
311 #ifdef HAVE_TARGET_32_BIG
312 result
= make_sized_incremental_binary
<32, true>(
313 file
, elfcpp::Ehdr
<32, true>(p
));
315 explain_no_incremental(_("unsupported file: 32-bit, big-endian"));
320 #ifdef HAVE_TARGET_32_LITTLE
321 result
= make_sized_incremental_binary
<32, false>(
322 file
, elfcpp::Ehdr
<32, false>(p
));
324 explain_no_incremental(_("unsupported file: 32-bit, little-endian"));
332 #ifdef HAVE_TARGET_64_BIG
333 result
= make_sized_incremental_binary
<64, true>(
334 file
, elfcpp::Ehdr
<64, true>(p
));
336 explain_no_incremental(_("unsupported file: 64-bit, big-endian"));
341 #ifdef HAVE_TARGET_64_LITTLE
342 result
= make_sized_incremental_binary
<64, false>(
343 file
, elfcpp::Ehdr
<64, false>(p
));
345 explain_no_incremental(_("unsupported file: 64-bit, little-endian"));
355 // Analyzes the output file to check if incremental linking is possible and
356 // (to be done) what files need to be relinked.
359 Incremental_checker::can_incrementally_link_output_file()
361 Output_file
output(this->output_name_
);
362 if (!output
.open_for_modification())
364 Incremental_binary
* binary
= open_incremental_binary(&output
);
367 return binary
->check_inputs(this->incremental_inputs_
);
370 // Class Incremental_inputs.
372 // Add the command line to the string table, setting
373 // command_line_key_. In incremental builds, the command line is
374 // stored in .gnu_incremental_inputs so that the next linker run can
375 // check if the command line options didn't change.
378 Incremental_inputs::report_command_line(int argc
, const char* const* argv
)
380 // Always store 'gold' as argv[0] to avoid a full relink if the user used a
381 // different path to the linker.
382 std::string
args("gold");
383 // Copied from collect_argv in main.cc.
384 for (int i
= 1; i
< argc
; ++i
)
386 // Adding/removing these options should not result in a full relink.
387 if (strcmp(argv
[i
], "--incremental-changed") == 0
388 || strcmp(argv
[i
], "--incremental-unchanged") == 0
389 || strcmp(argv
[i
], "--incremental-unknown") == 0)
393 // Now append argv[i], but with all single-quotes escaped
394 const char* argpos
= argv
[i
];
397 const int len
= strcspn(argpos
, "'");
398 args
.append(argpos
, len
);
399 if (argpos
[len
] == '\0')
401 args
.append("'\"'\"'");
407 this->command_line_
= args
;
408 this->strtab_
->add(this->command_line_
.c_str(), false,
409 &this->command_line_key_
);
412 // Record the input archive file ARCHIVE. This is called by the
413 // Add_archive_symbols task before determining which archive members
414 // to include. We create the Incremental_archive_entry here and
415 // attach it to the Archive, but we do not add it to the list of
416 // input objects until report_archive_end is called.
419 Incremental_inputs::report_archive_begin(Archive
* arch
)
421 Stringpool::Key filename_key
;
422 Timespec mtime
= arch
->file().get_mtime();
424 this->strtab_
->add(arch
->filename().c_str(), false, &filename_key
);
425 Incremental_archive_entry
* entry
=
426 new Incremental_archive_entry(filename_key
, arch
, mtime
);
427 arch
->set_incremental_info(entry
);
430 // Finish recording the input archive file ARCHIVE. This is called by the
431 // Add_archive_symbols task after determining which archive members
435 Incremental_inputs::report_archive_end(Archive
* arch
)
437 Incremental_archive_entry
* entry
= arch
->incremental_info();
439 gold_assert(entry
!= NULL
);
441 // Collect unused global symbols.
442 for (Archive::Unused_symbol_iterator p
= arch
->unused_symbols_begin();
443 p
!= arch
->unused_symbols_end();
446 Stringpool::Key symbol_key
;
447 this->strtab_
->add(*p
, true, &symbol_key
);
448 entry
->add_unused_global_symbol(symbol_key
);
450 this->inputs_
.push_back(entry
);
453 // Record the input object file OBJ. If ARCH is not NULL, attach
454 // the object file to the archive. This is called by the
455 // Add_symbols task after finding out the type of the file.
458 Incremental_inputs::report_object(Object
* obj
, Archive
* arch
)
460 Stringpool::Key filename_key
;
461 Timespec mtime
= obj
->input_file()->file().get_mtime();
463 this->strtab_
->add(obj
->name().c_str(), false, &filename_key
);
464 Incremental_object_entry
* obj_entry
=
465 new Incremental_object_entry(filename_key
, obj
, mtime
);
466 this->inputs_
.push_back(obj_entry
);
470 Incremental_archive_entry
* arch_entry
= arch
->incremental_info();
471 gold_assert(arch_entry
!= NULL
);
472 arch_entry
->add_object(obj_entry
);
475 this->current_object_
= obj
;
476 this->current_object_entry_
= obj_entry
;
479 // Record the input object file OBJ. If ARCH is not NULL, attach
480 // the object file to the archive. This is called by the
481 // Add_symbols task after finding out the type of the file.
484 Incremental_inputs::report_input_section(Object
* obj
, unsigned int shndx
,
485 const char* name
, off_t sh_size
)
487 Stringpool::Key key
= 0;
490 this->strtab_
->add(name
, true, &key
);
492 gold_assert(obj
== this->current_object_
);
493 this->current_object_entry_
->add_input_section(shndx
, key
, sh_size
);
496 // Record that the input argument INPUT is a script SCRIPT. This is
497 // called by read_script after parsing the script and reading the list
498 // of inputs added by this script.
501 Incremental_inputs::report_script(const std::string
& filename
,
502 Script_info
* script
, Timespec mtime
)
504 Stringpool::Key filename_key
;
506 this->strtab_
->add(filename
.c_str(), false, &filename_key
);
507 Incremental_script_entry
* entry
=
508 new Incremental_script_entry(filename_key
, script
, mtime
);
509 this->inputs_
.push_back(entry
);
512 // Finalize the incremental link information. Called from
516 Incremental_inputs::finalize()
518 // Finalize the string table.
519 this->strtab_
->set_string_offsets();
522 // Create the .gnu_incremental_inputs, _symtab, and _relocs input sections.
525 Incremental_inputs::create_data_sections(Symbol_table
* symtab
)
527 switch (parameters
->size_and_endianness())
529 #ifdef HAVE_TARGET_32_LITTLE
530 case Parameters::TARGET_32_LITTLE
:
531 this->inputs_section_
=
532 new Output_section_incremental_inputs
<32, false>(this, symtab
);
535 #ifdef HAVE_TARGET_32_BIG
536 case Parameters::TARGET_32_BIG
:
537 this->inputs_section_
=
538 new Output_section_incremental_inputs
<32, true>(this, symtab
);
541 #ifdef HAVE_TARGET_64_LITTLE
542 case Parameters::TARGET_64_LITTLE
:
543 this->inputs_section_
=
544 new Output_section_incremental_inputs
<64, false>(this, symtab
);
547 #ifdef HAVE_TARGET_64_BIG
548 case Parameters::TARGET_64_BIG
:
549 this->inputs_section_
=
550 new Output_section_incremental_inputs
<64, true>(this, symtab
);
556 this->symtab_section_
= new Output_data_space(4, "** incremental_symtab");
557 this->relocs_section_
= new Output_data_space(4, "** incremental_relocs");
560 // Return the sh_entsize value for the .gnu_incremental_relocs section.
562 Incremental_inputs::relocs_entsize() const
564 return 8 + 2 * parameters
->target().get_size() / 8;
567 // Class Output_section_incremental_inputs.
569 // Finalize the offsets for each input section and supplemental info block,
570 // and set the final data size of the incremental output sections.
572 template<int size
, bool big_endian
>
574 Output_section_incremental_inputs
<size
, big_endian
>::set_final_data_size()
576 const Incremental_inputs
* inputs
= this->inputs_
;
577 const unsigned int sizeof_addr
= size
/ 8;
578 const unsigned int rel_size
= 8 + 2 * sizeof_addr
;
580 // Offset of each input entry.
581 unsigned int input_offset
= this->header_size
;
583 // Offset of each supplemental info block.
584 unsigned int info_offset
= this->header_size
;
585 info_offset
+= this->input_entry_size
* inputs
->input_file_count();
587 // Count each input file and its supplemental information block.
588 for (Incremental_inputs::Input_list::const_iterator p
=
589 inputs
->input_files().begin();
590 p
!= inputs
->input_files().end();
593 // Set the offset of the input file entry.
594 (*p
)->set_offset(input_offset
);
595 input_offset
+= this->input_entry_size
;
597 // Set the offset of the supplemental info block.
598 switch ((*p
)->type())
600 case INCREMENTAL_INPUT_SCRIPT
:
601 // No supplemental info for a script.
602 (*p
)->set_info_offset(0);
604 case INCREMENTAL_INPUT_OBJECT
:
605 case INCREMENTAL_INPUT_ARCHIVE_MEMBER
:
607 Incremental_object_entry
*entry
= (*p
)->object_entry();
608 gold_assert(entry
!= NULL
);
609 (*p
)->set_info_offset(info_offset
);
610 // Input section count + global symbol count.
612 // Each input section.
613 info_offset
+= (entry
->get_input_section_count()
614 * (8 + 2 * sizeof_addr
));
615 // Each global symbol.
616 const Object::Symbols
* syms
= entry
->object()->get_global_symbols();
617 info_offset
+= syms
->size() * 16;
620 case INCREMENTAL_INPUT_SHARED_LIBRARY
:
622 Incremental_object_entry
*entry
= (*p
)->object_entry();
623 gold_assert(entry
!= NULL
);
624 (*p
)->set_info_offset(info_offset
);
625 // Global symbol count.
627 // Each global symbol.
628 const Object::Symbols
* syms
= entry
->object()->get_global_symbols();
629 unsigned int nsyms
= syms
!= NULL
? syms
->size() : 0;
630 info_offset
+= nsyms
* 4;
633 case INCREMENTAL_INPUT_ARCHIVE
:
635 Incremental_archive_entry
*entry
= (*p
)->archive_entry();
636 gold_assert(entry
!= NULL
);
637 (*p
)->set_info_offset(info_offset
);
638 // Member count + unused global symbol count.
641 info_offset
+= (entry
->get_member_count() * 4);
642 // Each global symbol.
643 info_offset
+= (entry
->get_unused_global_symbol_count() * 4);
651 this->set_data_size(info_offset
);
653 // Set the size of the .gnu_incremental_symtab section.
654 inputs
->symtab_section()->set_current_data_size(this->symtab_
->output_count()
655 * sizeof(unsigned int));
657 // Set the size of the .gnu_incremental_relocs section.
658 inputs
->relocs_section()->set_current_data_size(inputs
->get_reloc_count()
662 // Write the contents of the .gnu_incremental_inputs and
663 // .gnu_incremental_symtab sections.
665 template<int size
, bool big_endian
>
667 Output_section_incremental_inputs
<size
, big_endian
>::do_write(Output_file
* of
)
669 const Incremental_inputs
* inputs
= this->inputs_
;
670 Stringpool
* strtab
= inputs
->get_stringpool();
672 // Get a view into the .gnu_incremental_inputs section.
673 const off_t off
= this->offset();
674 const off_t oview_size
= this->data_size();
675 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
676 unsigned char* pov
= oview
;
678 // Get a view into the .gnu_incremental_symtab section.
679 const off_t symtab_off
= inputs
->symtab_section()->offset();
680 const off_t symtab_size
= inputs
->symtab_section()->data_size();
681 unsigned char* const symtab_view
= of
->get_output_view(symtab_off
,
684 // Allocate an array of linked list heads for the .gnu_incremental_symtab
685 // section. Each element corresponds to a global symbol in the output
686 // symbol table, and points to the head of the linked list that threads
687 // through the object file input entries. The value of each element
688 // is the section-relative offset to a global symbol entry in a
689 // supplemental information block.
690 unsigned int global_sym_count
= this->symtab_
->output_count();
691 unsigned int* global_syms
= new unsigned int[global_sym_count
];
692 memset(global_syms
, 0, global_sym_count
* sizeof(unsigned int));
694 // Write the section header.
695 Stringpool::Key command_line_key
= inputs
->command_line_key();
696 pov
= this->write_header(pov
, inputs
->input_file_count(),
697 strtab
->get_offset_from_key(command_line_key
));
699 // Write the list of input files.
700 pov
= this->write_input_files(oview
, pov
, strtab
);
702 // Write the supplemental information blocks for each input file.
703 pov
= this->write_info_blocks(oview
, pov
, strtab
, global_syms
,
706 gold_assert(pov
- oview
== oview_size
);
708 // Write the .gnu_incremental_symtab section.
709 gold_assert(global_sym_count
* 4 == symtab_size
);
710 this->write_symtab(symtab_view
, global_syms
, global_sym_count
);
712 delete[] global_syms
;
714 of
->write_output_view(off
, oview_size
, oview
);
715 of
->write_output_view(symtab_off
, symtab_size
, symtab_view
);
718 // Write the section header: version, input file count, offset of command line
719 // in the string table, and 4 bytes of padding.
721 template<int size
, bool big_endian
>
723 Output_section_incremental_inputs
<size
, big_endian
>::write_header(
725 unsigned int input_file_count
,
726 section_offset_type command_line_offset
)
728 Swap32::writeval(pov
, INCREMENTAL_LINK_VERSION
);
729 Swap32::writeval(pov
+ 4, input_file_count
);
730 Swap32::writeval(pov
+ 8, command_line_offset
);
731 Swap32::writeval(pov
+ 12, 0);
732 return pov
+ this->header_size
;
735 // Write the input file entries.
737 template<int size
, bool big_endian
>
739 Output_section_incremental_inputs
<size
, big_endian
>::write_input_files(
740 unsigned char* oview
,
744 const Incremental_inputs
* inputs
= this->inputs_
;
746 for (Incremental_inputs::Input_list::const_iterator p
=
747 inputs
->input_files().begin();
748 p
!= inputs
->input_files().end();
751 gold_assert(pov
- oview
== (*p
)->get_offset());
752 section_offset_type filename_offset
=
753 strtab
->get_offset_from_key((*p
)->get_filename_key());
754 const Timespec
& mtime
= (*p
)->get_mtime();
755 Swap32::writeval(pov
, filename_offset
);
756 Swap32::writeval(pov
+ 4, (*p
)->get_info_offset());
757 Swap64::writeval(pov
+ 8, mtime
.seconds
);
758 Swap32::writeval(pov
+ 16, mtime
.nanoseconds
);
759 Swap16::writeval(pov
+ 20, (*p
)->type());
760 Swap16::writeval(pov
+ 22, 0);
761 pov
+= this->input_entry_size
;
766 // Write the supplemental information blocks.
768 template<int size
, bool big_endian
>
770 Output_section_incremental_inputs
<size
, big_endian
>::write_info_blocks(
771 unsigned char* oview
,
774 unsigned int* global_syms
,
775 unsigned int global_sym_count
)
777 const Incremental_inputs
* inputs
= this->inputs_
;
778 unsigned int first_global_index
= this->symtab_
->first_global_index();
780 for (Incremental_inputs::Input_list::const_iterator p
=
781 inputs
->input_files().begin();
782 p
!= inputs
->input_files().end();
785 switch ((*p
)->type())
787 case INCREMENTAL_INPUT_SCRIPT
:
788 // No supplemental info for a script.
791 case INCREMENTAL_INPUT_OBJECT
:
792 case INCREMENTAL_INPUT_ARCHIVE_MEMBER
:
794 gold_assert(pov
- oview
== (*p
)->get_info_offset());
795 Incremental_object_entry
* entry
= (*p
)->object_entry();
796 gold_assert(entry
!= NULL
);
797 const Object
* obj
= entry
->object();
798 const Object::Symbols
* syms
= obj
->get_global_symbols();
799 // Write the input section count and global symbol count.
800 unsigned int nsections
= entry
->get_input_section_count();
801 unsigned int nsyms
= syms
->size();
802 Swap32::writeval(pov
, nsections
);
803 Swap32::writeval(pov
+ 4, nsyms
);
806 // For each input section, write the name, output section index,
807 // offset within output section, and input section size.
808 for (unsigned int i
= 0; i
< nsections
; i
++)
810 Stringpool::Key key
= entry
->get_input_section_name_key(i
);
811 off_t name_offset
= 0;
813 name_offset
= strtab
->get_offset_from_key(key
);
815 off_t out_offset
= 0;
817 Output_section
* os
= obj
->output_section(i
);
820 out_shndx
= os
->out_shndx();
821 out_offset
= obj
->output_section_offset(i
);
822 sh_size
= entry
->get_input_section_size(i
);
824 Swap32::writeval(pov
, name_offset
);
825 Swap32::writeval(pov
+ 4, out_shndx
);
826 Swap::writeval(pov
+ 8, out_offset
);
827 Swap::writeval(pov
+ 8 + sizeof_addr
, sh_size
);
828 pov
+= 8 + 2 * sizeof_addr
;
831 // For each global symbol, write its associated relocations,
832 // add it to the linked list of globals, then write the
833 // supplemental information: global symbol table index,
834 // linked list chain pointer, relocation count, and offset
835 // to the relocations.
836 for (unsigned int i
= 0; i
< nsyms
; i
++)
838 const Symbol
* sym
= (*syms
)[i
];
839 unsigned int symtab_index
= sym
->symtab_index();
840 unsigned int chain
= 0;
841 unsigned int first_reloc
= 0;
842 unsigned int nrelocs
= obj
->get_incremental_reloc_count(i
);
845 gold_assert(symtab_index
!= -1U
846 && (symtab_index
- first_global_index
847 < global_sym_count
));
848 first_reloc
= obj
->get_incremental_reloc_base(i
);
849 chain
= global_syms
[symtab_index
- first_global_index
];
850 global_syms
[symtab_index
- first_global_index
] =
853 Swap32::writeval(pov
, symtab_index
);
854 Swap32::writeval(pov
+ 4, chain
);
855 Swap32::writeval(pov
+ 8, nrelocs
);
856 Swap32::writeval(pov
+ 12, first_reloc
* 3 * sizeof_addr
);
862 case INCREMENTAL_INPUT_SHARED_LIBRARY
:
864 gold_assert(pov
- oview
== (*p
)->get_info_offset());
865 Incremental_object_entry
* entry
= (*p
)->object_entry();
866 gold_assert(entry
!= NULL
);
867 const Object
* obj
= entry
->object();
868 const Object::Symbols
* syms
= obj
->get_global_symbols();
870 // Write the global symbol count.
871 unsigned int nsyms
= syms
!= NULL
? syms
->size() : 0;
872 Swap32::writeval(pov
, nsyms
);
875 // For each global symbol, write the global symbol table index.
876 for (unsigned int i
= 0; i
< nsyms
; i
++)
878 const Symbol
* sym
= (*syms
)[i
];
879 Swap32::writeval(pov
, sym
->symtab_index());
885 case INCREMENTAL_INPUT_ARCHIVE
:
887 gold_assert(pov
- oview
== (*p
)->get_info_offset());
888 Incremental_archive_entry
* entry
= (*p
)->archive_entry();
889 gold_assert(entry
!= NULL
);
891 // Write the member count and unused global symbol count.
892 unsigned int nmembers
= entry
->get_member_count();
893 unsigned int nsyms
= entry
->get_unused_global_symbol_count();
894 Swap32::writeval(pov
, nmembers
);
895 Swap32::writeval(pov
+ 4, nsyms
);
898 // For each member, write the offset to its input file entry.
899 for (unsigned int i
= 0; i
< nmembers
; ++i
)
901 Incremental_object_entry
* member
= entry
->get_member(i
);
902 Swap32::writeval(pov
, member
->get_offset());
906 // For each global symbol, write the name offset.
907 for (unsigned int i
= 0; i
< nsyms
; ++i
)
909 Stringpool::Key key
= entry
->get_unused_global_symbol(i
);
910 Swap32::writeval(pov
, strtab
->get_offset_from_key(key
));
923 // Write the contents of the .gnu_incremental_symtab section.
925 template<int size
, bool big_endian
>
927 Output_section_incremental_inputs
<size
, big_endian
>::write_symtab(
929 unsigned int* global_syms
,
930 unsigned int global_sym_count
)
932 for (unsigned int i
= 0; i
< global_sym_count
; ++i
)
934 Swap32::writeval(pov
, global_syms
[i
]);
939 // Instantiate the templates we need.
941 #ifdef HAVE_TARGET_32_LITTLE
943 class Sized_incremental_binary
<32, false>;
946 #ifdef HAVE_TARGET_32_BIG
948 class Sized_incremental_binary
<32, true>;
951 #ifdef HAVE_TARGET_64_LITTLE
953 class Sized_incremental_binary
<64, false>;
956 #ifdef HAVE_TARGET_64_BIG
958 class Sized_incremental_binary
<64, true>;
961 } // End namespace gold.