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.
27 #include "libiberty.h"
33 #include "incremental.h"
37 #include "target-select.h"
44 // Version information. Will change frequently during the development, later
45 // we could think about backward (and forward?) compatibility.
46 const unsigned int INCREMENTAL_LINK_VERSION
= 1;
48 // This class manages the .gnu_incremental_inputs section, which holds
49 // the header information, a directory of input files, and separate
50 // entries for each input file.
52 template<int size
, bool big_endian
>
53 class Output_section_incremental_inputs
: public Output_section_data
56 Output_section_incremental_inputs(const Incremental_inputs
* inputs
,
57 const Symbol_table
* symtab
)
58 : Output_section_data(size
/ 8), inputs_(inputs
), symtab_(symtab
)
62 // This is called to update the section size prior to assigning
63 // the address and file offset.
66 { this->set_final_data_size(); }
68 // Set the final data size.
70 set_final_data_size();
72 // Write the data to the file.
74 do_write(Output_file
*);
76 // Write to a map file.
78 do_print_to_mapfile(Mapfile
* mapfile
) const
79 { mapfile
->print_output_data(this, _("** incremental_inputs")); }
82 // Write the section header.
84 write_header(unsigned char* pov
, unsigned int input_file_count
,
85 section_offset_type command_line_offset
);
87 // Write the input file entries.
89 write_input_files(unsigned char* oview
, unsigned char* pov
,
92 // Write the supplemental information blocks.
94 write_info_blocks(unsigned char* oview
, unsigned char* pov
,
95 Stringpool
* strtab
, unsigned int* global_syms
,
96 unsigned int global_sym_count
);
98 // Write the contents of the .gnu_incremental_symtab section.
100 write_symtab(unsigned char* pov
, unsigned int* global_syms
,
101 unsigned int global_sym_count
);
103 // Write the contents of the .gnu_incremental_got_plt section.
105 write_got_plt(unsigned char* pov
, off_t view_size
);
107 // Typedefs for writing the data to the output sections.
108 typedef elfcpp::Swap
<size
, big_endian
> Swap
;
109 typedef elfcpp::Swap
<16, big_endian
> Swap16
;
110 typedef elfcpp::Swap
<32, big_endian
> Swap32
;
111 typedef elfcpp::Swap
<64, big_endian
> Swap64
;
113 // Sizes of various structures.
114 static const int sizeof_addr
= size
/ 8;
115 static const int header_size
= 16;
116 static const int input_entry_size
= 24;
118 // The Incremental_inputs object.
119 const Incremental_inputs
* inputs_
;
122 const Symbol_table
* symtab_
;
125 // Inform the user why we don't do an incremental link. Not called in
126 // the obvious case of missing output file. TODO: Is this helpful?
129 vexplain_no_incremental(const char* format
, va_list args
)
132 if (vasprintf(&buf
, format
, args
) < 0)
134 gold_info(_("the link might take longer: "
135 "cannot perform incremental link: %s"), buf
);
140 explain_no_incremental(const char* format
, ...)
143 va_start(args
, format
);
144 vexplain_no_incremental(format
, args
);
151 Incremental_binary::error(const char* format
, ...) const
154 va_start(args
, format
);
155 // Current code only checks if the file can be used for incremental linking,
156 // so errors shouldn't fail the build, but only result in a fallback to a
158 // TODO: when we implement incremental editing of the file, we may need a
159 // flag that will cause errors to be treated seriously.
160 vexplain_no_incremental(format
, args
);
164 // Find the .gnu_incremental_inputs section and related sections.
166 template<int size
, bool big_endian
>
168 Sized_incremental_binary
<size
, big_endian
>::find_incremental_inputs_sections(
169 unsigned int* p_inputs_shndx
,
170 unsigned int* p_symtab_shndx
,
171 unsigned int* p_relocs_shndx
,
172 unsigned int* p_got_plt_shndx
,
173 unsigned int* p_strtab_shndx
)
175 unsigned int inputs_shndx
=
176 this->elf_file_
.find_section_by_type(elfcpp::SHT_GNU_INCREMENTAL_INPUTS
);
177 if (inputs_shndx
== elfcpp::SHN_UNDEF
) // Not found.
180 unsigned int symtab_shndx
=
181 this->elf_file_
.find_section_by_type(elfcpp::SHT_GNU_INCREMENTAL_SYMTAB
);
182 if (symtab_shndx
== elfcpp::SHN_UNDEF
) // Not found.
184 if (this->elf_file_
.section_link(symtab_shndx
) != inputs_shndx
)
187 unsigned int relocs_shndx
=
188 this->elf_file_
.find_section_by_type(elfcpp::SHT_GNU_INCREMENTAL_RELOCS
);
189 if (relocs_shndx
== elfcpp::SHN_UNDEF
) // Not found.
191 if (this->elf_file_
.section_link(relocs_shndx
) != inputs_shndx
)
194 unsigned int got_plt_shndx
=
195 this->elf_file_
.find_section_by_type(elfcpp::SHT_GNU_INCREMENTAL_GOT_PLT
);
196 if (got_plt_shndx
== elfcpp::SHN_UNDEF
) // Not found.
198 if (this->elf_file_
.section_link(got_plt_shndx
) != inputs_shndx
)
201 unsigned int strtab_shndx
= this->elf_file_
.section_link(inputs_shndx
);
202 if (strtab_shndx
== elfcpp::SHN_UNDEF
203 || strtab_shndx
> this->elf_file_
.shnum()
204 || this->elf_file_
.section_type(strtab_shndx
) != elfcpp::SHT_STRTAB
)
207 if (p_inputs_shndx
!= NULL
)
208 *p_inputs_shndx
= inputs_shndx
;
209 if (p_symtab_shndx
!= NULL
)
210 *p_symtab_shndx
= symtab_shndx
;
211 if (p_relocs_shndx
!= NULL
)
212 *p_relocs_shndx
= relocs_shndx
;
213 if (p_got_plt_shndx
!= NULL
)
214 *p_got_plt_shndx
= got_plt_shndx
;
215 if (p_strtab_shndx
!= NULL
)
216 *p_strtab_shndx
= strtab_shndx
;
220 // Set up the readers into the incremental info sections.
222 template<int size
, bool big_endian
>
224 Sized_incremental_binary
<size
, big_endian
>::setup_readers()
226 unsigned int inputs_shndx
;
227 unsigned int symtab_shndx
;
228 unsigned int relocs_shndx
;
229 unsigned int got_plt_shndx
;
230 unsigned int strtab_shndx
;
232 if (!this->find_incremental_inputs_sections(&inputs_shndx
, &symtab_shndx
,
233 &relocs_shndx
, &got_plt_shndx
,
237 Location
inputs_location(this->elf_file_
.section_contents(inputs_shndx
));
238 Location
symtab_location(this->elf_file_
.section_contents(symtab_shndx
));
239 Location
relocs_location(this->elf_file_
.section_contents(relocs_shndx
));
240 Location
got_plt_location(this->elf_file_
.section_contents(got_plt_shndx
));
241 Location
strtab_location(this->elf_file_
.section_contents(strtab_shndx
));
243 View inputs_view
= this->view(inputs_location
);
244 View symtab_view
= this->view(symtab_location
);
245 View relocs_view
= this->view(relocs_location
);
246 View got_plt_view
= this->view(got_plt_location
);
247 View strtab_view
= this->view(strtab_location
);
249 elfcpp::Elf_strtab
strtab(strtab_view
.data(), strtab_location
.data_size
);
251 this->inputs_reader_
=
252 Incremental_inputs_reader
<size
, big_endian
>(inputs_view
.data(), strtab
);
253 this->symtab_reader_
=
254 Incremental_symtab_reader
<big_endian
>(symtab_view
.data(),
255 symtab_location
.data_size
);
256 this->relocs_reader_
=
257 Incremental_relocs_reader
<size
, big_endian
>(relocs_view
.data(),
258 relocs_location
.data_size
);
259 this->got_plt_reader_
=
260 Incremental_got_plt_reader
<big_endian
>(got_plt_view
.data());
262 // Find the main symbol table.
263 unsigned int main_symtab_shndx
=
264 this->elf_file_
.find_section_by_type(elfcpp::SHT_SYMTAB
);
265 gold_assert(main_symtab_shndx
!= elfcpp::SHN_UNDEF
);
266 this->main_symtab_loc_
= this->elf_file_
.section_contents(main_symtab_shndx
);
268 // Find the main symbol string table.
269 unsigned int main_strtab_shndx
=
270 this->elf_file_
.section_link(main_symtab_shndx
);
271 gold_assert(main_strtab_shndx
!= elfcpp::SHN_UNDEF
272 && main_strtab_shndx
< this->elf_file_
.shnum());
273 this->main_strtab_loc_
= this->elf_file_
.section_contents(main_strtab_shndx
);
275 // Walk the list of input files (a) to setup an Input_reader for each
276 // input file, and (b) to record maps of files added from archive
277 // libraries and scripts.
278 Incremental_inputs_reader
<size
, big_endian
>& inputs
= this->inputs_reader_
;
279 unsigned int count
= inputs
.input_file_count();
280 this->input_objects_
.resize(count
);
281 this->input_entry_readers_
.reserve(count
);
282 this->library_map_
.resize(count
);
283 this->script_map_
.resize(count
);
284 for (unsigned int i
= 0; i
< count
; i
++)
286 Input_entry_reader input_file
= inputs
.input_file(i
);
287 this->input_entry_readers_
.push_back(Sized_input_reader(input_file
));
288 switch (input_file
.type())
290 case INCREMENTAL_INPUT_OBJECT
:
291 case INCREMENTAL_INPUT_ARCHIVE_MEMBER
:
292 case INCREMENTAL_INPUT_SHARED_LIBRARY
:
293 // No special treatment necessary.
295 case INCREMENTAL_INPUT_ARCHIVE
:
297 Incremental_library
* lib
=
298 new Incremental_library(input_file
.filename(), i
,
299 &this->input_entry_readers_
[i
]);
300 this->library_map_
[i
] = lib
;
301 unsigned int member_count
= input_file
.get_member_count();
302 for (unsigned int j
= 0; j
< member_count
; j
++)
304 int member_offset
= input_file
.get_member_offset(j
);
305 int member_index
= inputs
.input_file_index(member_offset
);
306 this->library_map_
[member_index
] = lib
;
310 case INCREMENTAL_INPUT_SCRIPT
:
312 Script_info
* script
= new Script_info(input_file
.filename());
313 this->script_map_
[i
] = script
;
314 unsigned int object_count
= input_file
.get_object_count();
315 for (unsigned int j
= 0; j
< object_count
; j
++)
317 int object_offset
= input_file
.get_object_offset(j
);
318 int object_index
= inputs
.input_file_index(object_offset
);
319 this->script_map_
[object_index
] = script
;
328 // Initialize the map of global symbols.
329 unsigned int nglobals
= this->symtab_reader_
.symbol_count();
330 this->symbol_map_
.resize(nglobals
);
332 this->has_incremental_info_
= true;
335 // Walk the list of input files given on the command line, and build
336 // a direct map of file index to the corresponding input argument.
339 check_input_args(std::vector
<const Input_argument
*>& input_args_map
,
340 Input_arguments::const_iterator begin
,
341 Input_arguments::const_iterator end
)
343 for (Input_arguments::const_iterator p
= begin
;
349 const Input_file_group
* group
= p
->group();
350 check_input_args(input_args_map
, group
->begin(), group
->end());
352 else if (p
->is_lib())
354 const Input_file_lib
* lib
= p
->lib();
355 check_input_args(input_args_map
, lib
->begin(), lib
->end());
359 gold_assert(p
->is_file());
360 unsigned int arg_serial
= p
->file().arg_serial();
363 gold_assert(arg_serial
<= input_args_map
.size());
364 gold_assert(input_args_map
[arg_serial
- 1] == 0);
365 input_args_map
[arg_serial
- 1] = &*p
;
371 // Determine whether an incremental link based on the existing output file
374 template<int size
, bool big_endian
>
376 Sized_incremental_binary
<size
, big_endian
>::do_check_inputs(
377 const Command_line
& cmdline
,
378 Incremental_inputs
* incremental_inputs
)
380 Incremental_inputs_reader
<size
, big_endian
>& inputs
= this->inputs_reader_
;
382 if (!this->has_incremental_info_
)
384 explain_no_incremental(_("no incremental data from previous build"));
388 if (inputs
.version() != INCREMENTAL_LINK_VERSION
)
390 explain_no_incremental(_("different version of incremental build data"));
394 if (incremental_inputs
->command_line() != inputs
.command_line())
396 explain_no_incremental(_("command line changed"));
400 // Walk the list of input files given on the command line, and build
401 // a direct map of argument serial numbers to the corresponding input
403 this->input_args_map_
.resize(cmdline
.number_of_input_files());
404 check_input_args(this->input_args_map_
, cmdline
.begin(), cmdline
.end());
406 // Walk the list of input files to check for conditions that prevent
407 // an incremental update link.
408 unsigned int count
= inputs
.input_file_count();
409 for (unsigned int i
= 0; i
< count
; i
++)
411 Input_entry_reader input_file
= inputs
.input_file(i
);
412 switch (input_file
.type())
414 case INCREMENTAL_INPUT_OBJECT
:
415 case INCREMENTAL_INPUT_ARCHIVE_MEMBER
:
416 case INCREMENTAL_INPUT_SHARED_LIBRARY
:
417 case INCREMENTAL_INPUT_ARCHIVE
:
418 // No special treatment necessary.
420 case INCREMENTAL_INPUT_SCRIPT
:
421 if (this->do_file_has_changed(i
))
423 explain_no_incremental(_("%s: script file changed"),
424 input_file
.filename());
436 // Return TRUE if input file N has changed since the last incremental link.
438 template<int size
, bool big_endian
>
440 Sized_incremental_binary
<size
, big_endian
>::do_file_has_changed(
441 unsigned int n
) const
443 Input_entry_reader input_file
= this->inputs_reader_
.input_file(n
);
444 Incremental_disposition disp
= INCREMENTAL_CHECK
;
445 const Input_argument
* input_argument
= this->get_input_argument(n
);
446 if (input_argument
!= NULL
)
447 disp
= input_argument
->file().options().incremental_disposition();
449 if (disp
!= INCREMENTAL_CHECK
)
450 return disp
== INCREMENTAL_CHANGED
;
452 const char* filename
= input_file
.filename();
453 Timespec old_mtime
= input_file
.get_mtime();
455 if (!get_mtime(filename
, &new_mtime
))
457 // If we can't open get the current modification time, assume it has
458 // changed. If the file doesn't exist, we'll issue an error when we
459 // try to open it later.
463 if (new_mtime
.seconds
> old_mtime
.seconds
)
465 if (new_mtime
.seconds
== old_mtime
.seconds
466 && new_mtime
.nanoseconds
> old_mtime
.nanoseconds
)
471 // Initialize the layout of the output file based on the existing
474 template<int size
, bool big_endian
>
476 Sized_incremental_binary
<size
, big_endian
>::do_init_layout(Layout
* layout
)
478 typedef elfcpp::Shdr
<size
, big_endian
> Shdr
;
479 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
481 // Get views of the section headers and the section string table.
482 const off_t shoff
= this->elf_file_
.shoff();
483 const unsigned int shnum
= this->elf_file_
.shnum();
484 const unsigned int shstrndx
= this->elf_file_
.shstrndx();
485 Location
shdrs_location(shoff
, shnum
* shdr_size
);
486 Location
shstrndx_location(this->elf_file_
.section_contents(shstrndx
));
487 View shdrs_view
= this->view(shdrs_location
);
488 View shstrndx_view
= this->view(shstrndx_location
);
489 elfcpp::Elf_strtab
shstrtab(shstrndx_view
.data(),
490 shstrndx_location
.data_size
);
492 layout
->set_incremental_base(this);
494 // Initialize the layout.
495 this->section_map_
.resize(shnum
);
496 const unsigned char* pshdr
= shdrs_view
.data() + shdr_size
;
497 for (unsigned int i
= 1; i
< shnum
; i
++)
501 if (!shstrtab
.get_c_string(shdr
.get_sh_name(), &name
))
503 gold_debug(DEBUG_INCREMENTAL
,
504 "Output section: %2d %08lx %08lx %08lx %3d %s",
506 static_cast<long>(shdr
.get_sh_addr()),
507 static_cast<long>(shdr
.get_sh_offset()),
508 static_cast<long>(shdr
.get_sh_size()),
509 shdr
.get_sh_type(), name
? name
: "<null>");
510 this->section_map_
[i
] = layout
->init_fixed_output_section(name
, shdr
);
515 // Mark regions of the input file that must be kept unchanged.
517 template<int size
, bool big_endian
>
519 Sized_incremental_binary
<size
, big_endian
>::do_reserve_layout(
520 unsigned int input_file_index
)
522 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
524 Input_entry_reader input_file
=
525 this->inputs_reader_
.input_file(input_file_index
);
527 if (input_file
.type() == INCREMENTAL_INPUT_SHARED_LIBRARY
)
529 // Reserve the BSS space used for COPY relocations.
530 unsigned int nsyms
= input_file
.get_global_symbol_count();
531 Incremental_binary::View
symtab_view(NULL
);
532 unsigned int symtab_count
;
533 elfcpp::Elf_strtab
strtab(NULL
, 0);
534 this->get_symtab_view(&symtab_view
, &symtab_count
, &strtab
);
535 for (unsigned int i
= 0; i
< nsyms
; ++i
)
539 unsigned int output_symndx
=
540 input_file
.get_output_symbol_index(i
, &is_def
, &is_copy
);
543 const unsigned char* sym_p
= (symtab_view
.data()
544 + output_symndx
* sym_size
);
545 elfcpp::Sym
<size
, big_endian
> gsym(sym_p
);
546 unsigned int shndx
= gsym
.get_st_shndx();
547 if (shndx
< 1 || shndx
>= this->section_map_
.size())
549 Output_section
* os
= this->section_map_
[shndx
];
550 off_t offset
= gsym
.get_st_value() - os
->address();
551 os
->reserve(offset
, gsym
.get_st_size());
552 gold_debug(DEBUG_INCREMENTAL
,
553 "Reserve for COPY reloc: %s, off %d, size %d",
555 static_cast<int>(offset
),
556 static_cast<int>(gsym
.get_st_size()));
562 unsigned int shnum
= input_file
.get_input_section_count();
563 for (unsigned int i
= 0; i
< shnum
; i
++)
565 typename
Input_entry_reader::Input_section_info sect
=
566 input_file
.get_input_section(i
);
567 if (sect
.output_shndx
== 0 || sect
.sh_offset
== -1)
569 Output_section
* os
= this->section_map_
[sect
.output_shndx
];
570 gold_assert(os
!= NULL
);
571 os
->reserve(sect
.sh_offset
, sect
.sh_size
);
575 // Process the GOT and PLT entries from the existing output file.
577 template<int size
, bool big_endian
>
579 Sized_incremental_binary
<size
, big_endian
>::do_process_got_plt(
580 Symbol_table
* symtab
,
583 Incremental_got_plt_reader
<big_endian
> got_plt_reader(this->got_plt_reader());
584 Sized_target
<size
, big_endian
>* target
=
585 parameters
->sized_target
<size
, big_endian
>();
587 // Get the number of symbols in the main symbol table and in the
588 // incremental symbol table. The difference between the two counts
589 // is the index of the first forced-local or global symbol in the
590 // main symbol table.
591 unsigned int symtab_count
=
592 this->main_symtab_loc_
.data_size
/ elfcpp::Elf_sizes
<size
>::sym_size
;
593 unsigned int isym_count
= this->symtab_reader_
.symbol_count();
594 unsigned int first_global
= symtab_count
- isym_count
;
596 // Tell the target how big the GOT and PLT sections are.
597 unsigned int got_count
= got_plt_reader
.get_got_entry_count();
598 unsigned int plt_count
= got_plt_reader
.get_plt_entry_count();
599 Output_data_got
<size
, big_endian
>* got
=
600 target
->init_got_plt_for_update(symtab
, layout
, got_count
, plt_count
);
602 // Read the GOT entries from the base file and build the outgoing GOT.
603 for (unsigned int i
= 0; i
< got_count
; ++i
)
605 unsigned int got_type
= got_plt_reader
.get_got_type(i
);
606 if ((got_type
& 0x7f) == 0x7f)
608 // This is the second entry of a pair.
609 got
->reserve_slot(i
);
612 unsigned int symndx
= got_plt_reader
.get_got_symndx(i
);
615 // This is an entry for a local symbol. Ignore this entry if
616 // the object file was replaced.
617 unsigned int input_index
= got_plt_reader
.get_got_input_index(i
);
618 gold_debug(DEBUG_INCREMENTAL
,
619 "GOT entry %d, type %02x: (local symbol)",
621 Sized_relobj_incr
<size
, big_endian
>* obj
=
622 this->input_object(input_index
);
624 target
->reserve_local_got_entry(i
, obj
, symndx
, got_type
& 0x7f);
628 // This is an entry for a global symbol. GOT_DESC is the symbol
630 // FIXME: This should really be a fatal error (corrupt input).
631 gold_assert(symndx
>= first_global
&& symndx
< symtab_count
);
632 Symbol
* sym
= this->global_symbol(symndx
- first_global
);
633 // Add the GOT entry only if the symbol is still referenced.
634 if (sym
!= NULL
&& sym
->in_reg())
636 gold_debug(DEBUG_INCREMENTAL
,
637 "GOT entry %d, type %02x: %s",
638 i
, got_type
, sym
->name());
639 target
->reserve_global_got_entry(i
, sym
, got_type
);
644 // Read the PLT entries from the base file and pass each to the target.
645 for (unsigned int i
= 0; i
< plt_count
; ++i
)
647 unsigned int plt_desc
= got_plt_reader
.get_plt_desc(i
);
648 // FIXME: This should really be a fatal error (corrupt input).
649 gold_assert(plt_desc
>= first_global
&& plt_desc
< symtab_count
);
650 Symbol
* sym
= this->global_symbol(plt_desc
- first_global
);
651 // Add the PLT entry only if the symbol is still referenced.
654 gold_debug(DEBUG_INCREMENTAL
,
657 target
->register_global_plt_entry(i
, sym
);
662 // Emit COPY relocations from the existing output file.
664 template<int size
, bool big_endian
>
666 Sized_incremental_binary
<size
, big_endian
>::do_emit_copy_relocs(
667 Symbol_table
* symtab
)
669 Sized_target
<size
, big_endian
>* target
=
670 parameters
->sized_target
<size
, big_endian
>();
672 for (typename
Copy_relocs::iterator p
= this->copy_relocs_
.begin();
673 p
!= this->copy_relocs_
.end();
676 if (!(*p
).symbol
->is_copied_from_dynobj())
677 target
->emit_copy_reloc(symtab
, (*p
).symbol
, (*p
).output_section
,
682 // Apply incremental relocations for symbols whose values have changed.
684 template<int size
, bool big_endian
>
686 Sized_incremental_binary
<size
, big_endian
>::do_apply_incremental_relocs(
687 const Symbol_table
* symtab
,
691 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
692 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Addend
;
693 Incremental_symtab_reader
<big_endian
> isymtab(this->symtab_reader());
694 Incremental_relocs_reader
<size
, big_endian
> irelocs(this->relocs_reader());
695 unsigned int nglobals
= isymtab
.symbol_count();
696 const unsigned int incr_reloc_size
= irelocs
.reloc_size
;
698 Relocate_info
<size
, big_endian
> relinfo
;
699 relinfo
.symtab
= symtab
;
700 relinfo
.layout
= layout
;
701 relinfo
.object
= NULL
;
702 relinfo
.reloc_shndx
= 0;
703 relinfo
.reloc_shdr
= NULL
;
704 relinfo
.data_shndx
= 0;
705 relinfo
.data_shdr
= NULL
;
707 Sized_target
<size
, big_endian
>* target
=
708 parameters
->sized_target
<size
, big_endian
>();
710 for (unsigned int i
= 0; i
< nglobals
; i
++)
712 const Symbol
* gsym
= this->global_symbol(i
);
714 // If the symbol is not referenced from any unchanged input files,
715 // we do not need to reapply any of its relocations.
719 // If the symbol is defined in an unchanged file, we do not need to
720 // reapply any of its relocations.
721 if (gsym
->source() == Symbol::FROM_OBJECT
722 && gsym
->object()->is_incremental())
725 gold_debug(DEBUG_INCREMENTAL
,
726 "Applying incremental relocations for global symbol %s [%d]",
729 // Follow the linked list of input symbol table entries for this symbol.
730 // We don't bother to figure out whether the symbol table entry belongs
731 // to a changed or unchanged file because it's easier just to apply all
732 // the relocations -- although we might scribble over an area that has
733 // been reallocated, we do this before copying any new data into the
735 unsigned int offset
= isymtab
.get_list_head(i
);
738 Incremental_global_symbol_reader
<big_endian
> sym_info
=
739 this->inputs_reader().global_symbol_reader_at_offset(offset
);
740 unsigned int r_base
= sym_info
.reloc_offset();
741 unsigned int r_count
= sym_info
.reloc_count();
743 // Apply each relocation for this symbol table entry.
744 for (unsigned int j
= 0; j
< r_count
;
745 ++j
, r_base
+= incr_reloc_size
)
747 unsigned int r_type
= irelocs
.get_r_type(r_base
);
748 unsigned int r_shndx
= irelocs
.get_r_shndx(r_base
);
749 Address r_offset
= irelocs
.get_r_offset(r_base
);
750 Addend r_addend
= irelocs
.get_r_addend(r_base
);
751 Output_section
* os
= this->output_section(r_shndx
);
752 Address address
= os
->address();
753 off_t section_offset
= os
->offset();
754 size_t view_size
= os
->data_size();
755 unsigned char* const view
= of
->get_output_view(section_offset
,
758 gold_debug(DEBUG_INCREMENTAL
,
759 " %08lx: %s + %d: type %d addend %ld",
760 (long)(section_offset
+ r_offset
),
766 target
->apply_relocation(&relinfo
, r_offset
, r_type
, r_addend
,
767 gsym
, view
, address
, view_size
);
769 // FIXME: Do something more efficient if write_output_view
770 // ever becomes more than a no-op.
771 of
->write_output_view(section_offset
, view_size
, view
);
773 offset
= sym_info
.next_offset();
778 // Get a view of the main symbol table and the symbol string table.
780 template<int size
, bool big_endian
>
782 Sized_incremental_binary
<size
, big_endian
>::get_symtab_view(
785 elfcpp::Elf_strtab
* strtab
)
787 *symtab_view
= this->view(this->main_symtab_loc_
);
788 *nsyms
= this->main_symtab_loc_
.data_size
/ elfcpp::Elf_sizes
<size
>::sym_size
;
790 View
strtab_view(this->view(this->main_strtab_loc_
));
791 *strtab
= elfcpp::Elf_strtab(strtab_view
.data(),
792 this->main_strtab_loc_
.data_size
);
798 // Create a Sized_incremental_binary object of the specified size and
799 // endianness. Fails if the target architecture is not supported.
801 template<int size
, bool big_endian
>
803 make_sized_incremental_binary(Output_file
* file
,
804 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
806 Target
* target
= select_target(ehdr
.get_e_machine(), size
, big_endian
,
807 ehdr
.get_e_ident()[elfcpp::EI_OSABI
],
808 ehdr
.get_e_ident()[elfcpp::EI_ABIVERSION
]);
811 explain_no_incremental(_("unsupported ELF machine number %d"),
812 ehdr
.get_e_machine());
816 if (!parameters
->target_valid())
817 set_parameters_target(target
);
818 else if (target
!= ¶meters
->target())
819 gold_error(_("%s: incompatible target"), file
->filename());
821 return new Sized_incremental_binary
<size
, big_endian
>(file
, ehdr
, target
);
824 } // End of anonymous namespace.
826 // Create an Incremental_binary object for FILE. Returns NULL is this is not
827 // possible, e.g. FILE is not an ELF file or has an unsupported target. FILE
831 open_incremental_binary(Output_file
* file
)
833 off_t filesize
= file
->filesize();
834 int want
= elfcpp::Elf_recognizer::max_header_size
;
838 const unsigned char* p
= file
->get_input_view(0, want
);
839 if (!elfcpp::Elf_recognizer::is_elf_file(p
, want
))
841 explain_no_incremental(_("output is not an ELF file."));
846 bool big_endian
= false;
848 if (!elfcpp::Elf_recognizer::is_valid_header(p
, want
, &size
, &big_endian
,
851 explain_no_incremental(error
.c_str());
855 Incremental_binary
* result
= NULL
;
860 #ifdef HAVE_TARGET_32_BIG
861 result
= make_sized_incremental_binary
<32, true>(
862 file
, elfcpp::Ehdr
<32, true>(p
));
864 explain_no_incremental(_("unsupported file: 32-bit, big-endian"));
869 #ifdef HAVE_TARGET_32_LITTLE
870 result
= make_sized_incremental_binary
<32, false>(
871 file
, elfcpp::Ehdr
<32, false>(p
));
873 explain_no_incremental(_("unsupported file: 32-bit, little-endian"));
881 #ifdef HAVE_TARGET_64_BIG
882 result
= make_sized_incremental_binary
<64, true>(
883 file
, elfcpp::Ehdr
<64, true>(p
));
885 explain_no_incremental(_("unsupported file: 64-bit, big-endian"));
890 #ifdef HAVE_TARGET_64_LITTLE
891 result
= make_sized_incremental_binary
<64, false>(
892 file
, elfcpp::Ehdr
<64, false>(p
));
894 explain_no_incremental(_("unsupported file: 64-bit, little-endian"));
904 // Class Incremental_inputs.
906 // Add the command line to the string table, setting
907 // command_line_key_. In incremental builds, the command line is
908 // stored in .gnu_incremental_inputs so that the next linker run can
909 // check if the command line options didn't change.
912 Incremental_inputs::report_command_line(int argc
, const char* const* argv
)
914 // Always store 'gold' as argv[0] to avoid a full relink if the user used a
915 // different path to the linker.
916 std::string
args("gold");
917 // Copied from collect_argv in main.cc.
918 for (int i
= 1; i
< argc
; ++i
)
920 // Adding/removing these options should not result in a full relink.
921 if (strcmp(argv
[i
], "--incremental") == 0
922 || strcmp(argv
[i
], "--incremental-full") == 0
923 || strcmp(argv
[i
], "--incremental-update") == 0
924 || strcmp(argv
[i
], "--incremental-changed") == 0
925 || strcmp(argv
[i
], "--incremental-unchanged") == 0
926 || strcmp(argv
[i
], "--incremental-unknown") == 0
927 || is_prefix_of("--incremental-base=", argv
[i
])
928 || is_prefix_of("--debug=", argv
[i
]))
930 if (strcmp(argv
[i
], "--incremental-base") == 0
931 || strcmp(argv
[i
], "--debug") == 0)
933 // When these options are used without the '=', skip the
934 // following parameter as well.
940 // Now append argv[i], but with all single-quotes escaped
941 const char* argpos
= argv
[i
];
944 const int len
= strcspn(argpos
, "'");
945 args
.append(argpos
, len
);
946 if (argpos
[len
] == '\0')
948 args
.append("'\"'\"'");
954 this->command_line_
= args
;
955 this->strtab_
->add(this->command_line_
.c_str(), false,
956 &this->command_line_key_
);
959 // Record the input archive file ARCHIVE. This is called by the
960 // Add_archive_symbols task before determining which archive members
961 // to include. We create the Incremental_archive_entry here and
962 // attach it to the Archive, but we do not add it to the list of
963 // input objects until report_archive_end is called.
966 Incremental_inputs::report_archive_begin(Library_base
* arch
,
967 unsigned int arg_serial
,
968 Script_info
* script_info
)
970 Stringpool::Key filename_key
;
971 Timespec mtime
= arch
->get_mtime();
973 // For a file loaded from a script, don't record its argument serial number.
974 if (script_info
!= NULL
)
977 this->strtab_
->add(arch
->filename().c_str(), false, &filename_key
);
978 Incremental_archive_entry
* entry
=
979 new Incremental_archive_entry(filename_key
, arg_serial
, mtime
);
980 arch
->set_incremental_info(entry
);
982 if (script_info
!= NULL
)
984 Incremental_script_entry
* script_entry
= script_info
->incremental_info();
985 gold_assert(script_entry
!= NULL
);
986 script_entry
->add_object(entry
);
990 // Visitor class for processing the unused global symbols in a library.
991 // An instance of this class is passed to the library's
992 // for_all_unused_symbols() iterator, which will call the visit()
993 // function for each global symbol defined in each unused library
994 // member. We add those symbol names to the incremental info for the
997 class Unused_symbol_visitor
: public Library_base::Symbol_visitor_base
1000 Unused_symbol_visitor(Incremental_archive_entry
* entry
, Stringpool
* strtab
)
1001 : entry_(entry
), strtab_(strtab
)
1005 visit(const char* sym
)
1007 Stringpool::Key symbol_key
;
1008 this->strtab_
->add(sym
, true, &symbol_key
);
1009 this->entry_
->add_unused_global_symbol(symbol_key
);
1013 Incremental_archive_entry
* entry_
;
1014 Stringpool
* strtab_
;
1017 // Finish recording the input archive file ARCHIVE. This is called by the
1018 // Add_archive_symbols task after determining which archive members
1022 Incremental_inputs::report_archive_end(Library_base
* arch
)
1024 Incremental_archive_entry
* entry
= arch
->incremental_info();
1026 gold_assert(entry
!= NULL
);
1027 this->inputs_
.push_back(entry
);
1029 // Collect unused global symbols.
1030 Unused_symbol_visitor
v(entry
, this->strtab_
);
1031 arch
->for_all_unused_symbols(&v
);
1034 // Record the input object file OBJ. If ARCH is not NULL, attach
1035 // the object file to the archive. This is called by the
1036 // Add_symbols task after finding out the type of the file.
1039 Incremental_inputs::report_object(Object
* obj
, unsigned int arg_serial
,
1040 Library_base
* arch
, Script_info
* script_info
)
1042 Stringpool::Key filename_key
;
1043 Timespec mtime
= obj
->get_mtime();
1045 // For a file loaded from a script, don't record its argument serial number.
1046 if (script_info
!= NULL
)
1049 this->strtab_
->add(obj
->name().c_str(), false, &filename_key
);
1051 Incremental_input_entry
* input_entry
;
1053 this->current_object_
= obj
;
1055 if (!obj
->is_dynamic())
1057 this->current_object_entry_
=
1058 new Incremental_object_entry(filename_key
, obj
, arg_serial
, mtime
);
1059 input_entry
= this->current_object_entry_
;
1062 Incremental_archive_entry
* arch_entry
= arch
->incremental_info();
1063 gold_assert(arch_entry
!= NULL
);
1064 arch_entry
->add_object(this->current_object_entry_
);
1069 this->current_object_entry_
= NULL
;
1070 Stringpool::Key soname_key
;
1071 Dynobj
* dynobj
= obj
->dynobj();
1072 gold_assert(dynobj
!= NULL
);
1073 this->strtab_
->add(dynobj
->soname(), false, &soname_key
);
1074 input_entry
= new Incremental_dynobj_entry(filename_key
, soname_key
, obj
,
1078 if (obj
->is_in_system_directory())
1079 input_entry
->set_is_in_system_directory();
1081 if (obj
->as_needed())
1082 input_entry
->set_as_needed();
1084 this->inputs_
.push_back(input_entry
);
1086 if (script_info
!= NULL
)
1088 Incremental_script_entry
* script_entry
= script_info
->incremental_info();
1089 gold_assert(script_entry
!= NULL
);
1090 script_entry
->add_object(input_entry
);
1094 // Record an input section SHNDX from object file OBJ.
1097 Incremental_inputs::report_input_section(Object
* obj
, unsigned int shndx
,
1098 const char* name
, off_t sh_size
)
1100 Stringpool::Key key
= 0;
1103 this->strtab_
->add(name
, true, &key
);
1105 gold_assert(obj
== this->current_object_
);
1106 gold_assert(this->current_object_entry_
!= NULL
);
1107 this->current_object_entry_
->add_input_section(shndx
, key
, sh_size
);
1110 // Record a kept COMDAT group belonging to object file OBJ.
1113 Incremental_inputs::report_comdat_group(Object
* obj
, const char* name
)
1115 Stringpool::Key key
= 0;
1118 this->strtab_
->add(name
, true, &key
);
1119 gold_assert(obj
== this->current_object_
);
1120 gold_assert(this->current_object_entry_
!= NULL
);
1121 this->current_object_entry_
->add_comdat_group(key
);
1124 // Record that the input argument INPUT is a script SCRIPT. This is
1125 // called by read_script after parsing the script and reading the list
1126 // of inputs added by this script.
1129 Incremental_inputs::report_script(Script_info
* script
,
1130 unsigned int arg_serial
,
1133 Stringpool::Key filename_key
;
1135 this->strtab_
->add(script
->filename().c_str(), false, &filename_key
);
1136 Incremental_script_entry
* entry
=
1137 new Incremental_script_entry(filename_key
, arg_serial
, script
, mtime
);
1138 this->inputs_
.push_back(entry
);
1139 script
->set_incremental_info(entry
);
1142 // Finalize the incremental link information. Called from
1143 // Layout::finalize.
1146 Incremental_inputs::finalize()
1148 // Finalize the string table.
1149 this->strtab_
->set_string_offsets();
1152 // Create the .gnu_incremental_inputs, _symtab, and _relocs input sections.
1155 Incremental_inputs::create_data_sections(Symbol_table
* symtab
)
1157 switch (parameters
->size_and_endianness())
1159 #ifdef HAVE_TARGET_32_LITTLE
1160 case Parameters::TARGET_32_LITTLE
:
1161 this->inputs_section_
=
1162 new Output_section_incremental_inputs
<32, false>(this, symtab
);
1165 #ifdef HAVE_TARGET_32_BIG
1166 case Parameters::TARGET_32_BIG
:
1167 this->inputs_section_
=
1168 new Output_section_incremental_inputs
<32, true>(this, symtab
);
1171 #ifdef HAVE_TARGET_64_LITTLE
1172 case Parameters::TARGET_64_LITTLE
:
1173 this->inputs_section_
=
1174 new Output_section_incremental_inputs
<64, false>(this, symtab
);
1177 #ifdef HAVE_TARGET_64_BIG
1178 case Parameters::TARGET_64_BIG
:
1179 this->inputs_section_
=
1180 new Output_section_incremental_inputs
<64, true>(this, symtab
);
1186 this->symtab_section_
= new Output_data_space(4, "** incremental_symtab");
1187 this->relocs_section_
= new Output_data_space(4, "** incremental_relocs");
1188 this->got_plt_section_
= new Output_data_space(4, "** incremental_got_plt");
1191 // Return the sh_entsize value for the .gnu_incremental_relocs section.
1193 Incremental_inputs::relocs_entsize() const
1195 return 8 + 2 * parameters
->target().get_size() / 8;
1198 // Class Output_section_incremental_inputs.
1200 // Finalize the offsets for each input section and supplemental info block,
1201 // and set the final data size of the incremental output sections.
1203 template<int size
, bool big_endian
>
1205 Output_section_incremental_inputs
<size
, big_endian
>::set_final_data_size()
1207 const Incremental_inputs
* inputs
= this->inputs_
;
1208 const unsigned int sizeof_addr
= size
/ 8;
1209 const unsigned int rel_size
= 8 + 2 * sizeof_addr
;
1211 // Offset of each input entry.
1212 unsigned int input_offset
= this->header_size
;
1214 // Offset of each supplemental info block.
1215 unsigned int file_index
= 0;
1216 unsigned int info_offset
= this->header_size
;
1217 info_offset
+= this->input_entry_size
* inputs
->input_file_count();
1219 // Count each input file and its supplemental information block.
1220 for (Incremental_inputs::Input_list::const_iterator p
=
1221 inputs
->input_files().begin();
1222 p
!= inputs
->input_files().end();
1225 // Set the index and offset of the input file entry.
1226 (*p
)->set_offset(file_index
, input_offset
);
1228 input_offset
+= this->input_entry_size
;
1230 // Set the offset of the supplemental info block.
1231 switch ((*p
)->type())
1233 case INCREMENTAL_INPUT_SCRIPT
:
1235 Incremental_script_entry
*entry
= (*p
)->script_entry();
1236 gold_assert(entry
!= NULL
);
1237 (*p
)->set_info_offset(info_offset
);
1241 info_offset
+= (entry
->get_object_count() * 4);
1244 case INCREMENTAL_INPUT_OBJECT
:
1245 case INCREMENTAL_INPUT_ARCHIVE_MEMBER
:
1247 Incremental_object_entry
* entry
= (*p
)->object_entry();
1248 gold_assert(entry
!= NULL
);
1249 (*p
)->set_info_offset(info_offset
);
1250 // Input section count, global symbol count, local symbol offset,
1251 // local symbol count, first dynamic reloc, dynamic reloc count,
1252 // comdat group count.
1254 // Each input section.
1255 info_offset
+= (entry
->get_input_section_count()
1256 * (8 + 2 * sizeof_addr
));
1257 // Each global symbol.
1258 const Object::Symbols
* syms
= entry
->object()->get_global_symbols();
1259 info_offset
+= syms
->size() * 20;
1260 // Each comdat group.
1261 info_offset
+= entry
->get_comdat_group_count() * 4;
1264 case INCREMENTAL_INPUT_SHARED_LIBRARY
:
1266 Incremental_dynobj_entry
* entry
= (*p
)->dynobj_entry();
1267 gold_assert(entry
!= NULL
);
1268 (*p
)->set_info_offset(info_offset
);
1269 // Global symbol count, soname index.
1271 // Each global symbol.
1272 const Object::Symbols
* syms
= entry
->object()->get_global_symbols();
1273 gold_assert(syms
!= NULL
);
1274 unsigned int nsyms
= syms
->size();
1275 unsigned int nsyms_out
= 0;
1276 for (unsigned int i
= 0; i
< nsyms
; ++i
)
1278 const Symbol
* sym
= (*syms
)[i
];
1281 if (sym
->is_forwarder())
1282 sym
= this->symtab_
->resolve_forwards(sym
);
1283 if (sym
->symtab_index() != -1U)
1286 info_offset
+= nsyms_out
* 4;
1289 case INCREMENTAL_INPUT_ARCHIVE
:
1291 Incremental_archive_entry
* entry
= (*p
)->archive_entry();
1292 gold_assert(entry
!= NULL
);
1293 (*p
)->set_info_offset(info_offset
);
1294 // Member count + unused global symbol count.
1297 info_offset
+= (entry
->get_member_count() * 4);
1298 // Each global symbol.
1299 info_offset
+= (entry
->get_unused_global_symbol_count() * 4);
1307 this->set_data_size(info_offset
);
1309 // Set the size of the .gnu_incremental_symtab section.
1310 inputs
->symtab_section()->set_current_data_size(this->symtab_
->output_count()
1311 * sizeof(unsigned int));
1313 // Set the size of the .gnu_incremental_relocs section.
1314 inputs
->relocs_section()->set_current_data_size(inputs
->get_reloc_count()
1317 // Set the size of the .gnu_incremental_got_plt section.
1318 Sized_target
<size
, big_endian
>* target
=
1319 parameters
->sized_target
<size
, big_endian
>();
1320 unsigned int got_count
= target
->got_entry_count();
1321 unsigned int plt_count
= target
->plt_entry_count();
1322 unsigned int got_plt_size
= 8; // GOT entry count, PLT entry count.
1323 got_plt_size
= (got_plt_size
+ got_count
+ 3) & ~3; // GOT type array.
1324 got_plt_size
+= got_count
* 8 + plt_count
* 4; // GOT array, PLT array.
1325 inputs
->got_plt_section()->set_current_data_size(got_plt_size
);
1328 // Write the contents of the .gnu_incremental_inputs and
1329 // .gnu_incremental_symtab sections.
1331 template<int size
, bool big_endian
>
1333 Output_section_incremental_inputs
<size
, big_endian
>::do_write(Output_file
* of
)
1335 const Incremental_inputs
* inputs
= this->inputs_
;
1336 Stringpool
* strtab
= inputs
->get_stringpool();
1338 // Get a view into the .gnu_incremental_inputs section.
1339 const off_t off
= this->offset();
1340 const off_t oview_size
= this->data_size();
1341 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
1342 unsigned char* pov
= oview
;
1344 // Get a view into the .gnu_incremental_symtab section.
1345 const off_t symtab_off
= inputs
->symtab_section()->offset();
1346 const off_t symtab_size
= inputs
->symtab_section()->data_size();
1347 unsigned char* const symtab_view
= of
->get_output_view(symtab_off
,
1350 // Allocate an array of linked list heads for the .gnu_incremental_symtab
1351 // section. Each element corresponds to a global symbol in the output
1352 // symbol table, and points to the head of the linked list that threads
1353 // through the object file input entries. The value of each element
1354 // is the section-relative offset to a global symbol entry in a
1355 // supplemental information block.
1356 unsigned int global_sym_count
= this->symtab_
->output_count();
1357 unsigned int* global_syms
= new unsigned int[global_sym_count
];
1358 memset(global_syms
, 0, global_sym_count
* sizeof(unsigned int));
1360 // Write the section header.
1361 Stringpool::Key command_line_key
= inputs
->command_line_key();
1362 pov
= this->write_header(pov
, inputs
->input_file_count(),
1363 strtab
->get_offset_from_key(command_line_key
));
1365 // Write the list of input files.
1366 pov
= this->write_input_files(oview
, pov
, strtab
);
1368 // Write the supplemental information blocks for each input file.
1369 pov
= this->write_info_blocks(oview
, pov
, strtab
, global_syms
,
1372 gold_assert(pov
- oview
== oview_size
);
1374 // Write the .gnu_incremental_symtab section.
1375 gold_assert(global_sym_count
* 4 == symtab_size
);
1376 this->write_symtab(symtab_view
, global_syms
, global_sym_count
);
1378 delete[] global_syms
;
1380 // Write the .gnu_incremental_got_plt section.
1381 const off_t got_plt_off
= inputs
->got_plt_section()->offset();
1382 const off_t got_plt_size
= inputs
->got_plt_section()->data_size();
1383 unsigned char* const got_plt_view
= of
->get_output_view(got_plt_off
,
1385 this->write_got_plt(got_plt_view
, got_plt_size
);
1387 of
->write_output_view(off
, oview_size
, oview
);
1388 of
->write_output_view(symtab_off
, symtab_size
, symtab_view
);
1389 of
->write_output_view(got_plt_off
, got_plt_size
, got_plt_view
);
1392 // Write the section header: version, input file count, offset of command line
1393 // in the string table, and 4 bytes of padding.
1395 template<int size
, bool big_endian
>
1397 Output_section_incremental_inputs
<size
, big_endian
>::write_header(
1399 unsigned int input_file_count
,
1400 section_offset_type command_line_offset
)
1402 Swap32::writeval(pov
, INCREMENTAL_LINK_VERSION
);
1403 Swap32::writeval(pov
+ 4, input_file_count
);
1404 Swap32::writeval(pov
+ 8, command_line_offset
);
1405 Swap32::writeval(pov
+ 12, 0);
1406 return pov
+ this->header_size
;
1409 // Write the input file entries.
1411 template<int size
, bool big_endian
>
1413 Output_section_incremental_inputs
<size
, big_endian
>::write_input_files(
1414 unsigned char* oview
,
1418 const Incremental_inputs
* inputs
= this->inputs_
;
1420 for (Incremental_inputs::Input_list::const_iterator p
=
1421 inputs
->input_files().begin();
1422 p
!= inputs
->input_files().end();
1425 gold_assert(static_cast<unsigned int>(pov
- oview
) == (*p
)->get_offset());
1426 section_offset_type filename_offset
=
1427 strtab
->get_offset_from_key((*p
)->get_filename_key());
1428 const Timespec
& mtime
= (*p
)->get_mtime();
1429 unsigned int flags
= (*p
)->type();
1430 if ((*p
)->is_in_system_directory())
1431 flags
|= INCREMENTAL_INPUT_IN_SYSTEM_DIR
;
1432 if ((*p
)->as_needed())
1433 flags
|= INCREMENTAL_INPUT_AS_NEEDED
;
1434 Swap32::writeval(pov
, filename_offset
);
1435 Swap32::writeval(pov
+ 4, (*p
)->get_info_offset());
1436 Swap64::writeval(pov
+ 8, mtime
.seconds
);
1437 Swap32::writeval(pov
+ 16, mtime
.nanoseconds
);
1438 Swap16::writeval(pov
+ 20, flags
);
1439 Swap16::writeval(pov
+ 22, (*p
)->arg_serial());
1440 pov
+= this->input_entry_size
;
1445 // Write the supplemental information blocks.
1447 template<int size
, bool big_endian
>
1449 Output_section_incremental_inputs
<size
, big_endian
>::write_info_blocks(
1450 unsigned char* oview
,
1453 unsigned int* global_syms
,
1454 unsigned int global_sym_count
)
1456 const Incremental_inputs
* inputs
= this->inputs_
;
1457 unsigned int first_global_index
= this->symtab_
->first_global_index();
1459 for (Incremental_inputs::Input_list::const_iterator p
=
1460 inputs
->input_files().begin();
1461 p
!= inputs
->input_files().end();
1464 switch ((*p
)->type())
1466 case INCREMENTAL_INPUT_SCRIPT
:
1468 gold_assert(static_cast<unsigned int>(pov
- oview
)
1469 == (*p
)->get_info_offset());
1470 Incremental_script_entry
* entry
= (*p
)->script_entry();
1471 gold_assert(entry
!= NULL
);
1473 // Write the object count.
1474 unsigned int nobjects
= entry
->get_object_count();
1475 Swap32::writeval(pov
, nobjects
);
1478 // For each object, write the offset to its input file entry.
1479 for (unsigned int i
= 0; i
< nobjects
; ++i
)
1481 Incremental_input_entry
* obj
= entry
->get_object(i
);
1482 Swap32::writeval(pov
, obj
->get_offset());
1488 case INCREMENTAL_INPUT_OBJECT
:
1489 case INCREMENTAL_INPUT_ARCHIVE_MEMBER
:
1491 gold_assert(static_cast<unsigned int>(pov
- oview
)
1492 == (*p
)->get_info_offset());
1493 Incremental_object_entry
* entry
= (*p
)->object_entry();
1494 gold_assert(entry
!= NULL
);
1495 const Object
* obj
= entry
->object();
1496 const Relobj
* relobj
= static_cast<const Relobj
*>(obj
);
1497 const Object::Symbols
* syms
= obj
->get_global_symbols();
1498 // Write the input section count and global symbol count.
1499 unsigned int nsections
= entry
->get_input_section_count();
1500 unsigned int nsyms
= syms
->size();
1501 off_t locals_offset
= relobj
->local_symbol_offset();
1502 unsigned int nlocals
= relobj
->output_local_symbol_count();
1503 unsigned int first_dynrel
= relobj
->first_dyn_reloc();
1504 unsigned int ndynrel
= relobj
->dyn_reloc_count();
1505 unsigned int ncomdat
= entry
->get_comdat_group_count();
1506 Swap32::writeval(pov
, nsections
);
1507 Swap32::writeval(pov
+ 4, nsyms
);
1508 Swap32::writeval(pov
+ 8, static_cast<unsigned int>(locals_offset
));
1509 Swap32::writeval(pov
+ 12, nlocals
);
1510 Swap32::writeval(pov
+ 16, first_dynrel
);
1511 Swap32::writeval(pov
+ 20, ndynrel
);
1512 Swap32::writeval(pov
+ 24, ncomdat
);
1515 // Build a temporary array to map input section indexes
1516 // from the original object file index to the index in the
1517 // incremental info table.
1518 unsigned int* index_map
= new unsigned int[obj
->shnum()];
1519 memset(index_map
, 0, obj
->shnum() * sizeof(unsigned int));
1521 // For each input section, write the name, output section index,
1522 // offset within output section, and input section size.
1523 for (unsigned int i
= 0; i
< nsections
; i
++)
1525 unsigned int shndx
= entry
->get_input_section_index(i
);
1526 index_map
[shndx
] = i
+ 1;
1527 Stringpool::Key key
= entry
->get_input_section_name_key(i
);
1528 off_t name_offset
= 0;
1530 name_offset
= strtab
->get_offset_from_key(key
);
1532 off_t out_offset
= 0;
1534 Output_section
* os
= obj
->output_section(shndx
);
1537 out_shndx
= os
->out_shndx();
1538 out_offset
= obj
->output_section_offset(shndx
);
1539 sh_size
= entry
->get_input_section_size(i
);
1541 Swap32::writeval(pov
, name_offset
);
1542 Swap32::writeval(pov
+ 4, out_shndx
);
1543 Swap::writeval(pov
+ 8, out_offset
);
1544 Swap::writeval(pov
+ 8 + sizeof_addr
, sh_size
);
1545 pov
+= 8 + 2 * sizeof_addr
;
1548 // For each global symbol, write its associated relocations,
1549 // add it to the linked list of globals, then write the
1550 // supplemental information: global symbol table index,
1551 // input section index, linked list chain pointer, relocation
1552 // count, and offset to the relocations.
1553 for (unsigned int i
= 0; i
< nsyms
; i
++)
1555 const Symbol
* sym
= (*syms
)[i
];
1556 if (sym
->is_forwarder())
1557 sym
= this->symtab_
->resolve_forwards(sym
);
1558 unsigned int shndx
= 0;
1559 if (sym
->source() != Symbol::FROM_OBJECT
)
1561 // The symbol was defined by the linker (e.g., common).
1562 // We mark these symbols with a special SHNDX of -1,
1563 // but exclude linker-predefined symbols and symbols
1564 // copied from shared objects.
1565 if (!sym
->is_predefined()
1566 && !sym
->is_copied_from_dynobj())
1569 else if (sym
->object() == obj
&& sym
->is_defined())
1572 unsigned int orig_shndx
= sym
->shndx(&is_ordinary
);
1574 shndx
= index_map
[orig_shndx
];
1578 unsigned int symtab_index
= sym
->symtab_index();
1579 unsigned int chain
= 0;
1580 unsigned int first_reloc
= 0;
1581 unsigned int nrelocs
= obj
->get_incremental_reloc_count(i
);
1584 gold_assert(symtab_index
!= -1U
1585 && (symtab_index
- first_global_index
1586 < global_sym_count
));
1587 first_reloc
= obj
->get_incremental_reloc_base(i
);
1588 chain
= global_syms
[symtab_index
- first_global_index
];
1589 global_syms
[symtab_index
- first_global_index
] =
1592 Swap32::writeval(pov
, symtab_index
);
1593 Swap32::writeval(pov
+ 4, shndx
);
1594 Swap32::writeval(pov
+ 8, chain
);
1595 Swap32::writeval(pov
+ 12, nrelocs
);
1596 Swap32::writeval(pov
+ 16, first_reloc
* 3 * sizeof_addr
);
1600 // For each kept COMDAT group, write the group signature.
1601 for (unsigned int i
= 0; i
< ncomdat
; i
++)
1603 Stringpool::Key key
= entry
->get_comdat_signature_key(i
);
1604 off_t name_offset
= 0;
1606 name_offset
= strtab
->get_offset_from_key(key
);
1607 Swap32::writeval(pov
, name_offset
);
1615 case INCREMENTAL_INPUT_SHARED_LIBRARY
:
1617 gold_assert(static_cast<unsigned int>(pov
- oview
)
1618 == (*p
)->get_info_offset());
1619 Incremental_dynobj_entry
* entry
= (*p
)->dynobj_entry();
1620 gold_assert(entry
!= NULL
);
1621 Object
* obj
= entry
->object();
1622 Dynobj
* dynobj
= obj
->dynobj();
1623 gold_assert(dynobj
!= NULL
);
1624 const Object::Symbols
* syms
= obj
->get_global_symbols();
1626 // Write the soname string table index.
1627 section_offset_type soname_offset
=
1628 strtab
->get_offset_from_key(entry
->get_soname_key());
1629 Swap32::writeval(pov
, soname_offset
);
1632 // Skip the global symbol count for now.
1633 unsigned char* orig_pov
= pov
;
1636 // For each global symbol, write the global symbol table index.
1637 unsigned int nsyms
= syms
->size();
1638 unsigned int nsyms_out
= 0;
1639 for (unsigned int i
= 0; i
< nsyms
; i
++)
1641 const Symbol
* sym
= (*syms
)[i
];
1644 if (sym
->is_forwarder())
1645 sym
= this->symtab_
->resolve_forwards(sym
);
1646 if (sym
->symtab_index() == -1U)
1648 unsigned int flags
= 0;
1649 if (sym
->source() == Symbol::FROM_OBJECT
1650 && sym
->object() == obj
1651 && sym
->is_defined())
1652 flags
= INCREMENTAL_SHLIB_SYM_DEF
;
1653 else if (sym
->is_copied_from_dynobj()
1654 && this->symtab_
->get_copy_source(sym
) == dynobj
)
1655 flags
= INCREMENTAL_SHLIB_SYM_COPY
;
1656 flags
<<= INCREMENTAL_SHLIB_SYM_FLAGS_SHIFT
;
1657 Swap32::writeval(pov
, sym
->symtab_index() | flags
);
1662 // Now write the global symbol count.
1663 Swap32::writeval(orig_pov
, nsyms_out
);
1667 case INCREMENTAL_INPUT_ARCHIVE
:
1669 gold_assert(static_cast<unsigned int>(pov
- oview
)
1670 == (*p
)->get_info_offset());
1671 Incremental_archive_entry
* entry
= (*p
)->archive_entry();
1672 gold_assert(entry
!= NULL
);
1674 // Write the member count and unused global symbol count.
1675 unsigned int nmembers
= entry
->get_member_count();
1676 unsigned int nsyms
= entry
->get_unused_global_symbol_count();
1677 Swap32::writeval(pov
, nmembers
);
1678 Swap32::writeval(pov
+ 4, nsyms
);
1681 // For each member, write the offset to its input file entry.
1682 for (unsigned int i
= 0; i
< nmembers
; ++i
)
1684 Incremental_object_entry
* member
= entry
->get_member(i
);
1685 Swap32::writeval(pov
, member
->get_offset());
1689 // For each global symbol, write the name offset.
1690 for (unsigned int i
= 0; i
< nsyms
; ++i
)
1692 Stringpool::Key key
= entry
->get_unused_global_symbol(i
);
1693 Swap32::writeval(pov
, strtab
->get_offset_from_key(key
));
1706 // Write the contents of the .gnu_incremental_symtab section.
1708 template<int size
, bool big_endian
>
1710 Output_section_incremental_inputs
<size
, big_endian
>::write_symtab(
1712 unsigned int* global_syms
,
1713 unsigned int global_sym_count
)
1715 for (unsigned int i
= 0; i
< global_sym_count
; ++i
)
1717 Swap32::writeval(pov
, global_syms
[i
]);
1722 // This struct holds the view information needed to write the
1723 // .gnu_incremental_got_plt section.
1725 struct Got_plt_view_info
1727 // Start of the GOT type array in the output view.
1728 unsigned char* got_type_p
;
1729 // Start of the GOT descriptor array in the output view.
1730 unsigned char* got_desc_p
;
1731 // Start of the PLT descriptor array in the output view.
1732 unsigned char* plt_desc_p
;
1733 // Number of GOT entries.
1734 unsigned int got_count
;
1735 // Number of PLT entries.
1736 unsigned int plt_count
;
1737 // Offset of the first non-reserved PLT entry (this is a target-dependent value).
1738 unsigned int first_plt_entry_offset
;
1739 // Size of a PLT entry (this is a target-dependent value).
1740 unsigned int plt_entry_size
;
1741 // Symbol index to write in the GOT descriptor array. For global symbols,
1742 // this is the global symbol table index; for local symbols, it is the
1743 // local symbol table index.
1744 unsigned int sym_index
;
1745 // Input file index to write in the GOT descriptor array. For global
1746 // symbols, this is 0; for local symbols, it is the index of the input
1747 // file entry in the .gnu_incremental_inputs section.
1748 unsigned int input_index
;
1751 // Functor class for processing a GOT offset list for local symbols.
1752 // Writes the GOT type and symbol index into the GOT type and descriptor
1753 // arrays in the output section.
1755 template<int size
, bool big_endian
>
1756 class Local_got_offset_visitor
: public Got_offset_list::Visitor
1759 Local_got_offset_visitor(struct Got_plt_view_info
& info
)
1764 visit(unsigned int got_type
, unsigned int got_offset
)
1766 unsigned int got_index
= got_offset
/ this->got_entry_size_
;
1767 gold_assert(got_index
< this->info_
.got_count
);
1768 // We can only handle GOT entry types in the range 0..0x7e
1769 // because we use a byte array to store them, and we use the
1770 // high bit to flag a local symbol.
1771 gold_assert(got_type
< 0x7f);
1772 this->info_
.got_type_p
[got_index
] = got_type
| 0x80;
1773 unsigned char* pov
= this->info_
.got_desc_p
+ got_index
* 8;
1774 elfcpp::Swap
<32, big_endian
>::writeval(pov
, this->info_
.sym_index
);
1775 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, this->info_
.input_index
);
1779 static const unsigned int got_entry_size_
= size
/ 8;
1780 struct Got_plt_view_info
& info_
;
1783 // Functor class for processing a GOT offset list. Writes the GOT type
1784 // and symbol index into the GOT type and descriptor arrays in the output
1787 template<int size
, bool big_endian
>
1788 class Global_got_offset_visitor
: public Got_offset_list::Visitor
1791 Global_got_offset_visitor(struct Got_plt_view_info
& info
)
1796 visit(unsigned int got_type
, unsigned int got_offset
)
1798 unsigned int got_index
= got_offset
/ this->got_entry_size_
;
1799 gold_assert(got_index
< this->info_
.got_count
);
1800 // We can only handle GOT entry types in the range 0..0x7e
1801 // because we use a byte array to store them, and we use the
1802 // high bit to flag a local symbol.
1803 gold_assert(got_type
< 0x7f);
1804 this->info_
.got_type_p
[got_index
] = got_type
;
1805 unsigned char* pov
= this->info_
.got_desc_p
+ got_index
* 8;
1806 elfcpp::Swap
<32, big_endian
>::writeval(pov
, this->info_
.sym_index
);
1807 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, 0);
1811 static const unsigned int got_entry_size_
= size
/ 8;
1812 struct Got_plt_view_info
& info_
;
1815 // Functor class for processing the global symbol table. Processes the
1816 // GOT offset list for the symbol, and writes the symbol table index
1817 // into the PLT descriptor array in the output section.
1819 template<int size
, bool big_endian
>
1820 class Global_symbol_visitor_got_plt
1823 Global_symbol_visitor_got_plt(struct Got_plt_view_info
& info
)
1828 operator()(const Sized_symbol
<size
>* sym
)
1830 typedef Global_got_offset_visitor
<size
, big_endian
> Got_visitor
;
1831 const Got_offset_list
* got_offsets
= sym
->got_offset_list();
1832 if (got_offsets
!= NULL
)
1834 this->info_
.sym_index
= sym
->symtab_index();
1835 this->info_
.input_index
= 0;
1836 Got_visitor
v(this->info_
);
1837 got_offsets
->for_all_got_offsets(&v
);
1839 if (sym
->has_plt_offset())
1841 unsigned int plt_index
=
1842 ((sym
->plt_offset() - this->info_
.first_plt_entry_offset
)
1843 / this->info_
.plt_entry_size
);
1844 gold_assert(plt_index
< this->info_
.plt_count
);
1845 unsigned char* pov
= this->info_
.plt_desc_p
+ plt_index
* 4;
1846 elfcpp::Swap
<32, big_endian
>::writeval(pov
, sym
->symtab_index());
1851 struct Got_plt_view_info
& info_
;
1854 // Write the contents of the .gnu_incremental_got_plt section.
1856 template<int size
, bool big_endian
>
1858 Output_section_incremental_inputs
<size
, big_endian
>::write_got_plt(
1862 Sized_target
<size
, big_endian
>* target
=
1863 parameters
->sized_target
<size
, big_endian
>();
1865 // Set up the view information for the functors.
1866 struct Got_plt_view_info view_info
;
1867 view_info
.got_count
= target
->got_entry_count();
1868 view_info
.plt_count
= target
->plt_entry_count();
1869 view_info
.first_plt_entry_offset
= target
->first_plt_entry_offset();
1870 view_info
.plt_entry_size
= target
->plt_entry_size();
1871 view_info
.got_type_p
= pov
+ 8;
1872 view_info
.got_desc_p
= (view_info
.got_type_p
1873 + ((view_info
.got_count
+ 3) & ~3));
1874 view_info
.plt_desc_p
= view_info
.got_desc_p
+ view_info
.got_count
* 8;
1876 gold_assert(pov
+ view_size
==
1877 view_info
.plt_desc_p
+ view_info
.plt_count
* 4);
1879 // Write the section header.
1880 Swap32::writeval(pov
, view_info
.got_count
);
1881 Swap32::writeval(pov
+ 4, view_info
.plt_count
);
1883 // Initialize the GOT type array to 0xff (reserved).
1884 memset(view_info
.got_type_p
, 0xff, view_info
.got_count
);
1886 // Write the incremental GOT descriptors for local symbols.
1887 typedef Local_got_offset_visitor
<size
, big_endian
> Got_visitor
;
1888 for (Incremental_inputs::Input_list::const_iterator p
=
1889 this->inputs_
->input_files().begin();
1890 p
!= this->inputs_
->input_files().end();
1893 if ((*p
)->type() != INCREMENTAL_INPUT_OBJECT
1894 && (*p
)->type() != INCREMENTAL_INPUT_ARCHIVE_MEMBER
)
1896 Incremental_object_entry
* entry
= (*p
)->object_entry();
1897 gold_assert(entry
!= NULL
);
1898 const Object
* obj
= entry
->object();
1899 gold_assert(obj
!= NULL
);
1900 view_info
.input_index
= (*p
)->get_file_index();
1901 Got_visitor
v(view_info
);
1902 obj
->for_all_local_got_entries(&v
);
1905 // Write the incremental GOT and PLT descriptors for global symbols.
1906 typedef Global_symbol_visitor_got_plt
<size
, big_endian
> Symbol_visitor
;
1907 symtab_
->for_all_symbols
<size
, Symbol_visitor
>(Symbol_visitor(view_info
));
1910 // Class Sized_relobj_incr. Most of these methods are not used for
1911 // Incremental objects, but are required to be implemented by the
1912 // base class Object.
1914 template<int size
, bool big_endian
>
1915 Sized_relobj_incr
<size
, big_endian
>::Sized_relobj_incr(
1916 const std::string
& name
,
1917 Sized_incremental_binary
<size
, big_endian
>* ibase
,
1918 unsigned int input_file_index
)
1919 : Sized_relobj
<size
, big_endian
>(name
, NULL
), ibase_(ibase
),
1920 input_file_index_(input_file_index
),
1921 input_reader_(ibase
->inputs_reader().input_file(input_file_index
)),
1922 local_symbol_count_(0), output_local_dynsym_count_(0),
1923 local_symbol_index_(0), local_symbol_offset_(0), local_dynsym_offset_(0),
1924 symbols_(), incr_reloc_offset_(-1U), incr_reloc_count_(0),
1925 incr_reloc_output_index_(0), incr_relocs_(NULL
), local_symbols_()
1927 if (this->input_reader_
.is_in_system_directory())
1928 this->set_is_in_system_directory();
1929 const unsigned int shnum
= this->input_reader_
.get_input_section_count() + 1;
1930 this->set_shnum(shnum
);
1931 ibase
->set_input_object(input_file_index
, this);
1934 // Read the symbols.
1936 template<int size
, bool big_endian
>
1938 Sized_relobj_incr
<size
, big_endian
>::do_read_symbols(Read_symbols_data
*)
1943 // Lay out the input sections.
1945 template<int size
, bool big_endian
>
1947 Sized_relobj_incr
<size
, big_endian
>::do_layout(
1952 const unsigned int shnum
= this->shnum();
1953 Incremental_inputs
* incremental_inputs
= layout
->incremental_inputs();
1954 gold_assert(incremental_inputs
!= NULL
);
1955 Output_sections
& out_sections(this->output_sections());
1956 out_sections
.resize(shnum
);
1957 this->section_offsets().resize(shnum
);
1958 for (unsigned int i
= 1; i
< shnum
; i
++)
1960 typename
Input_entry_reader::Input_section_info sect
=
1961 this->input_reader_
.get_input_section(i
- 1);
1962 // Add the section to the incremental inputs layout.
1963 incremental_inputs
->report_input_section(this, i
, sect
.name
,
1965 if (sect
.output_shndx
== 0 || sect
.sh_offset
== -1)
1967 Output_section
* os
= this->ibase_
->output_section(sect
.output_shndx
);
1968 gold_assert(os
!= NULL
);
1969 out_sections
[i
] = os
;
1970 this->section_offsets()[i
] = static_cast<Address
>(sect
.sh_offset
);
1973 // Process the COMDAT groups.
1974 unsigned int ncomdat
= this->input_reader_
.get_comdat_group_count();
1975 for (unsigned int i
= 0; i
< ncomdat
; i
++)
1977 const char* signature
= this->input_reader_
.get_comdat_group_signature(i
);
1978 if (signature
== NULL
|| signature
[0] == '\0')
1979 this->error(_("COMDAT group has no signature"));
1980 bool keep
= layout
->find_or_add_kept_section(signature
, this, i
, true,
1983 this->error(_("COMDAT group %s included twice in incremental link"),
1988 // Layout sections whose layout was deferred while waiting for
1989 // input files from a plugin.
1990 template<int size
, bool big_endian
>
1992 Sized_relobj_incr
<size
, big_endian
>::do_layout_deferred_sections(Layout
*)
1996 // Add the symbols to the symbol table.
1998 template<int size
, bool big_endian
>
2000 Sized_relobj_incr
<size
, big_endian
>::do_add_symbols(
2001 Symbol_table
* symtab
,
2005 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2006 unsigned char symbuf
[sym_size
];
2007 elfcpp::Sym
<size
, big_endian
> sym(symbuf
);
2008 elfcpp::Sym_write
<size
, big_endian
> osym(symbuf
);
2010 typedef typename
elfcpp::Elf_types
<size
>::Elf_WXword Elf_size_type
;
2012 unsigned int nsyms
= this->input_reader_
.get_global_symbol_count();
2013 this->symbols_
.resize(nsyms
);
2015 Incremental_binary::View
symtab_view(NULL
);
2016 unsigned int symtab_count
;
2017 elfcpp::Elf_strtab
strtab(NULL
, 0);
2018 this->ibase_
->get_symtab_view(&symtab_view
, &symtab_count
, &strtab
);
2020 Incremental_symtab_reader
<big_endian
> isymtab(this->ibase_
->symtab_reader());
2021 unsigned int isym_count
= isymtab
.symbol_count();
2022 unsigned int first_global
= symtab_count
- isym_count
;
2024 const unsigned char* sym_p
;
2025 for (unsigned int i
= 0; i
< nsyms
; ++i
)
2027 Incremental_global_symbol_reader
<big_endian
> info
=
2028 this->input_reader_
.get_global_symbol_reader(i
);
2029 unsigned int output_symndx
= info
.output_symndx();
2030 sym_p
= symtab_view
.data() + output_symndx
* sym_size
;
2031 elfcpp::Sym
<size
, big_endian
> gsym(sym_p
);
2033 if (!strtab
.get_c_string(gsym
.get_st_name(), &name
))
2036 typename
elfcpp::Elf_types
<size
>::Elf_Addr v
= gsym
.get_st_value();
2037 unsigned int shndx
= gsym
.get_st_shndx();
2038 elfcpp::STB st_bind
= gsym
.get_st_bind();
2039 elfcpp::STT st_type
= gsym
.get_st_type();
2041 // Local hidden symbols start out as globals, but get converted to
2042 // to local during output.
2043 if (st_bind
== elfcpp::STB_LOCAL
)
2044 st_bind
= elfcpp::STB_GLOBAL
;
2046 unsigned int input_shndx
= info
.shndx();
2047 if (input_shndx
== 0 || input_shndx
== -1U)
2049 shndx
= elfcpp::SHN_UNDEF
;
2052 else if (shndx
!= elfcpp::SHN_ABS
)
2054 // Find the input section and calculate the section-relative value.
2055 gold_assert(shndx
!= elfcpp::SHN_UNDEF
);
2056 Output_section
* os
= this->ibase_
->output_section(shndx
);
2057 gold_assert(os
!= NULL
&& os
->has_fixed_layout());
2058 typename
Input_entry_reader::Input_section_info sect
=
2059 this->input_reader_
.get_input_section(input_shndx
- 1);
2060 gold_assert(sect
.output_shndx
== shndx
);
2061 if (st_type
!= elfcpp::STT_TLS
)
2063 v
-= sect
.sh_offset
;
2064 shndx
= input_shndx
;
2067 osym
.put_st_name(0);
2068 osym
.put_st_value(v
);
2069 osym
.put_st_size(gsym
.get_st_size());
2070 osym
.put_st_info(st_bind
, st_type
);
2071 osym
.put_st_other(gsym
.get_st_other());
2072 osym
.put_st_shndx(shndx
);
2074 Symbol
* res
= symtab
->add_from_incrobj(this, name
, NULL
, &sym
);
2076 // If this is a linker-defined symbol that hasn't yet been defined,
2078 if (input_shndx
== -1U && !res
->is_defined())
2080 shndx
= gsym
.get_st_shndx();
2081 v
= gsym
.get_st_value();
2082 Elf_size_type symsize
= gsym
.get_st_size();
2083 if (shndx
== elfcpp::SHN_ABS
)
2085 symtab
->define_as_constant(name
, NULL
,
2086 Symbol_table::INCREMENTAL_BASE
,
2087 v
, symsize
, st_type
, st_bind
,
2088 gsym
.get_st_visibility(), 0,
2093 Output_section
* os
= this->ibase_
->output_section(shndx
);
2094 gold_assert(os
!= NULL
&& os
->has_fixed_layout());
2097 os
->reserve(v
, symsize
);
2098 symtab
->define_in_output_data(name
, NULL
,
2099 Symbol_table::INCREMENTAL_BASE
,
2100 os
, v
, symsize
, st_type
, st_bind
,
2101 gsym
.get_st_visibility(), 0,
2106 this->symbols_
[i
] = res
;
2107 this->ibase_
->add_global_symbol(output_symndx
- first_global
, res
);
2111 // Return TRUE if we should include this object from an archive library.
2113 template<int size
, bool big_endian
>
2114 Archive::Should_include
2115 Sized_relobj_incr
<size
, big_endian
>::do_should_include_member(
2124 // Iterate over global symbols, calling a visitor class V for each.
2126 template<int size
, bool big_endian
>
2128 Sized_relobj_incr
<size
, big_endian
>::do_for_all_global_symbols(
2130 Library_base::Symbol_visitor_base
*)
2132 // This routine is not used for incremental objects.
2135 // Get the size of a section.
2137 template<int size
, bool big_endian
>
2139 Sized_relobj_incr
<size
, big_endian
>::do_section_size(unsigned int)
2144 // Get the name of a section.
2146 template<int size
, bool big_endian
>
2148 Sized_relobj_incr
<size
, big_endian
>::do_section_name(unsigned int)
2153 // Return a view of the contents of a section.
2155 template<int size
, bool big_endian
>
2157 Sized_relobj_incr
<size
, big_endian
>::do_section_contents(unsigned int)
2162 // Return section flags.
2164 template<int size
, bool big_endian
>
2166 Sized_relobj_incr
<size
, big_endian
>::do_section_flags(unsigned int)
2171 // Return section entsize.
2173 template<int size
, bool big_endian
>
2175 Sized_relobj_incr
<size
, big_endian
>::do_section_entsize(unsigned int)
2180 // Return section address.
2182 template<int size
, bool big_endian
>
2184 Sized_relobj_incr
<size
, big_endian
>::do_section_address(unsigned int)
2189 // Return section type.
2191 template<int size
, bool big_endian
>
2193 Sized_relobj_incr
<size
, big_endian
>::do_section_type(unsigned int)
2198 // Return the section link field.
2200 template<int size
, bool big_endian
>
2202 Sized_relobj_incr
<size
, big_endian
>::do_section_link(unsigned int)
2207 // Return the section link field.
2209 template<int size
, bool big_endian
>
2211 Sized_relobj_incr
<size
, big_endian
>::do_section_info(unsigned int)
2216 // Return the section alignment.
2218 template<int size
, bool big_endian
>
2220 Sized_relobj_incr
<size
, big_endian
>::do_section_addralign(unsigned int)
2225 // Return the Xindex structure to use.
2227 template<int size
, bool big_endian
>
2229 Sized_relobj_incr
<size
, big_endian
>::do_initialize_xindex()
2234 // Get symbol counts.
2236 template<int size
, bool big_endian
>
2238 Sized_relobj_incr
<size
, big_endian
>::do_get_global_symbol_counts(
2239 const Symbol_table
*, size_t*, size_t*) const
2246 template<int size
, bool big_endian
>
2248 Sized_relobj_incr
<size
, big_endian
>::do_read_relocs(Read_relocs_data
*)
2252 // Process the relocs to find list of referenced sections. Used only
2253 // during garbage collection.
2255 template<int size
, bool big_endian
>
2257 Sized_relobj_incr
<size
, big_endian
>::do_gc_process_relocs(Symbol_table
*,
2264 // Scan the relocs and adjust the symbol table.
2266 template<int size
, bool big_endian
>
2268 Sized_relobj_incr
<size
, big_endian
>::do_scan_relocs(Symbol_table
*,
2272 // Count the incremental relocations for this object.
2273 unsigned int nsyms
= this->input_reader_
.get_global_symbol_count();
2274 this->allocate_incremental_reloc_counts();
2275 for (unsigned int i
= 0; i
< nsyms
; i
++)
2277 Incremental_global_symbol_reader
<big_endian
> sym
=
2278 this->input_reader_
.get_global_symbol_reader(i
);
2279 unsigned int reloc_count
= sym
.reloc_count();
2280 if (reloc_count
> 0 && this->incr_reloc_offset_
== -1U)
2281 this->incr_reloc_offset_
= sym
.reloc_offset();
2282 this->incr_reloc_count_
+= reloc_count
;
2283 for (unsigned int j
= 0; j
< reloc_count
; j
++)
2284 this->count_incremental_reloc(i
);
2286 this->incr_reloc_output_index_
=
2287 layout
->incremental_inputs()->get_reloc_count();
2288 this->finalize_incremental_relocs(layout
, false);
2290 // The incoming incremental relocations may not end up in the same
2291 // location after the incremental update, because the incremental info
2292 // is regenerated in each link. Because the new location may overlap
2293 // with other data in the updated output file, we need to copy the
2294 // relocations into a buffer so that we can still read them safely
2295 // after we start writing updates to the output file.
2296 if (this->incr_reloc_count_
> 0)
2298 const Incremental_relocs_reader
<size
, big_endian
>& relocs_reader
=
2299 this->ibase_
->relocs_reader();
2300 const unsigned int incr_reloc_size
= relocs_reader
.reloc_size
;
2301 unsigned int len
= this->incr_reloc_count_
* incr_reloc_size
;
2302 this->incr_relocs_
= new unsigned char[len
];
2303 memcpy(this->incr_relocs_
,
2304 relocs_reader
.data(this->incr_reloc_offset_
),
2309 // Count the local symbols.
2311 template<int size
, bool big_endian
>
2313 Sized_relobj_incr
<size
, big_endian
>::do_count_local_symbols(
2314 Stringpool_template
<char>* pool
,
2315 Stringpool_template
<char>*)
2317 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2319 // Set the count of local symbols based on the incremental info.
2320 unsigned int nlocals
= this->input_reader_
.get_local_symbol_count();
2321 this->local_symbol_count_
= nlocals
;
2322 this->local_symbols_
.reserve(nlocals
);
2324 // Get views of the base file's symbol table and string table.
2325 Incremental_binary::View
symtab_view(NULL
);
2326 unsigned int symtab_count
;
2327 elfcpp::Elf_strtab
strtab(NULL
, 0);
2328 this->ibase_
->get_symtab_view(&symtab_view
, &symtab_count
, &strtab
);
2330 // Read the local symbols from the base file's symbol table.
2331 off_t off
= this->input_reader_
.get_local_symbol_offset();
2332 const unsigned char* symp
= symtab_view
.data() + off
;
2333 for (unsigned int i
= 0; i
< nlocals
; ++i
, symp
+= sym_size
)
2335 elfcpp::Sym
<size
, big_endian
> sym(symp
);
2337 if (!strtab
.get_c_string(sym
.get_st_name(), &name
))
2339 gold_debug(DEBUG_INCREMENTAL
, "Local symbol %d: %s", i
, name
);
2340 name
= pool
->add(name
, true, NULL
);
2341 this->local_symbols_
.push_back(Local_symbol(name
,
2350 // Finalize the local symbols.
2352 template<int size
, bool big_endian
>
2354 Sized_relobj_incr
<size
, big_endian
>::do_finalize_local_symbols(
2359 this->local_symbol_index_
= index
;
2360 this->local_symbol_offset_
= off
;
2361 return index
+ this->local_symbol_count_
;
2364 // Set the offset where local dynamic symbol information will be stored.
2366 template<int size
, bool big_endian
>
2368 Sized_relobj_incr
<size
, big_endian
>::do_set_local_dynsym_indexes(
2371 // FIXME: set local dynsym indexes.
2375 // Set the offset where local dynamic symbol information will be stored.
2377 template<int size
, bool big_endian
>
2379 Sized_relobj_incr
<size
, big_endian
>::do_set_local_dynsym_offset(off_t
)
2384 // Relocate the input sections and write out the local symbols.
2385 // We don't actually do any relocation here. For unchanged input files,
2386 // we reapply relocations only for symbols that have changed; that happens
2387 // in queue_final_tasks. We do need to rewrite the incremental relocations
2390 template<int size
, bool big_endian
>
2392 Sized_relobj_incr
<size
, big_endian
>::do_relocate(const Symbol_table
*,
2393 const Layout
* layout
,
2396 if (this->incr_reloc_count_
== 0)
2399 const unsigned int incr_reloc_size
=
2400 Incremental_relocs_reader
<size
, big_endian
>::reloc_size
;
2402 // Get a view for the .gnu_incremental_relocs section.
2403 Incremental_inputs
* inputs
= layout
->incremental_inputs();
2404 gold_assert(inputs
!= NULL
);
2405 const off_t relocs_off
= inputs
->relocs_section()->offset();
2406 const off_t relocs_size
= inputs
->relocs_section()->data_size();
2407 unsigned char* const view
= of
->get_output_view(relocs_off
, relocs_size
);
2409 // Copy the relocations from the buffer.
2410 off_t off
= this->incr_reloc_output_index_
* incr_reloc_size
;
2411 unsigned int len
= this->incr_reloc_count_
* incr_reloc_size
;
2412 memcpy(view
+ off
, this->incr_relocs_
, len
);
2414 // The output section table may have changed, so we need to map
2415 // the old section index to the new section index for each relocation.
2416 for (unsigned int i
= 0; i
< this->incr_reloc_count_
; ++i
)
2418 unsigned char* pov
= view
+ off
+ i
* incr_reloc_size
;
2419 unsigned int shndx
= elfcpp::Swap
<32, big_endian
>::readval(pov
+ 4);
2420 Output_section
* os
= this->ibase_
->output_section(shndx
);
2421 gold_assert(os
!= NULL
);
2422 shndx
= os
->out_shndx();
2423 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, shndx
);
2426 of
->write_output_view(off
, len
, view
);
2428 // Get views into the output file for the portions of the symbol table
2429 // and the dynamic symbol table that we will be writing.
2430 off_t symtab_off
= layout
->symtab_section()->offset();
2431 off_t output_size
= this->local_symbol_count_
* This::sym_size
;
2432 unsigned char* oview
= NULL
;
2433 if (output_size
> 0)
2434 oview
= of
->get_output_view(symtab_off
+ this->local_symbol_offset_
,
2437 off_t dyn_output_size
= this->output_local_dynsym_count_
* sym_size
;
2438 unsigned char* dyn_oview
= NULL
;
2439 if (dyn_output_size
> 0)
2440 dyn_oview
= of
->get_output_view(this->local_dynsym_offset_
,
2443 // Write the local symbols.
2444 unsigned char* ov
= oview
;
2445 unsigned char* dyn_ov
= dyn_oview
;
2446 const Stringpool
* sympool
= layout
->sympool();
2447 const Stringpool
* dynpool
= layout
->dynpool();
2448 Output_symtab_xindex
* symtab_xindex
= layout
->symtab_xindex();
2449 Output_symtab_xindex
* dynsym_xindex
= layout
->dynsym_xindex();
2450 for (unsigned int i
= 0; i
< this->local_symbol_count_
; ++i
)
2452 Local_symbol
& lsym(this->local_symbols_
[i
]);
2455 unsigned int st_shndx
= this->adjust_sym_shndx(i
, lsym
.st_shndx
,
2459 Output_section
* os
= this->ibase_
->output_section(st_shndx
);
2460 st_shndx
= os
->out_shndx();
2461 if (st_shndx
>= elfcpp::SHN_LORESERVE
)
2463 symtab_xindex
->add(this->local_symbol_index_
+ i
, st_shndx
);
2464 if (lsym
.needs_dynsym_entry
)
2465 dynsym_xindex
->add(lsym
.output_dynsym_index
, st_shndx
);
2466 st_shndx
= elfcpp::SHN_XINDEX
;
2470 // Write the symbol to the output symbol table.
2472 elfcpp::Sym_write
<size
, big_endian
> osym(ov
);
2473 osym
.put_st_name(sympool
->get_offset(lsym
.name
));
2474 osym
.put_st_value(lsym
.st_value
);
2475 osym
.put_st_size(lsym
.st_size
);
2476 osym
.put_st_info(elfcpp::STB_LOCAL
,
2477 static_cast<elfcpp::STT
>(lsym
.st_type
));
2478 osym
.put_st_other(0);
2479 osym
.put_st_shndx(st_shndx
);
2483 // Write the symbol to the output dynamic symbol table.
2484 if (lsym
.needs_dynsym_entry
)
2486 gold_assert(dyn_ov
< dyn_oview
+ dyn_output_size
);
2487 elfcpp::Sym_write
<size
, big_endian
> osym(dyn_ov
);
2488 osym
.put_st_name(dynpool
->get_offset(lsym
.name
));
2489 osym
.put_st_value(lsym
.st_value
);
2490 osym
.put_st_size(lsym
.st_size
);
2491 osym
.put_st_info(elfcpp::STB_LOCAL
,
2492 static_cast<elfcpp::STT
>(lsym
.st_type
));
2493 osym
.put_st_other(0);
2494 osym
.put_st_shndx(st_shndx
);
2499 if (output_size
> 0)
2501 gold_assert(ov
- oview
== output_size
);
2502 of
->write_output_view(symtab_off
+ this->local_symbol_offset_
,
2503 output_size
, oview
);
2506 if (dyn_output_size
> 0)
2508 gold_assert(dyn_ov
- dyn_oview
== dyn_output_size
);
2509 of
->write_output_view(this->local_dynsym_offset_
, dyn_output_size
,
2514 // Set the offset of a section.
2516 template<int size
, bool big_endian
>
2518 Sized_relobj_incr
<size
, big_endian
>::do_set_section_offset(unsigned int,
2523 // Class Sized_incr_dynobj. Most of these methods are not used for
2524 // Incremental objects, but are required to be implemented by the
2525 // base class Object.
2527 template<int size
, bool big_endian
>
2528 Sized_incr_dynobj
<size
, big_endian
>::Sized_incr_dynobj(
2529 const std::string
& name
,
2530 Sized_incremental_binary
<size
, big_endian
>* ibase
,
2531 unsigned int input_file_index
)
2532 : Dynobj(name
, NULL
), ibase_(ibase
),
2533 input_file_index_(input_file_index
),
2534 input_reader_(ibase
->inputs_reader().input_file(input_file_index
)),
2537 if (this->input_reader_
.is_in_system_directory())
2538 this->set_is_in_system_directory();
2539 if (this->input_reader_
.as_needed())
2540 this->set_as_needed();
2541 this->set_soname_string(this->input_reader_
.get_soname());
2545 // Read the symbols.
2547 template<int size
, bool big_endian
>
2549 Sized_incr_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
*)
2554 // Lay out the input sections.
2556 template<int size
, bool big_endian
>
2558 Sized_incr_dynobj
<size
, big_endian
>::do_layout(
2565 // Add the symbols to the symbol table.
2567 template<int size
, bool big_endian
>
2569 Sized_incr_dynobj
<size
, big_endian
>::do_add_symbols(
2570 Symbol_table
* symtab
,
2574 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2575 unsigned char symbuf
[sym_size
];
2576 elfcpp::Sym
<size
, big_endian
> sym(symbuf
);
2577 elfcpp::Sym_write
<size
, big_endian
> osym(symbuf
);
2579 typedef typename
elfcpp::Elf_types
<size
>::Elf_WXword Elf_size_type
;
2581 unsigned int nsyms
= this->input_reader_
.get_global_symbol_count();
2582 this->symbols_
.resize(nsyms
);
2584 Incremental_binary::View
symtab_view(NULL
);
2585 unsigned int symtab_count
;
2586 elfcpp::Elf_strtab
strtab(NULL
, 0);
2587 this->ibase_
->get_symtab_view(&symtab_view
, &symtab_count
, &strtab
);
2589 Incremental_symtab_reader
<big_endian
> isymtab(this->ibase_
->symtab_reader());
2590 unsigned int isym_count
= isymtab
.symbol_count();
2591 unsigned int first_global
= symtab_count
- isym_count
;
2593 // We keep a set of symbols that we have generated COPY relocations
2594 // for, indexed by the symbol value. We do not need more than one
2595 // COPY relocation per address.
2596 typedef typename
std::set
<Address
> Copied_symbols
;
2597 Copied_symbols copied_symbols
;
2599 const unsigned char* sym_p
;
2600 for (unsigned int i
= 0; i
< nsyms
; ++i
)
2604 unsigned int output_symndx
=
2605 this->input_reader_
.get_output_symbol_index(i
, &is_def
, &is_copy
);
2606 sym_p
= symtab_view
.data() + output_symndx
* sym_size
;
2607 elfcpp::Sym
<size
, big_endian
> gsym(sym_p
);
2609 if (!strtab
.get_c_string(gsym
.get_st_name(), &name
))
2614 elfcpp::STB st_bind
= gsym
.get_st_bind();
2615 elfcpp::STT st_type
= gsym
.get_st_type();
2617 // Local hidden symbols start out as globals, but get converted to
2618 // to local during output.
2619 if (st_bind
== elfcpp::STB_LOCAL
)
2620 st_bind
= elfcpp::STB_GLOBAL
;
2624 shndx
= elfcpp::SHN_UNDEF
;
2629 // For a symbol defined in a shared object, the section index
2630 // is meaningless, as long as it's not SHN_UNDEF.
2632 v
= gsym
.get_st_value();
2635 osym
.put_st_name(0);
2636 osym
.put_st_value(v
);
2637 osym
.put_st_size(gsym
.get_st_size());
2638 osym
.put_st_info(st_bind
, st_type
);
2639 osym
.put_st_other(gsym
.get_st_other());
2640 osym
.put_st_shndx(shndx
);
2642 Sized_symbol
<size
>* res
=
2643 symtab
->add_from_incrobj
<size
, big_endian
>(this, name
, NULL
, &sym
);
2644 this->symbols_
[i
] = res
;
2645 this->ibase_
->add_global_symbol(output_symndx
- first_global
,
2650 std::pair
<typename
Copied_symbols::iterator
, bool> ins
=
2651 copied_symbols
.insert(v
);
2654 unsigned int shndx
= gsym
.get_st_shndx();
2655 Output_section
* os
= this->ibase_
->output_section(shndx
);
2656 off_t offset
= v
- os
->address();
2657 this->ibase_
->add_copy_reloc(this->symbols_
[i
], os
, offset
);
2663 // Return TRUE if we should include this object from an archive library.
2665 template<int size
, bool big_endian
>
2666 Archive::Should_include
2667 Sized_incr_dynobj
<size
, big_endian
>::do_should_include_member(
2676 // Iterate over global symbols, calling a visitor class V for each.
2678 template<int size
, bool big_endian
>
2680 Sized_incr_dynobj
<size
, big_endian
>::do_for_all_global_symbols(
2682 Library_base::Symbol_visitor_base
*)
2684 // This routine is not used for dynamic libraries.
2687 // Iterate over local symbols, calling a visitor class V for each GOT offset
2688 // associated with a local symbol.
2690 template<int size
, bool big_endian
>
2692 Sized_incr_dynobj
<size
, big_endian
>::do_for_all_local_got_entries(
2693 Got_offset_list::Visitor
*) const
2697 // Get the size of a section.
2699 template<int size
, bool big_endian
>
2701 Sized_incr_dynobj
<size
, big_endian
>::do_section_size(unsigned int)
2706 // Get the name of a section.
2708 template<int size
, bool big_endian
>
2710 Sized_incr_dynobj
<size
, big_endian
>::do_section_name(unsigned int)
2715 // Return a view of the contents of a section.
2717 template<int size
, bool big_endian
>
2719 Sized_incr_dynobj
<size
, big_endian
>::do_section_contents(unsigned int)
2724 // Return section flags.
2726 template<int size
, bool big_endian
>
2728 Sized_incr_dynobj
<size
, big_endian
>::do_section_flags(unsigned int)
2733 // Return section entsize.
2735 template<int size
, bool big_endian
>
2737 Sized_incr_dynobj
<size
, big_endian
>::do_section_entsize(unsigned int)
2742 // Return section address.
2744 template<int size
, bool big_endian
>
2746 Sized_incr_dynobj
<size
, big_endian
>::do_section_address(unsigned int)
2751 // Return section type.
2753 template<int size
, bool big_endian
>
2755 Sized_incr_dynobj
<size
, big_endian
>::do_section_type(unsigned int)
2760 // Return the section link field.
2762 template<int size
, bool big_endian
>
2764 Sized_incr_dynobj
<size
, big_endian
>::do_section_link(unsigned int)
2769 // Return the section link field.
2771 template<int size
, bool big_endian
>
2773 Sized_incr_dynobj
<size
, big_endian
>::do_section_info(unsigned int)
2778 // Return the section alignment.
2780 template<int size
, bool big_endian
>
2782 Sized_incr_dynobj
<size
, big_endian
>::do_section_addralign(unsigned int)
2787 // Return the Xindex structure to use.
2789 template<int size
, bool big_endian
>
2791 Sized_incr_dynobj
<size
, big_endian
>::do_initialize_xindex()
2796 // Get symbol counts.
2798 template<int size
, bool big_endian
>
2800 Sized_incr_dynobj
<size
, big_endian
>::do_get_global_symbol_counts(
2801 const Symbol_table
*, size_t*, size_t*) const
2806 // Allocate an incremental object of the appropriate size and endianness.
2809 make_sized_incremental_object(
2810 Incremental_binary
* ibase
,
2811 unsigned int input_file_index
,
2812 Incremental_input_type input_type
,
2813 const Incremental_binary::Input_reader
* input_reader
)
2816 std::string
name(input_reader
->filename());
2818 switch (parameters
->size_and_endianness())
2820 #ifdef HAVE_TARGET_32_LITTLE
2821 case Parameters::TARGET_32_LITTLE
:
2823 Sized_incremental_binary
<32, false>* sized_ibase
=
2824 static_cast<Sized_incremental_binary
<32, false>*>(ibase
);
2825 if (input_type
== INCREMENTAL_INPUT_SHARED_LIBRARY
)
2826 obj
= new Sized_incr_dynobj
<32, false>(name
, sized_ibase
,
2829 obj
= new Sized_relobj_incr
<32, false>(name
, sized_ibase
,
2834 #ifdef HAVE_TARGET_32_BIG
2835 case Parameters::TARGET_32_BIG
:
2837 Sized_incremental_binary
<32, true>* sized_ibase
=
2838 static_cast<Sized_incremental_binary
<32, true>*>(ibase
);
2839 if (input_type
== INCREMENTAL_INPUT_SHARED_LIBRARY
)
2840 obj
= new Sized_incr_dynobj
<32, true>(name
, sized_ibase
,
2843 obj
= new Sized_relobj_incr
<32, true>(name
, sized_ibase
,
2848 #ifdef HAVE_TARGET_64_LITTLE
2849 case Parameters::TARGET_64_LITTLE
:
2851 Sized_incremental_binary
<64, false>* sized_ibase
=
2852 static_cast<Sized_incremental_binary
<64, false>*>(ibase
);
2853 if (input_type
== INCREMENTAL_INPUT_SHARED_LIBRARY
)
2854 obj
= new Sized_incr_dynobj
<64, false>(name
, sized_ibase
,
2857 obj
= new Sized_relobj_incr
<64, false>(name
, sized_ibase
,
2862 #ifdef HAVE_TARGET_64_BIG
2863 case Parameters::TARGET_64_BIG
:
2865 Sized_incremental_binary
<64, true>* sized_ibase
=
2866 static_cast<Sized_incremental_binary
<64, true>*>(ibase
);
2867 if (input_type
== INCREMENTAL_INPUT_SHARED_LIBRARY
)
2868 obj
= new Sized_incr_dynobj
<64, true>(name
, sized_ibase
,
2871 obj
= new Sized_relobj_incr
<64, true>(name
, sized_ibase
,
2880 gold_assert(obj
!= NULL
);
2884 // Copy the unused symbols from the incremental input info.
2885 // We need to do this because we may be overwriting the incremental
2886 // input info in the base file before we write the new incremental
2889 Incremental_library::copy_unused_symbols()
2891 unsigned int symcount
= this->input_reader_
->get_unused_symbol_count();
2892 this->unused_symbols_
.reserve(symcount
);
2893 for (unsigned int i
= 0; i
< symcount
; ++i
)
2895 std::string
name(this->input_reader_
->get_unused_symbol(i
));
2896 this->unused_symbols_
.push_back(name
);
2900 // Iterator for unused global symbols in the library.
2902 Incremental_library::do_for_all_unused_symbols(Symbol_visitor_base
* v
) const
2904 for (Symbol_list::const_iterator p
= this->unused_symbols_
.begin();
2905 p
!= this->unused_symbols_
.end();
2907 v
->visit(p
->c_str());
2910 // Instantiate the templates we need.
2912 #ifdef HAVE_TARGET_32_LITTLE
2914 class Sized_incremental_binary
<32, false>;
2917 class Sized_relobj_incr
<32, false>;
2920 class Sized_incr_dynobj
<32, false>;
2923 #ifdef HAVE_TARGET_32_BIG
2925 class Sized_incremental_binary
<32, true>;
2928 class Sized_relobj_incr
<32, true>;
2931 class Sized_incr_dynobj
<32, true>;
2934 #ifdef HAVE_TARGET_64_LITTLE
2936 class Sized_incremental_binary
<64, false>;
2939 class Sized_relobj_incr
<64, false>;
2942 class Sized_incr_dynobj
<64, false>;
2945 #ifdef HAVE_TARGET_64_BIG
2947 class Sized_incremental_binary
<64, true>;
2950 class Sized_relobj_incr
<64, true>;
2953 class Sized_incr_dynobj
<64, true>;
2956 } // End namespace gold.