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 gold_debug(DEBUG_INCREMENTAL
,
397 "old command line: %s",
398 inputs
.command_line());
399 gold_debug(DEBUG_INCREMENTAL
,
400 "new command line: %s",
401 incremental_inputs
->command_line().c_str());
402 explain_no_incremental(_("command line changed"));
406 // Walk the list of input files given on the command line, and build
407 // a direct map of argument serial numbers to the corresponding input
409 this->input_args_map_
.resize(cmdline
.number_of_input_files());
410 check_input_args(this->input_args_map_
, cmdline
.begin(), cmdline
.end());
412 // Walk the list of input files to check for conditions that prevent
413 // an incremental update link.
414 unsigned int count
= inputs
.input_file_count();
415 for (unsigned int i
= 0; i
< count
; i
++)
417 Input_entry_reader input_file
= inputs
.input_file(i
);
418 switch (input_file
.type())
420 case INCREMENTAL_INPUT_OBJECT
:
421 case INCREMENTAL_INPUT_ARCHIVE_MEMBER
:
422 case INCREMENTAL_INPUT_SHARED_LIBRARY
:
423 case INCREMENTAL_INPUT_ARCHIVE
:
424 // No special treatment necessary.
426 case INCREMENTAL_INPUT_SCRIPT
:
427 if (this->do_file_has_changed(i
))
429 explain_no_incremental(_("%s: script file changed"),
430 input_file
.filename());
442 // Return TRUE if input file N has changed since the last incremental link.
444 template<int size
, bool big_endian
>
446 Sized_incremental_binary
<size
, big_endian
>::do_file_has_changed(
447 unsigned int n
) const
449 Input_entry_reader input_file
= this->inputs_reader_
.input_file(n
);
450 Incremental_disposition disp
= INCREMENTAL_CHECK
;
451 const Input_argument
* input_argument
= this->get_input_argument(n
);
452 if (input_argument
!= NULL
)
453 disp
= input_argument
->file().options().incremental_disposition();
455 if (disp
!= INCREMENTAL_CHECK
)
456 return disp
== INCREMENTAL_CHANGED
;
458 const char* filename
= input_file
.filename();
459 Timespec old_mtime
= input_file
.get_mtime();
461 if (!get_mtime(filename
, &new_mtime
))
463 // If we can't open get the current modification time, assume it has
464 // changed. If the file doesn't exist, we'll issue an error when we
465 // try to open it later.
469 if (new_mtime
.seconds
> old_mtime
.seconds
)
471 if (new_mtime
.seconds
== old_mtime
.seconds
472 && new_mtime
.nanoseconds
> old_mtime
.nanoseconds
)
477 // Initialize the layout of the output file based on the existing
480 template<int size
, bool big_endian
>
482 Sized_incremental_binary
<size
, big_endian
>::do_init_layout(Layout
* layout
)
484 typedef elfcpp::Shdr
<size
, big_endian
> Shdr
;
485 const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
487 // Get views of the section headers and the section string table.
488 const off_t shoff
= this->elf_file_
.shoff();
489 const unsigned int shnum
= this->elf_file_
.shnum();
490 const unsigned int shstrndx
= this->elf_file_
.shstrndx();
491 Location
shdrs_location(shoff
, shnum
* shdr_size
);
492 Location
shstrndx_location(this->elf_file_
.section_contents(shstrndx
));
493 View shdrs_view
= this->view(shdrs_location
);
494 View shstrndx_view
= this->view(shstrndx_location
);
495 elfcpp::Elf_strtab
shstrtab(shstrndx_view
.data(),
496 shstrndx_location
.data_size
);
498 layout
->set_incremental_base(this);
500 // Initialize the layout.
501 this->section_map_
.resize(shnum
);
502 const unsigned char* pshdr
= shdrs_view
.data() + shdr_size
;
503 for (unsigned int i
= 1; i
< shnum
; i
++)
507 if (!shstrtab
.get_c_string(shdr
.get_sh_name(), &name
))
509 gold_debug(DEBUG_INCREMENTAL
,
510 "Output section: %2d %08lx %08lx %08lx %3d %s",
512 static_cast<long>(shdr
.get_sh_addr()),
513 static_cast<long>(shdr
.get_sh_offset()),
514 static_cast<long>(shdr
.get_sh_size()),
515 shdr
.get_sh_type(), name
? name
: "<null>");
516 this->section_map_
[i
] = layout
->init_fixed_output_section(name
, shdr
);
521 // Mark regions of the input file that must be kept unchanged.
523 template<int size
, bool big_endian
>
525 Sized_incremental_binary
<size
, big_endian
>::do_reserve_layout(
526 unsigned int input_file_index
)
528 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
530 Input_entry_reader input_file
=
531 this->inputs_reader_
.input_file(input_file_index
);
533 if (input_file
.type() == INCREMENTAL_INPUT_SHARED_LIBRARY
)
535 // Reserve the BSS space used for COPY relocations.
536 unsigned int nsyms
= input_file
.get_global_symbol_count();
537 Incremental_binary::View
symtab_view(NULL
);
538 unsigned int symtab_count
;
539 elfcpp::Elf_strtab
strtab(NULL
, 0);
540 this->get_symtab_view(&symtab_view
, &symtab_count
, &strtab
);
541 for (unsigned int i
= 0; i
< nsyms
; ++i
)
545 unsigned int output_symndx
=
546 input_file
.get_output_symbol_index(i
, &is_def
, &is_copy
);
549 const unsigned char* sym_p
= (symtab_view
.data()
550 + output_symndx
* sym_size
);
551 elfcpp::Sym
<size
, big_endian
> gsym(sym_p
);
552 unsigned int shndx
= gsym
.get_st_shndx();
553 if (shndx
< 1 || shndx
>= this->section_map_
.size())
555 Output_section
* os
= this->section_map_
[shndx
];
556 off_t offset
= gsym
.get_st_value() - os
->address();
557 os
->reserve(offset
, gsym
.get_st_size());
558 gold_debug(DEBUG_INCREMENTAL
,
559 "Reserve for COPY reloc: %s, off %d, size %d",
561 static_cast<int>(offset
),
562 static_cast<int>(gsym
.get_st_size()));
568 unsigned int shnum
= input_file
.get_input_section_count();
569 for (unsigned int i
= 0; i
< shnum
; i
++)
571 typename
Input_entry_reader::Input_section_info sect
=
572 input_file
.get_input_section(i
);
573 if (sect
.output_shndx
== 0 || sect
.sh_offset
== -1)
575 Output_section
* os
= this->section_map_
[sect
.output_shndx
];
576 gold_assert(os
!= NULL
);
577 os
->reserve(sect
.sh_offset
, sect
.sh_size
);
581 // Process the GOT and PLT entries from the existing output file.
583 template<int size
, bool big_endian
>
585 Sized_incremental_binary
<size
, big_endian
>::do_process_got_plt(
586 Symbol_table
* symtab
,
589 Incremental_got_plt_reader
<big_endian
> got_plt_reader(this->got_plt_reader());
590 Sized_target
<size
, big_endian
>* target
=
591 parameters
->sized_target
<size
, big_endian
>();
593 // Get the number of symbols in the main symbol table and in the
594 // incremental symbol table. The difference between the two counts
595 // is the index of the first forced-local or global symbol in the
596 // main symbol table.
597 unsigned int symtab_count
=
598 this->main_symtab_loc_
.data_size
/ elfcpp::Elf_sizes
<size
>::sym_size
;
599 unsigned int isym_count
= this->symtab_reader_
.symbol_count();
600 unsigned int first_global
= symtab_count
- isym_count
;
602 // Tell the target how big the GOT and PLT sections are.
603 unsigned int got_count
= got_plt_reader
.get_got_entry_count();
604 unsigned int plt_count
= got_plt_reader
.get_plt_entry_count();
605 Output_data_got
<size
, big_endian
>* got
=
606 target
->init_got_plt_for_update(symtab
, layout
, got_count
, plt_count
);
608 // Read the GOT entries from the base file and build the outgoing GOT.
609 for (unsigned int i
= 0; i
< got_count
; ++i
)
611 unsigned int got_type
= got_plt_reader
.get_got_type(i
);
612 if ((got_type
& 0x7f) == 0x7f)
614 // This is the second entry of a pair.
615 got
->reserve_slot(i
);
618 unsigned int symndx
= got_plt_reader
.get_got_symndx(i
);
621 // This is an entry for a local symbol. Ignore this entry if
622 // the object file was replaced.
623 unsigned int input_index
= got_plt_reader
.get_got_input_index(i
);
624 gold_debug(DEBUG_INCREMENTAL
,
625 "GOT entry %d, type %02x: (local symbol)",
627 Sized_relobj_incr
<size
, big_endian
>* obj
=
628 this->input_object(input_index
);
630 target
->reserve_local_got_entry(i
, obj
, symndx
, got_type
& 0x7f);
634 // This is an entry for a global symbol. GOT_DESC is the symbol
636 // FIXME: This should really be a fatal error (corrupt input).
637 gold_assert(symndx
>= first_global
&& symndx
< symtab_count
);
638 Symbol
* sym
= this->global_symbol(symndx
- first_global
);
639 // Add the GOT entry only if the symbol is still referenced.
640 if (sym
!= NULL
&& sym
->in_reg())
642 gold_debug(DEBUG_INCREMENTAL
,
643 "GOT entry %d, type %02x: %s",
644 i
, got_type
, sym
->name());
645 target
->reserve_global_got_entry(i
, sym
, got_type
);
650 // Read the PLT entries from the base file and pass each to the target.
651 for (unsigned int i
= 0; i
< plt_count
; ++i
)
653 unsigned int plt_desc
= got_plt_reader
.get_plt_desc(i
);
654 // FIXME: This should really be a fatal error (corrupt input).
655 gold_assert(plt_desc
>= first_global
&& plt_desc
< symtab_count
);
656 Symbol
* sym
= this->global_symbol(plt_desc
- first_global
);
657 // Add the PLT entry only if the symbol is still referenced.
660 gold_debug(DEBUG_INCREMENTAL
,
663 target
->register_global_plt_entry(i
, sym
);
668 // Emit COPY relocations from the existing output file.
670 template<int size
, bool big_endian
>
672 Sized_incremental_binary
<size
, big_endian
>::do_emit_copy_relocs(
673 Symbol_table
* symtab
)
675 Sized_target
<size
, big_endian
>* target
=
676 parameters
->sized_target
<size
, big_endian
>();
678 for (typename
Copy_relocs::iterator p
= this->copy_relocs_
.begin();
679 p
!= this->copy_relocs_
.end();
682 if (!(*p
).symbol
->is_copied_from_dynobj())
683 target
->emit_copy_reloc(symtab
, (*p
).symbol
, (*p
).output_section
,
688 // Apply incremental relocations for symbols whose values have changed.
690 template<int size
, bool big_endian
>
692 Sized_incremental_binary
<size
, big_endian
>::do_apply_incremental_relocs(
693 const Symbol_table
* symtab
,
697 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
698 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Addend
;
699 Incremental_symtab_reader
<big_endian
> isymtab(this->symtab_reader());
700 Incremental_relocs_reader
<size
, big_endian
> irelocs(this->relocs_reader());
701 unsigned int nglobals
= isymtab
.symbol_count();
702 const unsigned int incr_reloc_size
= irelocs
.reloc_size
;
704 Relocate_info
<size
, big_endian
> relinfo
;
705 relinfo
.symtab
= symtab
;
706 relinfo
.layout
= layout
;
707 relinfo
.object
= NULL
;
708 relinfo
.reloc_shndx
= 0;
709 relinfo
.reloc_shdr
= NULL
;
710 relinfo
.data_shndx
= 0;
711 relinfo
.data_shdr
= NULL
;
713 Sized_target
<size
, big_endian
>* target
=
714 parameters
->sized_target
<size
, big_endian
>();
716 for (unsigned int i
= 0; i
< nglobals
; i
++)
718 const Symbol
* gsym
= this->global_symbol(i
);
720 // If the symbol is not referenced from any unchanged input files,
721 // we do not need to reapply any of its relocations.
725 // If the symbol is defined in an unchanged file, we do not need to
726 // reapply any of its relocations.
727 if (gsym
->source() == Symbol::FROM_OBJECT
728 && gsym
->object()->is_incremental())
731 gold_debug(DEBUG_INCREMENTAL
,
732 "Applying incremental relocations for global symbol %s [%d]",
735 // Follow the linked list of input symbol table entries for this symbol.
736 // We don't bother to figure out whether the symbol table entry belongs
737 // to a changed or unchanged file because it's easier just to apply all
738 // the relocations -- although we might scribble over an area that has
739 // been reallocated, we do this before copying any new data into the
741 unsigned int offset
= isymtab
.get_list_head(i
);
744 Incremental_global_symbol_reader
<big_endian
> sym_info
=
745 this->inputs_reader().global_symbol_reader_at_offset(offset
);
746 unsigned int r_base
= sym_info
.reloc_offset();
747 unsigned int r_count
= sym_info
.reloc_count();
749 // Apply each relocation for this symbol table entry.
750 for (unsigned int j
= 0; j
< r_count
;
751 ++j
, r_base
+= incr_reloc_size
)
753 unsigned int r_type
= irelocs
.get_r_type(r_base
);
754 unsigned int r_shndx
= irelocs
.get_r_shndx(r_base
);
755 Address r_offset
= irelocs
.get_r_offset(r_base
);
756 Addend r_addend
= irelocs
.get_r_addend(r_base
);
757 Output_section
* os
= this->output_section(r_shndx
);
758 Address address
= os
->address();
759 off_t section_offset
= os
->offset();
760 size_t view_size
= os
->data_size();
761 unsigned char* const view
= of
->get_output_view(section_offset
,
764 gold_debug(DEBUG_INCREMENTAL
,
765 " %08lx: %s + %d: type %d addend %ld",
766 (long)(section_offset
+ r_offset
),
772 target
->apply_relocation(&relinfo
, r_offset
, r_type
, r_addend
,
773 gsym
, view
, address
, view_size
);
775 // FIXME: Do something more efficient if write_output_view
776 // ever becomes more than a no-op.
777 of
->write_output_view(section_offset
, view_size
, view
);
779 offset
= sym_info
.next_offset();
784 // Get a view of the main symbol table and the symbol string table.
786 template<int size
, bool big_endian
>
788 Sized_incremental_binary
<size
, big_endian
>::get_symtab_view(
791 elfcpp::Elf_strtab
* strtab
)
793 *symtab_view
= this->view(this->main_symtab_loc_
);
794 *nsyms
= this->main_symtab_loc_
.data_size
/ elfcpp::Elf_sizes
<size
>::sym_size
;
796 View
strtab_view(this->view(this->main_strtab_loc_
));
797 *strtab
= elfcpp::Elf_strtab(strtab_view
.data(),
798 this->main_strtab_loc_
.data_size
);
804 // Create a Sized_incremental_binary object of the specified size and
805 // endianness. Fails if the target architecture is not supported.
807 template<int size
, bool big_endian
>
809 make_sized_incremental_binary(Output_file
* file
,
810 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
812 Target
* target
= select_target(ehdr
.get_e_machine(), size
, big_endian
,
813 ehdr
.get_e_ident()[elfcpp::EI_OSABI
],
814 ehdr
.get_e_ident()[elfcpp::EI_ABIVERSION
]);
817 explain_no_incremental(_("unsupported ELF machine number %d"),
818 ehdr
.get_e_machine());
822 if (!parameters
->target_valid())
823 set_parameters_target(target
);
824 else if (target
!= ¶meters
->target())
825 gold_error(_("%s: incompatible target"), file
->filename());
827 return new Sized_incremental_binary
<size
, big_endian
>(file
, ehdr
, target
);
830 } // End of anonymous namespace.
832 // Create an Incremental_binary object for FILE. Returns NULL is this is not
833 // possible, e.g. FILE is not an ELF file or has an unsupported target. FILE
837 open_incremental_binary(Output_file
* file
)
839 off_t filesize
= file
->filesize();
840 int want
= elfcpp::Elf_recognizer::max_header_size
;
844 const unsigned char* p
= file
->get_input_view(0, want
);
845 if (!elfcpp::Elf_recognizer::is_elf_file(p
, want
))
847 explain_no_incremental(_("output is not an ELF file."));
852 bool big_endian
= false;
854 if (!elfcpp::Elf_recognizer::is_valid_header(p
, want
, &size
, &big_endian
,
857 explain_no_incremental(error
.c_str());
861 Incremental_binary
* result
= NULL
;
866 #ifdef HAVE_TARGET_32_BIG
867 result
= make_sized_incremental_binary
<32, true>(
868 file
, elfcpp::Ehdr
<32, true>(p
));
870 explain_no_incremental(_("unsupported file: 32-bit, big-endian"));
875 #ifdef HAVE_TARGET_32_LITTLE
876 result
= make_sized_incremental_binary
<32, false>(
877 file
, elfcpp::Ehdr
<32, false>(p
));
879 explain_no_incremental(_("unsupported file: 32-bit, little-endian"));
887 #ifdef HAVE_TARGET_64_BIG
888 result
= make_sized_incremental_binary
<64, true>(
889 file
, elfcpp::Ehdr
<64, true>(p
));
891 explain_no_incremental(_("unsupported file: 64-bit, big-endian"));
896 #ifdef HAVE_TARGET_64_LITTLE
897 result
= make_sized_incremental_binary
<64, false>(
898 file
, elfcpp::Ehdr
<64, false>(p
));
900 explain_no_incremental(_("unsupported file: 64-bit, little-endian"));
910 // Class Incremental_inputs.
912 // Add the command line to the string table, setting
913 // command_line_key_. In incremental builds, the command line is
914 // stored in .gnu_incremental_inputs so that the next linker run can
915 // check if the command line options didn't change.
918 Incremental_inputs::report_command_line(int argc
, const char* const* argv
)
920 // Always store 'gold' as argv[0] to avoid a full relink if the user used a
921 // different path to the linker.
922 std::string
args("gold");
923 // Copied from collect_argv in main.cc.
924 for (int i
= 1; i
< argc
; ++i
)
926 // Adding/removing these options should not result in a full relink.
927 if (strcmp(argv
[i
], "--incremental") == 0
928 || strcmp(argv
[i
], "--incremental-full") == 0
929 || strcmp(argv
[i
], "--incremental-update") == 0
930 || strcmp(argv
[i
], "--incremental-changed") == 0
931 || strcmp(argv
[i
], "--incremental-unchanged") == 0
932 || strcmp(argv
[i
], "--incremental-unknown") == 0
933 || is_prefix_of("--incremental-base=", argv
[i
])
934 || is_prefix_of("--incremental-patch=", argv
[i
])
935 || is_prefix_of("--debug=", argv
[i
]))
937 if (strcmp(argv
[i
], "--incremental-base") == 0
938 || strcmp(argv
[i
], "--incremental-patch") == 0
939 || strcmp(argv
[i
], "--debug") == 0)
941 // When these options are used without the '=', skip the
942 // following parameter as well.
948 // Now append argv[i], but with all single-quotes escaped
949 const char* argpos
= argv
[i
];
952 const int len
= strcspn(argpos
, "'");
953 args
.append(argpos
, len
);
954 if (argpos
[len
] == '\0')
956 args
.append("'\"'\"'");
962 this->command_line_
= args
;
963 this->strtab_
->add(this->command_line_
.c_str(), false,
964 &this->command_line_key_
);
967 // Record the input archive file ARCHIVE. This is called by the
968 // Add_archive_symbols task before determining which archive members
969 // to include. We create the Incremental_archive_entry here and
970 // attach it to the Archive, but we do not add it to the list of
971 // input objects until report_archive_end is called.
974 Incremental_inputs::report_archive_begin(Library_base
* arch
,
975 unsigned int arg_serial
,
976 Script_info
* script_info
)
978 Stringpool::Key filename_key
;
979 Timespec mtime
= arch
->get_mtime();
981 // For a file loaded from a script, don't record its argument serial number.
982 if (script_info
!= NULL
)
985 this->strtab_
->add(arch
->filename().c_str(), false, &filename_key
);
986 Incremental_archive_entry
* entry
=
987 new Incremental_archive_entry(filename_key
, arg_serial
, mtime
);
988 arch
->set_incremental_info(entry
);
990 if (script_info
!= NULL
)
992 Incremental_script_entry
* script_entry
= script_info
->incremental_info();
993 gold_assert(script_entry
!= NULL
);
994 script_entry
->add_object(entry
);
998 // Visitor class for processing the unused global symbols in a library.
999 // An instance of this class is passed to the library's
1000 // for_all_unused_symbols() iterator, which will call the visit()
1001 // function for each global symbol defined in each unused library
1002 // member. We add those symbol names to the incremental info for the
1005 class Unused_symbol_visitor
: public Library_base::Symbol_visitor_base
1008 Unused_symbol_visitor(Incremental_archive_entry
* entry
, Stringpool
* strtab
)
1009 : entry_(entry
), strtab_(strtab
)
1013 visit(const char* sym
)
1015 Stringpool::Key symbol_key
;
1016 this->strtab_
->add(sym
, true, &symbol_key
);
1017 this->entry_
->add_unused_global_symbol(symbol_key
);
1021 Incremental_archive_entry
* entry_
;
1022 Stringpool
* strtab_
;
1025 // Finish recording the input archive file ARCHIVE. This is called by the
1026 // Add_archive_symbols task after determining which archive members
1030 Incremental_inputs::report_archive_end(Library_base
* arch
)
1032 Incremental_archive_entry
* entry
= arch
->incremental_info();
1034 gold_assert(entry
!= NULL
);
1035 this->inputs_
.push_back(entry
);
1037 // Collect unused global symbols.
1038 Unused_symbol_visitor
v(entry
, this->strtab_
);
1039 arch
->for_all_unused_symbols(&v
);
1042 // Record the input object file OBJ. If ARCH is not NULL, attach
1043 // the object file to the archive. This is called by the
1044 // Add_symbols task after finding out the type of the file.
1047 Incremental_inputs::report_object(Object
* obj
, unsigned int arg_serial
,
1048 Library_base
* arch
, Script_info
* script_info
)
1050 Stringpool::Key filename_key
;
1051 Timespec mtime
= obj
->get_mtime();
1053 // For a file loaded from a script, don't record its argument serial number.
1054 if (script_info
!= NULL
)
1057 this->strtab_
->add(obj
->name().c_str(), false, &filename_key
);
1059 Incremental_input_entry
* input_entry
;
1061 this->current_object_
= obj
;
1063 if (!obj
->is_dynamic())
1065 this->current_object_entry_
=
1066 new Incremental_object_entry(filename_key
, obj
, arg_serial
, mtime
);
1067 input_entry
= this->current_object_entry_
;
1070 Incremental_archive_entry
* arch_entry
= arch
->incremental_info();
1071 gold_assert(arch_entry
!= NULL
);
1072 arch_entry
->add_object(this->current_object_entry_
);
1077 this->current_object_entry_
= NULL
;
1078 Stringpool::Key soname_key
;
1079 Dynobj
* dynobj
= obj
->dynobj();
1080 gold_assert(dynobj
!= NULL
);
1081 this->strtab_
->add(dynobj
->soname(), false, &soname_key
);
1082 input_entry
= new Incremental_dynobj_entry(filename_key
, soname_key
, obj
,
1086 if (obj
->is_in_system_directory())
1087 input_entry
->set_is_in_system_directory();
1089 if (obj
->as_needed())
1090 input_entry
->set_as_needed();
1092 this->inputs_
.push_back(input_entry
);
1094 if (script_info
!= NULL
)
1096 Incremental_script_entry
* script_entry
= script_info
->incremental_info();
1097 gold_assert(script_entry
!= NULL
);
1098 script_entry
->add_object(input_entry
);
1102 // Record an input section SHNDX from object file OBJ.
1105 Incremental_inputs::report_input_section(Object
* obj
, unsigned int shndx
,
1106 const char* name
, off_t sh_size
)
1108 Stringpool::Key key
= 0;
1111 this->strtab_
->add(name
, true, &key
);
1113 gold_assert(obj
== this->current_object_
);
1114 gold_assert(this->current_object_entry_
!= NULL
);
1115 this->current_object_entry_
->add_input_section(shndx
, key
, sh_size
);
1118 // Record a kept COMDAT group belonging to object file OBJ.
1121 Incremental_inputs::report_comdat_group(Object
* obj
, const char* name
)
1123 Stringpool::Key key
= 0;
1126 this->strtab_
->add(name
, true, &key
);
1127 gold_assert(obj
== this->current_object_
);
1128 gold_assert(this->current_object_entry_
!= NULL
);
1129 this->current_object_entry_
->add_comdat_group(key
);
1132 // Record that the input argument INPUT is a script SCRIPT. This is
1133 // called by read_script after parsing the script and reading the list
1134 // of inputs added by this script.
1137 Incremental_inputs::report_script(Script_info
* script
,
1138 unsigned int arg_serial
,
1141 Stringpool::Key filename_key
;
1143 this->strtab_
->add(script
->filename().c_str(), false, &filename_key
);
1144 Incremental_script_entry
* entry
=
1145 new Incremental_script_entry(filename_key
, arg_serial
, script
, mtime
);
1146 this->inputs_
.push_back(entry
);
1147 script
->set_incremental_info(entry
);
1150 // Finalize the incremental link information. Called from
1151 // Layout::finalize.
1154 Incremental_inputs::finalize()
1156 // Finalize the string table.
1157 this->strtab_
->set_string_offsets();
1160 // Create the .gnu_incremental_inputs, _symtab, and _relocs input sections.
1163 Incremental_inputs::create_data_sections(Symbol_table
* symtab
)
1165 switch (parameters
->size_and_endianness())
1167 #ifdef HAVE_TARGET_32_LITTLE
1168 case Parameters::TARGET_32_LITTLE
:
1169 this->inputs_section_
=
1170 new Output_section_incremental_inputs
<32, false>(this, symtab
);
1173 #ifdef HAVE_TARGET_32_BIG
1174 case Parameters::TARGET_32_BIG
:
1175 this->inputs_section_
=
1176 new Output_section_incremental_inputs
<32, true>(this, symtab
);
1179 #ifdef HAVE_TARGET_64_LITTLE
1180 case Parameters::TARGET_64_LITTLE
:
1181 this->inputs_section_
=
1182 new Output_section_incremental_inputs
<64, false>(this, symtab
);
1185 #ifdef HAVE_TARGET_64_BIG
1186 case Parameters::TARGET_64_BIG
:
1187 this->inputs_section_
=
1188 new Output_section_incremental_inputs
<64, true>(this, symtab
);
1194 this->symtab_section_
= new Output_data_space(4, "** incremental_symtab");
1195 this->relocs_section_
= new Output_data_space(4, "** incremental_relocs");
1196 this->got_plt_section_
= new Output_data_space(4, "** incremental_got_plt");
1199 // Return the sh_entsize value for the .gnu_incremental_relocs section.
1201 Incremental_inputs::relocs_entsize() const
1203 return 8 + 2 * parameters
->target().get_size() / 8;
1206 // Class Output_section_incremental_inputs.
1208 // Finalize the offsets for each input section and supplemental info block,
1209 // and set the final data size of the incremental output sections.
1211 template<int size
, bool big_endian
>
1213 Output_section_incremental_inputs
<size
, big_endian
>::set_final_data_size()
1215 const Incremental_inputs
* inputs
= this->inputs_
;
1216 const unsigned int sizeof_addr
= size
/ 8;
1217 const unsigned int rel_size
= 8 + 2 * sizeof_addr
;
1219 // Offset of each input entry.
1220 unsigned int input_offset
= this->header_size
;
1222 // Offset of each supplemental info block.
1223 unsigned int file_index
= 0;
1224 unsigned int info_offset
= this->header_size
;
1225 info_offset
+= this->input_entry_size
* inputs
->input_file_count();
1227 // Count each input file and its supplemental information block.
1228 for (Incremental_inputs::Input_list::const_iterator p
=
1229 inputs
->input_files().begin();
1230 p
!= inputs
->input_files().end();
1233 // Set the index and offset of the input file entry.
1234 (*p
)->set_offset(file_index
, input_offset
);
1236 input_offset
+= this->input_entry_size
;
1238 // Set the offset of the supplemental info block.
1239 switch ((*p
)->type())
1241 case INCREMENTAL_INPUT_SCRIPT
:
1243 Incremental_script_entry
*entry
= (*p
)->script_entry();
1244 gold_assert(entry
!= NULL
);
1245 (*p
)->set_info_offset(info_offset
);
1249 info_offset
+= (entry
->get_object_count() * 4);
1252 case INCREMENTAL_INPUT_OBJECT
:
1253 case INCREMENTAL_INPUT_ARCHIVE_MEMBER
:
1255 Incremental_object_entry
* entry
= (*p
)->object_entry();
1256 gold_assert(entry
!= NULL
);
1257 (*p
)->set_info_offset(info_offset
);
1258 // Input section count, global symbol count, local symbol offset,
1259 // local symbol count, first dynamic reloc, dynamic reloc count,
1260 // comdat group count.
1262 // Each input section.
1263 info_offset
+= (entry
->get_input_section_count()
1264 * (8 + 2 * sizeof_addr
));
1265 // Each global symbol.
1266 const Object::Symbols
* syms
= entry
->object()->get_global_symbols();
1267 info_offset
+= syms
->size() * 20;
1268 // Each comdat group.
1269 info_offset
+= entry
->get_comdat_group_count() * 4;
1272 case INCREMENTAL_INPUT_SHARED_LIBRARY
:
1274 Incremental_dynobj_entry
* entry
= (*p
)->dynobj_entry();
1275 gold_assert(entry
!= NULL
);
1276 (*p
)->set_info_offset(info_offset
);
1277 // Global symbol count, soname index.
1279 // Each global symbol.
1280 const Object::Symbols
* syms
= entry
->object()->get_global_symbols();
1281 gold_assert(syms
!= NULL
);
1282 unsigned int nsyms
= syms
->size();
1283 unsigned int nsyms_out
= 0;
1284 for (unsigned int i
= 0; i
< nsyms
; ++i
)
1286 const Symbol
* sym
= (*syms
)[i
];
1289 if (sym
->is_forwarder())
1290 sym
= this->symtab_
->resolve_forwards(sym
);
1291 if (sym
->symtab_index() != -1U)
1294 info_offset
+= nsyms_out
* 4;
1297 case INCREMENTAL_INPUT_ARCHIVE
:
1299 Incremental_archive_entry
* entry
= (*p
)->archive_entry();
1300 gold_assert(entry
!= NULL
);
1301 (*p
)->set_info_offset(info_offset
);
1302 // Member count + unused global symbol count.
1305 info_offset
+= (entry
->get_member_count() * 4);
1306 // Each global symbol.
1307 info_offset
+= (entry
->get_unused_global_symbol_count() * 4);
1315 this->set_data_size(info_offset
);
1317 // Set the size of the .gnu_incremental_symtab section.
1318 inputs
->symtab_section()->set_current_data_size(this->symtab_
->output_count()
1319 * sizeof(unsigned int));
1321 // Set the size of the .gnu_incremental_relocs section.
1322 inputs
->relocs_section()->set_current_data_size(inputs
->get_reloc_count()
1325 // Set the size of the .gnu_incremental_got_plt section.
1326 Sized_target
<size
, big_endian
>* target
=
1327 parameters
->sized_target
<size
, big_endian
>();
1328 unsigned int got_count
= target
->got_entry_count();
1329 unsigned int plt_count
= target
->plt_entry_count();
1330 unsigned int got_plt_size
= 8; // GOT entry count, PLT entry count.
1331 got_plt_size
= (got_plt_size
+ got_count
+ 3) & ~3; // GOT type array.
1332 got_plt_size
+= got_count
* 8 + plt_count
* 4; // GOT array, PLT array.
1333 inputs
->got_plt_section()->set_current_data_size(got_plt_size
);
1336 // Write the contents of the .gnu_incremental_inputs and
1337 // .gnu_incremental_symtab sections.
1339 template<int size
, bool big_endian
>
1341 Output_section_incremental_inputs
<size
, big_endian
>::do_write(Output_file
* of
)
1343 const Incremental_inputs
* inputs
= this->inputs_
;
1344 Stringpool
* strtab
= inputs
->get_stringpool();
1346 // Get a view into the .gnu_incremental_inputs section.
1347 const off_t off
= this->offset();
1348 const off_t oview_size
= this->data_size();
1349 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
1350 unsigned char* pov
= oview
;
1352 // Get a view into the .gnu_incremental_symtab section.
1353 const off_t symtab_off
= inputs
->symtab_section()->offset();
1354 const off_t symtab_size
= inputs
->symtab_section()->data_size();
1355 unsigned char* const symtab_view
= of
->get_output_view(symtab_off
,
1358 // Allocate an array of linked list heads for the .gnu_incremental_symtab
1359 // section. Each element corresponds to a global symbol in the output
1360 // symbol table, and points to the head of the linked list that threads
1361 // through the object file input entries. The value of each element
1362 // is the section-relative offset to a global symbol entry in a
1363 // supplemental information block.
1364 unsigned int global_sym_count
= this->symtab_
->output_count();
1365 unsigned int* global_syms
= new unsigned int[global_sym_count
];
1366 memset(global_syms
, 0, global_sym_count
* sizeof(unsigned int));
1368 // Write the section header.
1369 Stringpool::Key command_line_key
= inputs
->command_line_key();
1370 pov
= this->write_header(pov
, inputs
->input_file_count(),
1371 strtab
->get_offset_from_key(command_line_key
));
1373 // Write the list of input files.
1374 pov
= this->write_input_files(oview
, pov
, strtab
);
1376 // Write the supplemental information blocks for each input file.
1377 pov
= this->write_info_blocks(oview
, pov
, strtab
, global_syms
,
1380 gold_assert(pov
- oview
== oview_size
);
1382 // Write the .gnu_incremental_symtab section.
1383 gold_assert(global_sym_count
* 4 == symtab_size
);
1384 this->write_symtab(symtab_view
, global_syms
, global_sym_count
);
1386 delete[] global_syms
;
1388 // Write the .gnu_incremental_got_plt section.
1389 const off_t got_plt_off
= inputs
->got_plt_section()->offset();
1390 const off_t got_plt_size
= inputs
->got_plt_section()->data_size();
1391 unsigned char* const got_plt_view
= of
->get_output_view(got_plt_off
,
1393 this->write_got_plt(got_plt_view
, got_plt_size
);
1395 of
->write_output_view(off
, oview_size
, oview
);
1396 of
->write_output_view(symtab_off
, symtab_size
, symtab_view
);
1397 of
->write_output_view(got_plt_off
, got_plt_size
, got_plt_view
);
1400 // Write the section header: version, input file count, offset of command line
1401 // in the string table, and 4 bytes of padding.
1403 template<int size
, bool big_endian
>
1405 Output_section_incremental_inputs
<size
, big_endian
>::write_header(
1407 unsigned int input_file_count
,
1408 section_offset_type command_line_offset
)
1410 Swap32::writeval(pov
, INCREMENTAL_LINK_VERSION
);
1411 Swap32::writeval(pov
+ 4, input_file_count
);
1412 Swap32::writeval(pov
+ 8, command_line_offset
);
1413 Swap32::writeval(pov
+ 12, 0);
1414 return pov
+ this->header_size
;
1417 // Write the input file entries.
1419 template<int size
, bool big_endian
>
1421 Output_section_incremental_inputs
<size
, big_endian
>::write_input_files(
1422 unsigned char* oview
,
1426 const Incremental_inputs
* inputs
= this->inputs_
;
1428 for (Incremental_inputs::Input_list::const_iterator p
=
1429 inputs
->input_files().begin();
1430 p
!= inputs
->input_files().end();
1433 gold_assert(static_cast<unsigned int>(pov
- oview
) == (*p
)->get_offset());
1434 section_offset_type filename_offset
=
1435 strtab
->get_offset_from_key((*p
)->get_filename_key());
1436 const Timespec
& mtime
= (*p
)->get_mtime();
1437 unsigned int flags
= (*p
)->type();
1438 if ((*p
)->is_in_system_directory())
1439 flags
|= INCREMENTAL_INPUT_IN_SYSTEM_DIR
;
1440 if ((*p
)->as_needed())
1441 flags
|= INCREMENTAL_INPUT_AS_NEEDED
;
1442 Swap32::writeval(pov
, filename_offset
);
1443 Swap32::writeval(pov
+ 4, (*p
)->get_info_offset());
1444 Swap64::writeval(pov
+ 8, mtime
.seconds
);
1445 Swap32::writeval(pov
+ 16, mtime
.nanoseconds
);
1446 Swap16::writeval(pov
+ 20, flags
);
1447 Swap16::writeval(pov
+ 22, (*p
)->arg_serial());
1448 pov
+= this->input_entry_size
;
1453 // Write the supplemental information blocks.
1455 template<int size
, bool big_endian
>
1457 Output_section_incremental_inputs
<size
, big_endian
>::write_info_blocks(
1458 unsigned char* oview
,
1461 unsigned int* global_syms
,
1462 unsigned int global_sym_count
)
1464 const Incremental_inputs
* inputs
= this->inputs_
;
1465 unsigned int first_global_index
= this->symtab_
->first_global_index();
1467 for (Incremental_inputs::Input_list::const_iterator p
=
1468 inputs
->input_files().begin();
1469 p
!= inputs
->input_files().end();
1472 switch ((*p
)->type())
1474 case INCREMENTAL_INPUT_SCRIPT
:
1476 gold_assert(static_cast<unsigned int>(pov
- oview
)
1477 == (*p
)->get_info_offset());
1478 Incremental_script_entry
* entry
= (*p
)->script_entry();
1479 gold_assert(entry
!= NULL
);
1481 // Write the object count.
1482 unsigned int nobjects
= entry
->get_object_count();
1483 Swap32::writeval(pov
, nobjects
);
1486 // For each object, write the offset to its input file entry.
1487 for (unsigned int i
= 0; i
< nobjects
; ++i
)
1489 Incremental_input_entry
* obj
= entry
->get_object(i
);
1490 Swap32::writeval(pov
, obj
->get_offset());
1496 case INCREMENTAL_INPUT_OBJECT
:
1497 case INCREMENTAL_INPUT_ARCHIVE_MEMBER
:
1499 gold_assert(static_cast<unsigned int>(pov
- oview
)
1500 == (*p
)->get_info_offset());
1501 Incremental_object_entry
* entry
= (*p
)->object_entry();
1502 gold_assert(entry
!= NULL
);
1503 const Object
* obj
= entry
->object();
1504 const Relobj
* relobj
= static_cast<const Relobj
*>(obj
);
1505 const Object::Symbols
* syms
= obj
->get_global_symbols();
1506 // Write the input section count and global symbol count.
1507 unsigned int nsections
= entry
->get_input_section_count();
1508 unsigned int nsyms
= syms
->size();
1509 off_t locals_offset
= relobj
->local_symbol_offset();
1510 unsigned int nlocals
= relobj
->output_local_symbol_count();
1511 unsigned int first_dynrel
= relobj
->first_dyn_reloc();
1512 unsigned int ndynrel
= relobj
->dyn_reloc_count();
1513 unsigned int ncomdat
= entry
->get_comdat_group_count();
1514 Swap32::writeval(pov
, nsections
);
1515 Swap32::writeval(pov
+ 4, nsyms
);
1516 Swap32::writeval(pov
+ 8, static_cast<unsigned int>(locals_offset
));
1517 Swap32::writeval(pov
+ 12, nlocals
);
1518 Swap32::writeval(pov
+ 16, first_dynrel
);
1519 Swap32::writeval(pov
+ 20, ndynrel
);
1520 Swap32::writeval(pov
+ 24, ncomdat
);
1523 // Build a temporary array to map input section indexes
1524 // from the original object file index to the index in the
1525 // incremental info table.
1526 unsigned int* index_map
= new unsigned int[obj
->shnum()];
1527 memset(index_map
, 0, obj
->shnum() * sizeof(unsigned int));
1529 // For each input section, write the name, output section index,
1530 // offset within output section, and input section size.
1531 for (unsigned int i
= 0; i
< nsections
; i
++)
1533 unsigned int shndx
= entry
->get_input_section_index(i
);
1534 index_map
[shndx
] = i
+ 1;
1535 Stringpool::Key key
= entry
->get_input_section_name_key(i
);
1536 off_t name_offset
= 0;
1538 name_offset
= strtab
->get_offset_from_key(key
);
1540 off_t out_offset
= 0;
1542 Output_section
* os
= obj
->output_section(shndx
);
1545 out_shndx
= os
->out_shndx();
1546 out_offset
= obj
->output_section_offset(shndx
);
1547 sh_size
= entry
->get_input_section_size(i
);
1549 Swap32::writeval(pov
, name_offset
);
1550 Swap32::writeval(pov
+ 4, out_shndx
);
1551 Swap::writeval(pov
+ 8, out_offset
);
1552 Swap::writeval(pov
+ 8 + sizeof_addr
, sh_size
);
1553 pov
+= 8 + 2 * sizeof_addr
;
1556 // For each global symbol, write its associated relocations,
1557 // add it to the linked list of globals, then write the
1558 // supplemental information: global symbol table index,
1559 // input section index, linked list chain pointer, relocation
1560 // count, and offset to the relocations.
1561 for (unsigned int i
= 0; i
< nsyms
; i
++)
1563 const Symbol
* sym
= (*syms
)[i
];
1564 if (sym
->is_forwarder())
1565 sym
= this->symtab_
->resolve_forwards(sym
);
1566 unsigned int shndx
= 0;
1567 if (sym
->source() != Symbol::FROM_OBJECT
)
1569 // The symbol was defined by the linker (e.g., common).
1570 // We mark these symbols with a special SHNDX of -1,
1571 // but exclude linker-predefined symbols and symbols
1572 // copied from shared objects.
1573 if (!sym
->is_predefined()
1574 && !sym
->is_copied_from_dynobj())
1577 else if (sym
->object() == obj
&& sym
->is_defined())
1580 unsigned int orig_shndx
= sym
->shndx(&is_ordinary
);
1582 shndx
= index_map
[orig_shndx
];
1586 unsigned int symtab_index
= sym
->symtab_index();
1587 unsigned int chain
= 0;
1588 unsigned int first_reloc
= 0;
1589 unsigned int nrelocs
= obj
->get_incremental_reloc_count(i
);
1592 gold_assert(symtab_index
!= -1U
1593 && (symtab_index
- first_global_index
1594 < global_sym_count
));
1595 first_reloc
= obj
->get_incremental_reloc_base(i
);
1596 chain
= global_syms
[symtab_index
- first_global_index
];
1597 global_syms
[symtab_index
- first_global_index
] =
1600 Swap32::writeval(pov
, symtab_index
);
1601 Swap32::writeval(pov
+ 4, shndx
);
1602 Swap32::writeval(pov
+ 8, chain
);
1603 Swap32::writeval(pov
+ 12, nrelocs
);
1604 Swap32::writeval(pov
+ 16, first_reloc
* 3 * sizeof_addr
);
1608 // For each kept COMDAT group, write the group signature.
1609 for (unsigned int i
= 0; i
< ncomdat
; i
++)
1611 Stringpool::Key key
= entry
->get_comdat_signature_key(i
);
1612 off_t name_offset
= 0;
1614 name_offset
= strtab
->get_offset_from_key(key
);
1615 Swap32::writeval(pov
, name_offset
);
1623 case INCREMENTAL_INPUT_SHARED_LIBRARY
:
1625 gold_assert(static_cast<unsigned int>(pov
- oview
)
1626 == (*p
)->get_info_offset());
1627 Incremental_dynobj_entry
* entry
= (*p
)->dynobj_entry();
1628 gold_assert(entry
!= NULL
);
1629 Object
* obj
= entry
->object();
1630 Dynobj
* dynobj
= obj
->dynobj();
1631 gold_assert(dynobj
!= NULL
);
1632 const Object::Symbols
* syms
= obj
->get_global_symbols();
1634 // Write the soname string table index.
1635 section_offset_type soname_offset
=
1636 strtab
->get_offset_from_key(entry
->get_soname_key());
1637 Swap32::writeval(pov
, soname_offset
);
1640 // Skip the global symbol count for now.
1641 unsigned char* orig_pov
= pov
;
1644 // For each global symbol, write the global symbol table index.
1645 unsigned int nsyms
= syms
->size();
1646 unsigned int nsyms_out
= 0;
1647 for (unsigned int i
= 0; i
< nsyms
; i
++)
1649 const Symbol
* sym
= (*syms
)[i
];
1652 if (sym
->is_forwarder())
1653 sym
= this->symtab_
->resolve_forwards(sym
);
1654 if (sym
->symtab_index() == -1U)
1656 unsigned int flags
= 0;
1657 if (sym
->source() == Symbol::FROM_OBJECT
1658 && sym
->object() == obj
1659 && sym
->is_defined())
1660 flags
= INCREMENTAL_SHLIB_SYM_DEF
;
1661 else if (sym
->is_copied_from_dynobj()
1662 && this->symtab_
->get_copy_source(sym
) == dynobj
)
1663 flags
= INCREMENTAL_SHLIB_SYM_COPY
;
1664 flags
<<= INCREMENTAL_SHLIB_SYM_FLAGS_SHIFT
;
1665 Swap32::writeval(pov
, sym
->symtab_index() | flags
);
1670 // Now write the global symbol count.
1671 Swap32::writeval(orig_pov
, nsyms_out
);
1675 case INCREMENTAL_INPUT_ARCHIVE
:
1677 gold_assert(static_cast<unsigned int>(pov
- oview
)
1678 == (*p
)->get_info_offset());
1679 Incremental_archive_entry
* entry
= (*p
)->archive_entry();
1680 gold_assert(entry
!= NULL
);
1682 // Write the member count and unused global symbol count.
1683 unsigned int nmembers
= entry
->get_member_count();
1684 unsigned int nsyms
= entry
->get_unused_global_symbol_count();
1685 Swap32::writeval(pov
, nmembers
);
1686 Swap32::writeval(pov
+ 4, nsyms
);
1689 // For each member, write the offset to its input file entry.
1690 for (unsigned int i
= 0; i
< nmembers
; ++i
)
1692 Incremental_object_entry
* member
= entry
->get_member(i
);
1693 Swap32::writeval(pov
, member
->get_offset());
1697 // For each global symbol, write the name offset.
1698 for (unsigned int i
= 0; i
< nsyms
; ++i
)
1700 Stringpool::Key key
= entry
->get_unused_global_symbol(i
);
1701 Swap32::writeval(pov
, strtab
->get_offset_from_key(key
));
1714 // Write the contents of the .gnu_incremental_symtab section.
1716 template<int size
, bool big_endian
>
1718 Output_section_incremental_inputs
<size
, big_endian
>::write_symtab(
1720 unsigned int* global_syms
,
1721 unsigned int global_sym_count
)
1723 for (unsigned int i
= 0; i
< global_sym_count
; ++i
)
1725 Swap32::writeval(pov
, global_syms
[i
]);
1730 // This struct holds the view information needed to write the
1731 // .gnu_incremental_got_plt section.
1733 struct Got_plt_view_info
1735 // Start of the GOT type array in the output view.
1736 unsigned char* got_type_p
;
1737 // Start of the GOT descriptor array in the output view.
1738 unsigned char* got_desc_p
;
1739 // Start of the PLT descriptor array in the output view.
1740 unsigned char* plt_desc_p
;
1741 // Number of GOT entries.
1742 unsigned int got_count
;
1743 // Number of PLT entries.
1744 unsigned int plt_count
;
1745 // Offset of the first non-reserved PLT entry (this is a target-dependent value).
1746 unsigned int first_plt_entry_offset
;
1747 // Size of a PLT entry (this is a target-dependent value).
1748 unsigned int plt_entry_size
;
1749 // Symbol index to write in the GOT descriptor array. For global symbols,
1750 // this is the global symbol table index; for local symbols, it is the
1751 // local symbol table index.
1752 unsigned int sym_index
;
1753 // Input file index to write in the GOT descriptor array. For global
1754 // symbols, this is 0; for local symbols, it is the index of the input
1755 // file entry in the .gnu_incremental_inputs section.
1756 unsigned int input_index
;
1759 // Functor class for processing a GOT offset list for local symbols.
1760 // Writes the GOT type and symbol index into the GOT type and descriptor
1761 // arrays in the output section.
1763 template<int size
, bool big_endian
>
1764 class Local_got_offset_visitor
: public Got_offset_list::Visitor
1767 Local_got_offset_visitor(struct Got_plt_view_info
& info
)
1772 visit(unsigned int got_type
, unsigned int got_offset
)
1774 unsigned int got_index
= got_offset
/ this->got_entry_size_
;
1775 gold_assert(got_index
< this->info_
.got_count
);
1776 // We can only handle GOT entry types in the range 0..0x7e
1777 // because we use a byte array to store them, and we use the
1778 // high bit to flag a local symbol.
1779 gold_assert(got_type
< 0x7f);
1780 this->info_
.got_type_p
[got_index
] = got_type
| 0x80;
1781 unsigned char* pov
= this->info_
.got_desc_p
+ got_index
* 8;
1782 elfcpp::Swap
<32, big_endian
>::writeval(pov
, this->info_
.sym_index
);
1783 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, this->info_
.input_index
);
1787 static const unsigned int got_entry_size_
= size
/ 8;
1788 struct Got_plt_view_info
& info_
;
1791 // Functor class for processing a GOT offset list. Writes the GOT type
1792 // and symbol index into the GOT type and descriptor arrays in the output
1795 template<int size
, bool big_endian
>
1796 class Global_got_offset_visitor
: public Got_offset_list::Visitor
1799 Global_got_offset_visitor(struct Got_plt_view_info
& info
)
1804 visit(unsigned int got_type
, unsigned int got_offset
)
1806 unsigned int got_index
= got_offset
/ this->got_entry_size_
;
1807 gold_assert(got_index
< this->info_
.got_count
);
1808 // We can only handle GOT entry types in the range 0..0x7e
1809 // because we use a byte array to store them, and we use the
1810 // high bit to flag a local symbol.
1811 gold_assert(got_type
< 0x7f);
1812 this->info_
.got_type_p
[got_index
] = got_type
;
1813 unsigned char* pov
= this->info_
.got_desc_p
+ got_index
* 8;
1814 elfcpp::Swap
<32, big_endian
>::writeval(pov
, this->info_
.sym_index
);
1815 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, 0);
1819 static const unsigned int got_entry_size_
= size
/ 8;
1820 struct Got_plt_view_info
& info_
;
1823 // Functor class for processing the global symbol table. Processes the
1824 // GOT offset list for the symbol, and writes the symbol table index
1825 // into the PLT descriptor array in the output section.
1827 template<int size
, bool big_endian
>
1828 class Global_symbol_visitor_got_plt
1831 Global_symbol_visitor_got_plt(struct Got_plt_view_info
& info
)
1836 operator()(const Sized_symbol
<size
>* sym
)
1838 typedef Global_got_offset_visitor
<size
, big_endian
> Got_visitor
;
1839 const Got_offset_list
* got_offsets
= sym
->got_offset_list();
1840 if (got_offsets
!= NULL
)
1842 this->info_
.sym_index
= sym
->symtab_index();
1843 this->info_
.input_index
= 0;
1844 Got_visitor
v(this->info_
);
1845 got_offsets
->for_all_got_offsets(&v
);
1847 if (sym
->has_plt_offset())
1849 unsigned int plt_index
=
1850 ((sym
->plt_offset() - this->info_
.first_plt_entry_offset
)
1851 / this->info_
.plt_entry_size
);
1852 gold_assert(plt_index
< this->info_
.plt_count
);
1853 unsigned char* pov
= this->info_
.plt_desc_p
+ plt_index
* 4;
1854 elfcpp::Swap
<32, big_endian
>::writeval(pov
, sym
->symtab_index());
1859 struct Got_plt_view_info
& info_
;
1862 // Write the contents of the .gnu_incremental_got_plt section.
1864 template<int size
, bool big_endian
>
1866 Output_section_incremental_inputs
<size
, big_endian
>::write_got_plt(
1870 Sized_target
<size
, big_endian
>* target
=
1871 parameters
->sized_target
<size
, big_endian
>();
1873 // Set up the view information for the functors.
1874 struct Got_plt_view_info view_info
;
1875 view_info
.got_count
= target
->got_entry_count();
1876 view_info
.plt_count
= target
->plt_entry_count();
1877 view_info
.first_plt_entry_offset
= target
->first_plt_entry_offset();
1878 view_info
.plt_entry_size
= target
->plt_entry_size();
1879 view_info
.got_type_p
= pov
+ 8;
1880 view_info
.got_desc_p
= (view_info
.got_type_p
1881 + ((view_info
.got_count
+ 3) & ~3));
1882 view_info
.plt_desc_p
= view_info
.got_desc_p
+ view_info
.got_count
* 8;
1884 gold_assert(pov
+ view_size
==
1885 view_info
.plt_desc_p
+ view_info
.plt_count
* 4);
1887 // Write the section header.
1888 Swap32::writeval(pov
, view_info
.got_count
);
1889 Swap32::writeval(pov
+ 4, view_info
.plt_count
);
1891 // Initialize the GOT type array to 0xff (reserved).
1892 memset(view_info
.got_type_p
, 0xff, view_info
.got_count
);
1894 // Write the incremental GOT descriptors for local symbols.
1895 typedef Local_got_offset_visitor
<size
, big_endian
> Got_visitor
;
1896 for (Incremental_inputs::Input_list::const_iterator p
=
1897 this->inputs_
->input_files().begin();
1898 p
!= this->inputs_
->input_files().end();
1901 if ((*p
)->type() != INCREMENTAL_INPUT_OBJECT
1902 && (*p
)->type() != INCREMENTAL_INPUT_ARCHIVE_MEMBER
)
1904 Incremental_object_entry
* entry
= (*p
)->object_entry();
1905 gold_assert(entry
!= NULL
);
1906 const Object
* obj
= entry
->object();
1907 gold_assert(obj
!= NULL
);
1908 view_info
.input_index
= (*p
)->get_file_index();
1909 Got_visitor
v(view_info
);
1910 obj
->for_all_local_got_entries(&v
);
1913 // Write the incremental GOT and PLT descriptors for global symbols.
1914 typedef Global_symbol_visitor_got_plt
<size
, big_endian
> Symbol_visitor
;
1915 symtab_
->for_all_symbols
<size
, Symbol_visitor
>(Symbol_visitor(view_info
));
1918 // Class Sized_relobj_incr. Most of these methods are not used for
1919 // Incremental objects, but are required to be implemented by the
1920 // base class Object.
1922 template<int size
, bool big_endian
>
1923 Sized_relobj_incr
<size
, big_endian
>::Sized_relobj_incr(
1924 const std::string
& name
,
1925 Sized_incremental_binary
<size
, big_endian
>* ibase
,
1926 unsigned int input_file_index
)
1927 : Sized_relobj
<size
, big_endian
>(name
, NULL
), ibase_(ibase
),
1928 input_file_index_(input_file_index
),
1929 input_reader_(ibase
->inputs_reader().input_file(input_file_index
)),
1930 local_symbol_count_(0), output_local_dynsym_count_(0),
1931 local_symbol_index_(0), local_symbol_offset_(0), local_dynsym_offset_(0),
1932 symbols_(), incr_reloc_offset_(-1U), incr_reloc_count_(0),
1933 incr_reloc_output_index_(0), incr_relocs_(NULL
), local_symbols_()
1935 if (this->input_reader_
.is_in_system_directory())
1936 this->set_is_in_system_directory();
1937 const unsigned int shnum
= this->input_reader_
.get_input_section_count() + 1;
1938 this->set_shnum(shnum
);
1939 ibase
->set_input_object(input_file_index
, this);
1942 // Read the symbols.
1944 template<int size
, bool big_endian
>
1946 Sized_relobj_incr
<size
, big_endian
>::do_read_symbols(Read_symbols_data
*)
1951 // Lay out the input sections.
1953 template<int size
, bool big_endian
>
1955 Sized_relobj_incr
<size
, big_endian
>::do_layout(
1960 const unsigned int shnum
= this->shnum();
1961 Incremental_inputs
* incremental_inputs
= layout
->incremental_inputs();
1962 gold_assert(incremental_inputs
!= NULL
);
1963 Output_sections
& out_sections(this->output_sections());
1964 out_sections
.resize(shnum
);
1965 this->section_offsets().resize(shnum
);
1966 for (unsigned int i
= 1; i
< shnum
; i
++)
1968 typename
Input_entry_reader::Input_section_info sect
=
1969 this->input_reader_
.get_input_section(i
- 1);
1970 // Add the section to the incremental inputs layout.
1971 incremental_inputs
->report_input_section(this, i
, sect
.name
,
1973 if (sect
.output_shndx
== 0 || sect
.sh_offset
== -1)
1975 Output_section
* os
= this->ibase_
->output_section(sect
.output_shndx
);
1976 gold_assert(os
!= NULL
);
1977 out_sections
[i
] = os
;
1978 this->section_offsets()[i
] = static_cast<Address
>(sect
.sh_offset
);
1981 // Process the COMDAT groups.
1982 unsigned int ncomdat
= this->input_reader_
.get_comdat_group_count();
1983 for (unsigned int i
= 0; i
< ncomdat
; i
++)
1985 const char* signature
= this->input_reader_
.get_comdat_group_signature(i
);
1986 if (signature
== NULL
|| signature
[0] == '\0')
1987 this->error(_("COMDAT group has no signature"));
1988 bool keep
= layout
->find_or_add_kept_section(signature
, this, i
, true,
1991 this->error(_("COMDAT group %s included twice in incremental link"),
1996 // Layout sections whose layout was deferred while waiting for
1997 // input files from a plugin.
1998 template<int size
, bool big_endian
>
2000 Sized_relobj_incr
<size
, big_endian
>::do_layout_deferred_sections(Layout
*)
2004 // Add the symbols to the symbol table.
2006 template<int size
, bool big_endian
>
2008 Sized_relobj_incr
<size
, big_endian
>::do_add_symbols(
2009 Symbol_table
* symtab
,
2013 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2014 unsigned char symbuf
[sym_size
];
2015 elfcpp::Sym
<size
, big_endian
> sym(symbuf
);
2016 elfcpp::Sym_write
<size
, big_endian
> osym(symbuf
);
2018 typedef typename
elfcpp::Elf_types
<size
>::Elf_WXword Elf_size_type
;
2020 unsigned int nsyms
= this->input_reader_
.get_global_symbol_count();
2021 this->symbols_
.resize(nsyms
);
2023 Incremental_binary::View
symtab_view(NULL
);
2024 unsigned int symtab_count
;
2025 elfcpp::Elf_strtab
strtab(NULL
, 0);
2026 this->ibase_
->get_symtab_view(&symtab_view
, &symtab_count
, &strtab
);
2028 Incremental_symtab_reader
<big_endian
> isymtab(this->ibase_
->symtab_reader());
2029 unsigned int isym_count
= isymtab
.symbol_count();
2030 unsigned int first_global
= symtab_count
- isym_count
;
2032 const unsigned char* sym_p
;
2033 for (unsigned int i
= 0; i
< nsyms
; ++i
)
2035 Incremental_global_symbol_reader
<big_endian
> info
=
2036 this->input_reader_
.get_global_symbol_reader(i
);
2037 unsigned int output_symndx
= info
.output_symndx();
2038 sym_p
= symtab_view
.data() + output_symndx
* sym_size
;
2039 elfcpp::Sym
<size
, big_endian
> gsym(sym_p
);
2041 if (!strtab
.get_c_string(gsym
.get_st_name(), &name
))
2044 typename
elfcpp::Elf_types
<size
>::Elf_Addr v
= gsym
.get_st_value();
2045 unsigned int shndx
= gsym
.get_st_shndx();
2046 elfcpp::STB st_bind
= gsym
.get_st_bind();
2047 elfcpp::STT st_type
= gsym
.get_st_type();
2049 // Local hidden symbols start out as globals, but get converted to
2050 // to local during output.
2051 if (st_bind
== elfcpp::STB_LOCAL
)
2052 st_bind
= elfcpp::STB_GLOBAL
;
2054 unsigned int input_shndx
= info
.shndx();
2055 if (input_shndx
== 0 || input_shndx
== -1U)
2057 shndx
= elfcpp::SHN_UNDEF
;
2060 else if (shndx
!= elfcpp::SHN_ABS
)
2062 // Find the input section and calculate the section-relative value.
2063 gold_assert(shndx
!= elfcpp::SHN_UNDEF
);
2064 Output_section
* os
= this->ibase_
->output_section(shndx
);
2065 gold_assert(os
!= NULL
&& os
->has_fixed_layout());
2066 typename
Input_entry_reader::Input_section_info sect
=
2067 this->input_reader_
.get_input_section(input_shndx
- 1);
2068 gold_assert(sect
.output_shndx
== shndx
);
2069 if (st_type
!= elfcpp::STT_TLS
)
2071 v
-= sect
.sh_offset
;
2072 shndx
= input_shndx
;
2075 osym
.put_st_name(0);
2076 osym
.put_st_value(v
);
2077 osym
.put_st_size(gsym
.get_st_size());
2078 osym
.put_st_info(st_bind
, st_type
);
2079 osym
.put_st_other(gsym
.get_st_other());
2080 osym
.put_st_shndx(shndx
);
2082 Symbol
* res
= symtab
->add_from_incrobj(this, name
, NULL
, &sym
);
2084 // If this is a linker-defined symbol that hasn't yet been defined,
2086 if (input_shndx
== -1U && !res
->is_defined())
2088 shndx
= gsym
.get_st_shndx();
2089 v
= gsym
.get_st_value();
2090 Elf_size_type symsize
= gsym
.get_st_size();
2091 if (shndx
== elfcpp::SHN_ABS
)
2093 symtab
->define_as_constant(name
, NULL
,
2094 Symbol_table::INCREMENTAL_BASE
,
2095 v
, symsize
, st_type
, st_bind
,
2096 gsym
.get_st_visibility(), 0,
2101 Output_section
* os
= this->ibase_
->output_section(shndx
);
2102 gold_assert(os
!= NULL
&& os
->has_fixed_layout());
2105 os
->reserve(v
, symsize
);
2106 symtab
->define_in_output_data(name
, NULL
,
2107 Symbol_table::INCREMENTAL_BASE
,
2108 os
, v
, symsize
, st_type
, st_bind
,
2109 gsym
.get_st_visibility(), 0,
2114 this->symbols_
[i
] = res
;
2115 this->ibase_
->add_global_symbol(output_symndx
- first_global
, res
);
2119 // Return TRUE if we should include this object from an archive library.
2121 template<int size
, bool big_endian
>
2122 Archive::Should_include
2123 Sized_relobj_incr
<size
, big_endian
>::do_should_include_member(
2132 // Iterate over global symbols, calling a visitor class V for each.
2134 template<int size
, bool big_endian
>
2136 Sized_relobj_incr
<size
, big_endian
>::do_for_all_global_symbols(
2138 Library_base::Symbol_visitor_base
*)
2140 // This routine is not used for incremental objects.
2143 // Get the size of a section.
2145 template<int size
, bool big_endian
>
2147 Sized_relobj_incr
<size
, big_endian
>::do_section_size(unsigned int)
2152 // Get the name of a section.
2154 template<int size
, bool big_endian
>
2156 Sized_relobj_incr
<size
, big_endian
>::do_section_name(unsigned int)
2161 // Return a view of the contents of a section.
2163 template<int size
, bool big_endian
>
2165 Sized_relobj_incr
<size
, big_endian
>::do_section_contents(unsigned int)
2170 // Return section flags.
2172 template<int size
, bool big_endian
>
2174 Sized_relobj_incr
<size
, big_endian
>::do_section_flags(unsigned int)
2179 // Return section entsize.
2181 template<int size
, bool big_endian
>
2183 Sized_relobj_incr
<size
, big_endian
>::do_section_entsize(unsigned int)
2188 // Return section address.
2190 template<int size
, bool big_endian
>
2192 Sized_relobj_incr
<size
, big_endian
>::do_section_address(unsigned int)
2197 // Return section type.
2199 template<int size
, bool big_endian
>
2201 Sized_relobj_incr
<size
, big_endian
>::do_section_type(unsigned int)
2206 // Return the section link field.
2208 template<int size
, bool big_endian
>
2210 Sized_relobj_incr
<size
, big_endian
>::do_section_link(unsigned int)
2215 // Return the section link field.
2217 template<int size
, bool big_endian
>
2219 Sized_relobj_incr
<size
, big_endian
>::do_section_info(unsigned int)
2224 // Return the section alignment.
2226 template<int size
, bool big_endian
>
2228 Sized_relobj_incr
<size
, big_endian
>::do_section_addralign(unsigned int)
2233 // Return the Xindex structure to use.
2235 template<int size
, bool big_endian
>
2237 Sized_relobj_incr
<size
, big_endian
>::do_initialize_xindex()
2242 // Get symbol counts.
2244 template<int size
, bool big_endian
>
2246 Sized_relobj_incr
<size
, big_endian
>::do_get_global_symbol_counts(
2247 const Symbol_table
*, size_t*, size_t*) const
2254 template<int size
, bool big_endian
>
2256 Sized_relobj_incr
<size
, big_endian
>::do_read_relocs(Read_relocs_data
*)
2260 // Process the relocs to find list of referenced sections. Used only
2261 // during garbage collection.
2263 template<int size
, bool big_endian
>
2265 Sized_relobj_incr
<size
, big_endian
>::do_gc_process_relocs(Symbol_table
*,
2272 // Scan the relocs and adjust the symbol table.
2274 template<int size
, bool big_endian
>
2276 Sized_relobj_incr
<size
, big_endian
>::do_scan_relocs(Symbol_table
*,
2280 // Count the incremental relocations for this object.
2281 unsigned int nsyms
= this->input_reader_
.get_global_symbol_count();
2282 this->allocate_incremental_reloc_counts();
2283 for (unsigned int i
= 0; i
< nsyms
; i
++)
2285 Incremental_global_symbol_reader
<big_endian
> sym
=
2286 this->input_reader_
.get_global_symbol_reader(i
);
2287 unsigned int reloc_count
= sym
.reloc_count();
2288 if (reloc_count
> 0 && this->incr_reloc_offset_
== -1U)
2289 this->incr_reloc_offset_
= sym
.reloc_offset();
2290 this->incr_reloc_count_
+= reloc_count
;
2291 for (unsigned int j
= 0; j
< reloc_count
; j
++)
2292 this->count_incremental_reloc(i
);
2294 this->incr_reloc_output_index_
=
2295 layout
->incremental_inputs()->get_reloc_count();
2296 this->finalize_incremental_relocs(layout
, false);
2298 // The incoming incremental relocations may not end up in the same
2299 // location after the incremental update, because the incremental info
2300 // is regenerated in each link. Because the new location may overlap
2301 // with other data in the updated output file, we need to copy the
2302 // relocations into a buffer so that we can still read them safely
2303 // after we start writing updates to the output file.
2304 if (this->incr_reloc_count_
> 0)
2306 const Incremental_relocs_reader
<size
, big_endian
>& relocs_reader
=
2307 this->ibase_
->relocs_reader();
2308 const unsigned int incr_reloc_size
= relocs_reader
.reloc_size
;
2309 unsigned int len
= this->incr_reloc_count_
* incr_reloc_size
;
2310 this->incr_relocs_
= new unsigned char[len
];
2311 memcpy(this->incr_relocs_
,
2312 relocs_reader
.data(this->incr_reloc_offset_
),
2317 // Count the local symbols.
2319 template<int size
, bool big_endian
>
2321 Sized_relobj_incr
<size
, big_endian
>::do_count_local_symbols(
2322 Stringpool_template
<char>* pool
,
2323 Stringpool_template
<char>*)
2325 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2327 // Set the count of local symbols based on the incremental info.
2328 unsigned int nlocals
= this->input_reader_
.get_local_symbol_count();
2329 this->local_symbol_count_
= nlocals
;
2330 this->local_symbols_
.reserve(nlocals
);
2332 // Get views of the base file's symbol table and string table.
2333 Incremental_binary::View
symtab_view(NULL
);
2334 unsigned int symtab_count
;
2335 elfcpp::Elf_strtab
strtab(NULL
, 0);
2336 this->ibase_
->get_symtab_view(&symtab_view
, &symtab_count
, &strtab
);
2338 // Read the local symbols from the base file's symbol table.
2339 off_t off
= this->input_reader_
.get_local_symbol_offset();
2340 const unsigned char* symp
= symtab_view
.data() + off
;
2341 for (unsigned int i
= 0; i
< nlocals
; ++i
, symp
+= sym_size
)
2343 elfcpp::Sym
<size
, big_endian
> sym(symp
);
2345 if (!strtab
.get_c_string(sym
.get_st_name(), &name
))
2347 gold_debug(DEBUG_INCREMENTAL
, "Local symbol %d: %s", i
, name
);
2348 name
= pool
->add(name
, true, NULL
);
2349 this->local_symbols_
.push_back(Local_symbol(name
,
2358 // Finalize the local symbols.
2360 template<int size
, bool big_endian
>
2362 Sized_relobj_incr
<size
, big_endian
>::do_finalize_local_symbols(
2367 this->local_symbol_index_
= index
;
2368 this->local_symbol_offset_
= off
;
2369 return index
+ this->local_symbol_count_
;
2372 // Set the offset where local dynamic symbol information will be stored.
2374 template<int size
, bool big_endian
>
2376 Sized_relobj_incr
<size
, big_endian
>::do_set_local_dynsym_indexes(
2379 // FIXME: set local dynsym indexes.
2383 // Set the offset where local dynamic symbol information will be stored.
2385 template<int size
, bool big_endian
>
2387 Sized_relobj_incr
<size
, big_endian
>::do_set_local_dynsym_offset(off_t
)
2392 // Relocate the input sections and write out the local symbols.
2393 // We don't actually do any relocation here. For unchanged input files,
2394 // we reapply relocations only for symbols that have changed; that happens
2395 // in queue_final_tasks. We do need to rewrite the incremental relocations
2398 template<int size
, bool big_endian
>
2400 Sized_relobj_incr
<size
, big_endian
>::do_relocate(const Symbol_table
*,
2401 const Layout
* layout
,
2404 if (this->incr_reloc_count_
== 0)
2407 const unsigned int incr_reloc_size
=
2408 Incremental_relocs_reader
<size
, big_endian
>::reloc_size
;
2410 // Get a view for the .gnu_incremental_relocs section.
2411 Incremental_inputs
* inputs
= layout
->incremental_inputs();
2412 gold_assert(inputs
!= NULL
);
2413 const off_t relocs_off
= inputs
->relocs_section()->offset();
2414 const off_t relocs_size
= inputs
->relocs_section()->data_size();
2415 unsigned char* const view
= of
->get_output_view(relocs_off
, relocs_size
);
2417 // Copy the relocations from the buffer.
2418 off_t off
= this->incr_reloc_output_index_
* incr_reloc_size
;
2419 unsigned int len
= this->incr_reloc_count_
* incr_reloc_size
;
2420 memcpy(view
+ off
, this->incr_relocs_
, len
);
2422 // The output section table may have changed, so we need to map
2423 // the old section index to the new section index for each relocation.
2424 for (unsigned int i
= 0; i
< this->incr_reloc_count_
; ++i
)
2426 unsigned char* pov
= view
+ off
+ i
* incr_reloc_size
;
2427 unsigned int shndx
= elfcpp::Swap
<32, big_endian
>::readval(pov
+ 4);
2428 Output_section
* os
= this->ibase_
->output_section(shndx
);
2429 gold_assert(os
!= NULL
);
2430 shndx
= os
->out_shndx();
2431 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, shndx
);
2434 of
->write_output_view(off
, len
, view
);
2436 // Get views into the output file for the portions of the symbol table
2437 // and the dynamic symbol table that we will be writing.
2438 off_t symtab_off
= layout
->symtab_section()->offset();
2439 off_t output_size
= this->local_symbol_count_
* This::sym_size
;
2440 unsigned char* oview
= NULL
;
2441 if (output_size
> 0)
2442 oview
= of
->get_output_view(symtab_off
+ this->local_symbol_offset_
,
2445 off_t dyn_output_size
= this->output_local_dynsym_count_
* sym_size
;
2446 unsigned char* dyn_oview
= NULL
;
2447 if (dyn_output_size
> 0)
2448 dyn_oview
= of
->get_output_view(this->local_dynsym_offset_
,
2451 // Write the local symbols.
2452 unsigned char* ov
= oview
;
2453 unsigned char* dyn_ov
= dyn_oview
;
2454 const Stringpool
* sympool
= layout
->sympool();
2455 const Stringpool
* dynpool
= layout
->dynpool();
2456 Output_symtab_xindex
* symtab_xindex
= layout
->symtab_xindex();
2457 Output_symtab_xindex
* dynsym_xindex
= layout
->dynsym_xindex();
2458 for (unsigned int i
= 0; i
< this->local_symbol_count_
; ++i
)
2460 Local_symbol
& lsym(this->local_symbols_
[i
]);
2463 unsigned int st_shndx
= this->adjust_sym_shndx(i
, lsym
.st_shndx
,
2467 Output_section
* os
= this->ibase_
->output_section(st_shndx
);
2468 st_shndx
= os
->out_shndx();
2469 if (st_shndx
>= elfcpp::SHN_LORESERVE
)
2471 symtab_xindex
->add(this->local_symbol_index_
+ i
, st_shndx
);
2472 if (lsym
.needs_dynsym_entry
)
2473 dynsym_xindex
->add(lsym
.output_dynsym_index
, st_shndx
);
2474 st_shndx
= elfcpp::SHN_XINDEX
;
2478 // Write the symbol to the output symbol table.
2480 elfcpp::Sym_write
<size
, big_endian
> osym(ov
);
2481 osym
.put_st_name(sympool
->get_offset(lsym
.name
));
2482 osym
.put_st_value(lsym
.st_value
);
2483 osym
.put_st_size(lsym
.st_size
);
2484 osym
.put_st_info(elfcpp::STB_LOCAL
,
2485 static_cast<elfcpp::STT
>(lsym
.st_type
));
2486 osym
.put_st_other(0);
2487 osym
.put_st_shndx(st_shndx
);
2491 // Write the symbol to the output dynamic symbol table.
2492 if (lsym
.needs_dynsym_entry
)
2494 gold_assert(dyn_ov
< dyn_oview
+ dyn_output_size
);
2495 elfcpp::Sym_write
<size
, big_endian
> osym(dyn_ov
);
2496 osym
.put_st_name(dynpool
->get_offset(lsym
.name
));
2497 osym
.put_st_value(lsym
.st_value
);
2498 osym
.put_st_size(lsym
.st_size
);
2499 osym
.put_st_info(elfcpp::STB_LOCAL
,
2500 static_cast<elfcpp::STT
>(lsym
.st_type
));
2501 osym
.put_st_other(0);
2502 osym
.put_st_shndx(st_shndx
);
2507 if (output_size
> 0)
2509 gold_assert(ov
- oview
== output_size
);
2510 of
->write_output_view(symtab_off
+ this->local_symbol_offset_
,
2511 output_size
, oview
);
2514 if (dyn_output_size
> 0)
2516 gold_assert(dyn_ov
- dyn_oview
== dyn_output_size
);
2517 of
->write_output_view(this->local_dynsym_offset_
, dyn_output_size
,
2522 // Set the offset of a section.
2524 template<int size
, bool big_endian
>
2526 Sized_relobj_incr
<size
, big_endian
>::do_set_section_offset(unsigned int,
2531 // Class Sized_incr_dynobj. Most of these methods are not used for
2532 // Incremental objects, but are required to be implemented by the
2533 // base class Object.
2535 template<int size
, bool big_endian
>
2536 Sized_incr_dynobj
<size
, big_endian
>::Sized_incr_dynobj(
2537 const std::string
& name
,
2538 Sized_incremental_binary
<size
, big_endian
>* ibase
,
2539 unsigned int input_file_index
)
2540 : Dynobj(name
, NULL
), ibase_(ibase
),
2541 input_file_index_(input_file_index
),
2542 input_reader_(ibase
->inputs_reader().input_file(input_file_index
)),
2545 if (this->input_reader_
.is_in_system_directory())
2546 this->set_is_in_system_directory();
2547 if (this->input_reader_
.as_needed())
2548 this->set_as_needed();
2549 this->set_soname_string(this->input_reader_
.get_soname());
2553 // Read the symbols.
2555 template<int size
, bool big_endian
>
2557 Sized_incr_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
*)
2562 // Lay out the input sections.
2564 template<int size
, bool big_endian
>
2566 Sized_incr_dynobj
<size
, big_endian
>::do_layout(
2573 // Add the symbols to the symbol table.
2575 template<int size
, bool big_endian
>
2577 Sized_incr_dynobj
<size
, big_endian
>::do_add_symbols(
2578 Symbol_table
* symtab
,
2582 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2583 unsigned char symbuf
[sym_size
];
2584 elfcpp::Sym
<size
, big_endian
> sym(symbuf
);
2585 elfcpp::Sym_write
<size
, big_endian
> osym(symbuf
);
2587 typedef typename
elfcpp::Elf_types
<size
>::Elf_WXword Elf_size_type
;
2589 unsigned int nsyms
= this->input_reader_
.get_global_symbol_count();
2590 this->symbols_
.resize(nsyms
);
2592 Incremental_binary::View
symtab_view(NULL
);
2593 unsigned int symtab_count
;
2594 elfcpp::Elf_strtab
strtab(NULL
, 0);
2595 this->ibase_
->get_symtab_view(&symtab_view
, &symtab_count
, &strtab
);
2597 Incremental_symtab_reader
<big_endian
> isymtab(this->ibase_
->symtab_reader());
2598 unsigned int isym_count
= isymtab
.symbol_count();
2599 unsigned int first_global
= symtab_count
- isym_count
;
2601 // We keep a set of symbols that we have generated COPY relocations
2602 // for, indexed by the symbol value. We do not need more than one
2603 // COPY relocation per address.
2604 typedef typename
std::set
<Address
> Copied_symbols
;
2605 Copied_symbols copied_symbols
;
2607 const unsigned char* sym_p
;
2608 for (unsigned int i
= 0; i
< nsyms
; ++i
)
2612 unsigned int output_symndx
=
2613 this->input_reader_
.get_output_symbol_index(i
, &is_def
, &is_copy
);
2614 sym_p
= symtab_view
.data() + output_symndx
* sym_size
;
2615 elfcpp::Sym
<size
, big_endian
> gsym(sym_p
);
2617 if (!strtab
.get_c_string(gsym
.get_st_name(), &name
))
2622 elfcpp::STB st_bind
= gsym
.get_st_bind();
2623 elfcpp::STT st_type
= gsym
.get_st_type();
2625 // Local hidden symbols start out as globals, but get converted to
2626 // to local during output.
2627 if (st_bind
== elfcpp::STB_LOCAL
)
2628 st_bind
= elfcpp::STB_GLOBAL
;
2632 shndx
= elfcpp::SHN_UNDEF
;
2637 // For a symbol defined in a shared object, the section index
2638 // is meaningless, as long as it's not SHN_UNDEF.
2640 v
= gsym
.get_st_value();
2643 osym
.put_st_name(0);
2644 osym
.put_st_value(v
);
2645 osym
.put_st_size(gsym
.get_st_size());
2646 osym
.put_st_info(st_bind
, st_type
);
2647 osym
.put_st_other(gsym
.get_st_other());
2648 osym
.put_st_shndx(shndx
);
2650 Sized_symbol
<size
>* res
=
2651 symtab
->add_from_incrobj
<size
, big_endian
>(this, name
, NULL
, &sym
);
2652 this->symbols_
[i
] = res
;
2653 this->ibase_
->add_global_symbol(output_symndx
- first_global
,
2658 std::pair
<typename
Copied_symbols::iterator
, bool> ins
=
2659 copied_symbols
.insert(v
);
2662 unsigned int shndx
= gsym
.get_st_shndx();
2663 Output_section
* os
= this->ibase_
->output_section(shndx
);
2664 off_t offset
= v
- os
->address();
2665 this->ibase_
->add_copy_reloc(this->symbols_
[i
], os
, offset
);
2671 // Return TRUE if we should include this object from an archive library.
2673 template<int size
, bool big_endian
>
2674 Archive::Should_include
2675 Sized_incr_dynobj
<size
, big_endian
>::do_should_include_member(
2684 // Iterate over global symbols, calling a visitor class V for each.
2686 template<int size
, bool big_endian
>
2688 Sized_incr_dynobj
<size
, big_endian
>::do_for_all_global_symbols(
2690 Library_base::Symbol_visitor_base
*)
2692 // This routine is not used for dynamic libraries.
2695 // Iterate over local symbols, calling a visitor class V for each GOT offset
2696 // associated with a local symbol.
2698 template<int size
, bool big_endian
>
2700 Sized_incr_dynobj
<size
, big_endian
>::do_for_all_local_got_entries(
2701 Got_offset_list::Visitor
*) const
2705 // Get the size of a section.
2707 template<int size
, bool big_endian
>
2709 Sized_incr_dynobj
<size
, big_endian
>::do_section_size(unsigned int)
2714 // Get the name of a section.
2716 template<int size
, bool big_endian
>
2718 Sized_incr_dynobj
<size
, big_endian
>::do_section_name(unsigned int)
2723 // Return a view of the contents of a section.
2725 template<int size
, bool big_endian
>
2727 Sized_incr_dynobj
<size
, big_endian
>::do_section_contents(unsigned int)
2732 // Return section flags.
2734 template<int size
, bool big_endian
>
2736 Sized_incr_dynobj
<size
, big_endian
>::do_section_flags(unsigned int)
2741 // Return section entsize.
2743 template<int size
, bool big_endian
>
2745 Sized_incr_dynobj
<size
, big_endian
>::do_section_entsize(unsigned int)
2750 // Return section address.
2752 template<int size
, bool big_endian
>
2754 Sized_incr_dynobj
<size
, big_endian
>::do_section_address(unsigned int)
2759 // Return section type.
2761 template<int size
, bool big_endian
>
2763 Sized_incr_dynobj
<size
, big_endian
>::do_section_type(unsigned int)
2768 // Return the section link field.
2770 template<int size
, bool big_endian
>
2772 Sized_incr_dynobj
<size
, big_endian
>::do_section_link(unsigned int)
2777 // Return the section link field.
2779 template<int size
, bool big_endian
>
2781 Sized_incr_dynobj
<size
, big_endian
>::do_section_info(unsigned int)
2786 // Return the section alignment.
2788 template<int size
, bool big_endian
>
2790 Sized_incr_dynobj
<size
, big_endian
>::do_section_addralign(unsigned int)
2795 // Return the Xindex structure to use.
2797 template<int size
, bool big_endian
>
2799 Sized_incr_dynobj
<size
, big_endian
>::do_initialize_xindex()
2804 // Get symbol counts.
2806 template<int size
, bool big_endian
>
2808 Sized_incr_dynobj
<size
, big_endian
>::do_get_global_symbol_counts(
2809 const Symbol_table
*, size_t*, size_t*) const
2814 // Allocate an incremental object of the appropriate size and endianness.
2817 make_sized_incremental_object(
2818 Incremental_binary
* ibase
,
2819 unsigned int input_file_index
,
2820 Incremental_input_type input_type
,
2821 const Incremental_binary::Input_reader
* input_reader
)
2824 std::string
name(input_reader
->filename());
2826 switch (parameters
->size_and_endianness())
2828 #ifdef HAVE_TARGET_32_LITTLE
2829 case Parameters::TARGET_32_LITTLE
:
2831 Sized_incremental_binary
<32, false>* sized_ibase
=
2832 static_cast<Sized_incremental_binary
<32, false>*>(ibase
);
2833 if (input_type
== INCREMENTAL_INPUT_SHARED_LIBRARY
)
2834 obj
= new Sized_incr_dynobj
<32, false>(name
, sized_ibase
,
2837 obj
= new Sized_relobj_incr
<32, false>(name
, sized_ibase
,
2842 #ifdef HAVE_TARGET_32_BIG
2843 case Parameters::TARGET_32_BIG
:
2845 Sized_incremental_binary
<32, true>* sized_ibase
=
2846 static_cast<Sized_incremental_binary
<32, true>*>(ibase
);
2847 if (input_type
== INCREMENTAL_INPUT_SHARED_LIBRARY
)
2848 obj
= new Sized_incr_dynobj
<32, true>(name
, sized_ibase
,
2851 obj
= new Sized_relobj_incr
<32, true>(name
, sized_ibase
,
2856 #ifdef HAVE_TARGET_64_LITTLE
2857 case Parameters::TARGET_64_LITTLE
:
2859 Sized_incremental_binary
<64, false>* sized_ibase
=
2860 static_cast<Sized_incremental_binary
<64, false>*>(ibase
);
2861 if (input_type
== INCREMENTAL_INPUT_SHARED_LIBRARY
)
2862 obj
= new Sized_incr_dynobj
<64, false>(name
, sized_ibase
,
2865 obj
= new Sized_relobj_incr
<64, false>(name
, sized_ibase
,
2870 #ifdef HAVE_TARGET_64_BIG
2871 case Parameters::TARGET_64_BIG
:
2873 Sized_incremental_binary
<64, true>* sized_ibase
=
2874 static_cast<Sized_incremental_binary
<64, true>*>(ibase
);
2875 if (input_type
== INCREMENTAL_INPUT_SHARED_LIBRARY
)
2876 obj
= new Sized_incr_dynobj
<64, true>(name
, sized_ibase
,
2879 obj
= new Sized_relobj_incr
<64, true>(name
, sized_ibase
,
2888 gold_assert(obj
!= NULL
);
2892 // Copy the unused symbols from the incremental input info.
2893 // We need to do this because we may be overwriting the incremental
2894 // input info in the base file before we write the new incremental
2897 Incremental_library::copy_unused_symbols()
2899 unsigned int symcount
= this->input_reader_
->get_unused_symbol_count();
2900 this->unused_symbols_
.reserve(symcount
);
2901 for (unsigned int i
= 0; i
< symcount
; ++i
)
2903 std::string
name(this->input_reader_
->get_unused_symbol(i
));
2904 this->unused_symbols_
.push_back(name
);
2908 // Iterator for unused global symbols in the library.
2910 Incremental_library::do_for_all_unused_symbols(Symbol_visitor_base
* v
) const
2912 for (Symbol_list::const_iterator p
= this->unused_symbols_
.begin();
2913 p
!= this->unused_symbols_
.end();
2915 v
->visit(p
->c_str());
2918 // Instantiate the templates we need.
2920 #ifdef HAVE_TARGET_32_LITTLE
2922 class Sized_incremental_binary
<32, false>;
2925 class Sized_relobj_incr
<32, false>;
2928 class Sized_incr_dynobj
<32, false>;
2931 #ifdef HAVE_TARGET_32_BIG
2933 class Sized_incremental_binary
<32, true>;
2936 class Sized_relobj_incr
<32, true>;
2939 class Sized_incr_dynobj
<32, true>;
2942 #ifdef HAVE_TARGET_64_LITTLE
2944 class Sized_incremental_binary
<64, false>;
2947 class Sized_relobj_incr
<64, false>;
2950 class Sized_incr_dynobj
<64, false>;
2953 #ifdef HAVE_TARGET_64_BIG
2955 class Sized_incremental_binary
<64, true>;
2958 class Sized_relobj_incr
<64, true>;
2961 class Sized_incr_dynobj
<64, true>;
2964 } // End namespace gold.