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 gold_debug(DEBUG_INCREMENTAL
,
634 "GOT entry %d, type %02x: %s",
635 i
, got_type
, sym
->name());
636 target
->reserve_global_got_entry(i
, sym
, got_type
);
640 // Read the PLT entries from the base file and pass each to the target.
641 for (unsigned int i
= 0; i
< plt_count
; ++i
)
643 unsigned int plt_desc
= got_plt_reader
.get_plt_desc(i
);
644 // FIXME: This should really be a fatal error (corrupt input).
645 gold_assert(plt_desc
>= first_global
&& plt_desc
< symtab_count
);
646 Symbol
* sym
= this->global_symbol(plt_desc
- first_global
);
647 gold_debug(DEBUG_INCREMENTAL
,
650 target
->register_global_plt_entry(i
, sym
);
654 // Emit COPY relocations from the existing output file.
656 template<int size
, bool big_endian
>
658 Sized_incremental_binary
<size
, big_endian
>::do_emit_copy_relocs(
659 Symbol_table
* symtab
)
661 Sized_target
<size
, big_endian
>* target
=
662 parameters
->sized_target
<size
, big_endian
>();
664 for (typename
Copy_relocs::iterator p
= this->copy_relocs_
.begin();
665 p
!= this->copy_relocs_
.end();
668 if (!(*p
).symbol
->is_copied_from_dynobj())
669 target
->emit_copy_reloc(symtab
, (*p
).symbol
, (*p
).output_section
,
674 // Apply incremental relocations for symbols whose values have changed.
676 template<int size
, bool big_endian
>
678 Sized_incremental_binary
<size
, big_endian
>::do_apply_incremental_relocs(
679 const Symbol_table
* symtab
,
683 typedef typename
elfcpp::Elf_types
<size
>::Elf_Addr Address
;
684 typedef typename
elfcpp::Elf_types
<size
>::Elf_Swxword Addend
;
685 Incremental_symtab_reader
<big_endian
> isymtab(this->symtab_reader());
686 Incremental_relocs_reader
<size
, big_endian
> irelocs(this->relocs_reader());
687 unsigned int nglobals
= isymtab
.symbol_count();
688 const unsigned int incr_reloc_size
= irelocs
.reloc_size
;
690 Relocate_info
<size
, big_endian
> relinfo
;
691 relinfo
.symtab
= symtab
;
692 relinfo
.layout
= layout
;
693 relinfo
.object
= NULL
;
694 relinfo
.reloc_shndx
= 0;
695 relinfo
.reloc_shdr
= NULL
;
696 relinfo
.data_shndx
= 0;
697 relinfo
.data_shdr
= NULL
;
699 Sized_target
<size
, big_endian
>* target
=
700 parameters
->sized_target
<size
, big_endian
>();
702 for (unsigned int i
= 0; i
< nglobals
; i
++)
704 const Symbol
* gsym
= this->global_symbol(i
);
706 // If the symbol is not referenced from any unchanged input files,
707 // we do not need to reapply any of its relocations.
711 // If the symbol is defined in an unchanged file, we do not need to
712 // reapply any of its relocations.
713 if (gsym
->source() == Symbol::FROM_OBJECT
714 && gsym
->object()->is_incremental())
717 gold_debug(DEBUG_INCREMENTAL
,
718 "Applying incremental relocations for global symbol %s [%d]",
721 // Follow the linked list of input symbol table entries for this symbol.
722 // We don't bother to figure out whether the symbol table entry belongs
723 // to a changed or unchanged file because it's easier just to apply all
724 // the relocations -- although we might scribble over an area that has
725 // been reallocated, we do this before copying any new data into the
727 unsigned int offset
= isymtab
.get_list_head(i
);
730 Incremental_global_symbol_reader
<big_endian
> sym_info
=
731 this->inputs_reader().global_symbol_reader_at_offset(offset
);
732 unsigned int r_base
= sym_info
.reloc_offset();
733 unsigned int r_count
= sym_info
.reloc_count();
735 // Apply each relocation for this symbol table entry.
736 for (unsigned int j
= 0; j
< r_count
;
737 ++j
, r_base
+= incr_reloc_size
)
739 unsigned int r_type
= irelocs
.get_r_type(r_base
);
740 unsigned int r_shndx
= irelocs
.get_r_shndx(r_base
);
741 Address r_offset
= irelocs
.get_r_offset(r_base
);
742 Addend r_addend
= irelocs
.get_r_addend(r_base
);
743 Output_section
* os
= this->output_section(r_shndx
);
744 Address address
= os
->address();
745 off_t section_offset
= os
->offset();
746 size_t view_size
= os
->data_size();
747 unsigned char* const view
= of
->get_output_view(section_offset
,
750 gold_debug(DEBUG_INCREMENTAL
,
751 " %08lx: %s + %d: type %d addend %ld",
752 (long)(section_offset
+ r_offset
),
758 target
->apply_relocation(&relinfo
, r_offset
, r_type
, r_addend
,
759 gsym
, view
, address
, view_size
);
761 // FIXME: Do something more efficient if write_output_view
762 // ever becomes more than a no-op.
763 of
->write_output_view(section_offset
, view_size
, view
);
765 offset
= sym_info
.next_offset();
770 // Get a view of the main symbol table and the symbol string table.
772 template<int size
, bool big_endian
>
774 Sized_incremental_binary
<size
, big_endian
>::get_symtab_view(
777 elfcpp::Elf_strtab
* strtab
)
779 *symtab_view
= this->view(this->main_symtab_loc_
);
780 *nsyms
= this->main_symtab_loc_
.data_size
/ elfcpp::Elf_sizes
<size
>::sym_size
;
782 View
strtab_view(this->view(this->main_strtab_loc_
));
783 *strtab
= elfcpp::Elf_strtab(strtab_view
.data(),
784 this->main_strtab_loc_
.data_size
);
790 // Create a Sized_incremental_binary object of the specified size and
791 // endianness. Fails if the target architecture is not supported.
793 template<int size
, bool big_endian
>
795 make_sized_incremental_binary(Output_file
* file
,
796 const elfcpp::Ehdr
<size
, big_endian
>& ehdr
)
798 Target
* target
= select_target(ehdr
.get_e_machine(), size
, big_endian
,
799 ehdr
.get_e_ident()[elfcpp::EI_OSABI
],
800 ehdr
.get_e_ident()[elfcpp::EI_ABIVERSION
]);
803 explain_no_incremental(_("unsupported ELF machine number %d"),
804 ehdr
.get_e_machine());
808 if (!parameters
->target_valid())
809 set_parameters_target(target
);
810 else if (target
!= ¶meters
->target())
811 gold_error(_("%s: incompatible target"), file
->filename());
813 return new Sized_incremental_binary
<size
, big_endian
>(file
, ehdr
, target
);
816 } // End of anonymous namespace.
818 // Create an Incremental_binary object for FILE. Returns NULL is this is not
819 // possible, e.g. FILE is not an ELF file or has an unsupported target. FILE
823 open_incremental_binary(Output_file
* file
)
825 off_t filesize
= file
->filesize();
826 int want
= elfcpp::Elf_recognizer::max_header_size
;
830 const unsigned char* p
= file
->get_input_view(0, want
);
831 if (!elfcpp::Elf_recognizer::is_elf_file(p
, want
))
833 explain_no_incremental(_("output is not an ELF file."));
838 bool big_endian
= false;
840 if (!elfcpp::Elf_recognizer::is_valid_header(p
, want
, &size
, &big_endian
,
843 explain_no_incremental(error
.c_str());
847 Incremental_binary
* result
= NULL
;
852 #ifdef HAVE_TARGET_32_BIG
853 result
= make_sized_incremental_binary
<32, true>(
854 file
, elfcpp::Ehdr
<32, true>(p
));
856 explain_no_incremental(_("unsupported file: 32-bit, big-endian"));
861 #ifdef HAVE_TARGET_32_LITTLE
862 result
= make_sized_incremental_binary
<32, false>(
863 file
, elfcpp::Ehdr
<32, false>(p
));
865 explain_no_incremental(_("unsupported file: 32-bit, little-endian"));
873 #ifdef HAVE_TARGET_64_BIG
874 result
= make_sized_incremental_binary
<64, true>(
875 file
, elfcpp::Ehdr
<64, true>(p
));
877 explain_no_incremental(_("unsupported file: 64-bit, big-endian"));
882 #ifdef HAVE_TARGET_64_LITTLE
883 result
= make_sized_incremental_binary
<64, false>(
884 file
, elfcpp::Ehdr
<64, false>(p
));
886 explain_no_incremental(_("unsupported file: 64-bit, little-endian"));
896 // Class Incremental_inputs.
898 // Add the command line to the string table, setting
899 // command_line_key_. In incremental builds, the command line is
900 // stored in .gnu_incremental_inputs so that the next linker run can
901 // check if the command line options didn't change.
904 Incremental_inputs::report_command_line(int argc
, const char* const* argv
)
906 // Always store 'gold' as argv[0] to avoid a full relink if the user used a
907 // different path to the linker.
908 std::string
args("gold");
909 // Copied from collect_argv in main.cc.
910 for (int i
= 1; i
< argc
; ++i
)
912 // Adding/removing these options should not result in a full relink.
913 if (strcmp(argv
[i
], "--incremental") == 0
914 || strcmp(argv
[i
], "--incremental-full") == 0
915 || strcmp(argv
[i
], "--incremental-update") == 0
916 || strcmp(argv
[i
], "--incremental-changed") == 0
917 || strcmp(argv
[i
], "--incremental-unchanged") == 0
918 || strcmp(argv
[i
], "--incremental-unknown") == 0
919 || is_prefix_of("--incremental-base=", argv
[i
])
920 || is_prefix_of("--debug=", argv
[i
]))
922 if (strcmp(argv
[i
], "--incremental-base") == 0
923 || strcmp(argv
[i
], "--debug") == 0)
925 // When these options are used without the '=', skip the
926 // following parameter as well.
932 // Now append argv[i], but with all single-quotes escaped
933 const char* argpos
= argv
[i
];
936 const int len
= strcspn(argpos
, "'");
937 args
.append(argpos
, len
);
938 if (argpos
[len
] == '\0')
940 args
.append("'\"'\"'");
946 this->command_line_
= args
;
947 this->strtab_
->add(this->command_line_
.c_str(), false,
948 &this->command_line_key_
);
951 // Record the input archive file ARCHIVE. This is called by the
952 // Add_archive_symbols task before determining which archive members
953 // to include. We create the Incremental_archive_entry here and
954 // attach it to the Archive, but we do not add it to the list of
955 // input objects until report_archive_end is called.
958 Incremental_inputs::report_archive_begin(Library_base
* arch
,
959 unsigned int arg_serial
,
960 Script_info
* script_info
)
962 Stringpool::Key filename_key
;
963 Timespec mtime
= arch
->get_mtime();
965 // For a file loaded from a script, don't record its argument serial number.
966 if (script_info
!= NULL
)
969 this->strtab_
->add(arch
->filename().c_str(), false, &filename_key
);
970 Incremental_archive_entry
* entry
=
971 new Incremental_archive_entry(filename_key
, arg_serial
, mtime
);
972 arch
->set_incremental_info(entry
);
974 if (script_info
!= NULL
)
976 Incremental_script_entry
* script_entry
= script_info
->incremental_info();
977 gold_assert(script_entry
!= NULL
);
978 script_entry
->add_object(entry
);
982 // Visitor class for processing the unused global symbols in a library.
983 // An instance of this class is passed to the library's
984 // for_all_unused_symbols() iterator, which will call the visit()
985 // function for each global symbol defined in each unused library
986 // member. We add those symbol names to the incremental info for the
989 class Unused_symbol_visitor
: public Library_base::Symbol_visitor_base
992 Unused_symbol_visitor(Incremental_archive_entry
* entry
, Stringpool
* strtab
)
993 : entry_(entry
), strtab_(strtab
)
997 visit(const char* sym
)
999 Stringpool::Key symbol_key
;
1000 this->strtab_
->add(sym
, true, &symbol_key
);
1001 this->entry_
->add_unused_global_symbol(symbol_key
);
1005 Incremental_archive_entry
* entry_
;
1006 Stringpool
* strtab_
;
1009 // Finish recording the input archive file ARCHIVE. This is called by the
1010 // Add_archive_symbols task after determining which archive members
1014 Incremental_inputs::report_archive_end(Library_base
* arch
)
1016 Incremental_archive_entry
* entry
= arch
->incremental_info();
1018 gold_assert(entry
!= NULL
);
1019 this->inputs_
.push_back(entry
);
1021 // Collect unused global symbols.
1022 Unused_symbol_visitor
v(entry
, this->strtab_
);
1023 arch
->for_all_unused_symbols(&v
);
1026 // Record the input object file OBJ. If ARCH is not NULL, attach
1027 // the object file to the archive. This is called by the
1028 // Add_symbols task after finding out the type of the file.
1031 Incremental_inputs::report_object(Object
* obj
, unsigned int arg_serial
,
1032 Library_base
* arch
, Script_info
* script_info
)
1034 Stringpool::Key filename_key
;
1035 Timespec mtime
= obj
->get_mtime();
1037 // For a file loaded from a script, don't record its argument serial number.
1038 if (script_info
!= NULL
)
1041 this->strtab_
->add(obj
->name().c_str(), false, &filename_key
);
1043 Incremental_input_entry
* input_entry
;
1045 this->current_object_
= obj
;
1047 if (!obj
->is_dynamic())
1049 this->current_object_entry_
=
1050 new Incremental_object_entry(filename_key
, obj
, arg_serial
, mtime
);
1051 input_entry
= this->current_object_entry_
;
1054 Incremental_archive_entry
* arch_entry
= arch
->incremental_info();
1055 gold_assert(arch_entry
!= NULL
);
1056 arch_entry
->add_object(this->current_object_entry_
);
1061 this->current_object_entry_
= NULL
;
1062 Stringpool::Key soname_key
;
1063 Dynobj
* dynobj
= obj
->dynobj();
1064 gold_assert(dynobj
!= NULL
);
1065 this->strtab_
->add(dynobj
->soname(), false, &soname_key
);
1066 input_entry
= new Incremental_dynobj_entry(filename_key
, soname_key
, obj
,
1070 if (obj
->is_in_system_directory())
1071 input_entry
->set_is_in_system_directory();
1073 if (obj
->as_needed())
1074 input_entry
->set_as_needed();
1076 this->inputs_
.push_back(input_entry
);
1078 if (script_info
!= NULL
)
1080 Incremental_script_entry
* script_entry
= script_info
->incremental_info();
1081 gold_assert(script_entry
!= NULL
);
1082 script_entry
->add_object(input_entry
);
1086 // Record an input section SHNDX from object file OBJ.
1089 Incremental_inputs::report_input_section(Object
* obj
, unsigned int shndx
,
1090 const char* name
, off_t sh_size
)
1092 Stringpool::Key key
= 0;
1095 this->strtab_
->add(name
, true, &key
);
1097 gold_assert(obj
== this->current_object_
);
1098 gold_assert(this->current_object_entry_
!= NULL
);
1099 this->current_object_entry_
->add_input_section(shndx
, key
, sh_size
);
1102 // Record a kept COMDAT group belonging to object file OBJ.
1105 Incremental_inputs::report_comdat_group(Object
* obj
, const char* name
)
1107 Stringpool::Key key
= 0;
1110 this->strtab_
->add(name
, true, &key
);
1111 gold_assert(obj
== this->current_object_
);
1112 gold_assert(this->current_object_entry_
!= NULL
);
1113 this->current_object_entry_
->add_comdat_group(key
);
1116 // Record that the input argument INPUT is a script SCRIPT. This is
1117 // called by read_script after parsing the script and reading the list
1118 // of inputs added by this script.
1121 Incremental_inputs::report_script(Script_info
* script
,
1122 unsigned int arg_serial
,
1125 Stringpool::Key filename_key
;
1127 this->strtab_
->add(script
->filename().c_str(), false, &filename_key
);
1128 Incremental_script_entry
* entry
=
1129 new Incremental_script_entry(filename_key
, arg_serial
, script
, mtime
);
1130 this->inputs_
.push_back(entry
);
1131 script
->set_incremental_info(entry
);
1134 // Finalize the incremental link information. Called from
1135 // Layout::finalize.
1138 Incremental_inputs::finalize()
1140 // Finalize the string table.
1141 this->strtab_
->set_string_offsets();
1144 // Create the .gnu_incremental_inputs, _symtab, and _relocs input sections.
1147 Incremental_inputs::create_data_sections(Symbol_table
* symtab
)
1149 switch (parameters
->size_and_endianness())
1151 #ifdef HAVE_TARGET_32_LITTLE
1152 case Parameters::TARGET_32_LITTLE
:
1153 this->inputs_section_
=
1154 new Output_section_incremental_inputs
<32, false>(this, symtab
);
1157 #ifdef HAVE_TARGET_32_BIG
1158 case Parameters::TARGET_32_BIG
:
1159 this->inputs_section_
=
1160 new Output_section_incremental_inputs
<32, true>(this, symtab
);
1163 #ifdef HAVE_TARGET_64_LITTLE
1164 case Parameters::TARGET_64_LITTLE
:
1165 this->inputs_section_
=
1166 new Output_section_incremental_inputs
<64, false>(this, symtab
);
1169 #ifdef HAVE_TARGET_64_BIG
1170 case Parameters::TARGET_64_BIG
:
1171 this->inputs_section_
=
1172 new Output_section_incremental_inputs
<64, true>(this, symtab
);
1178 this->symtab_section_
= new Output_data_space(4, "** incremental_symtab");
1179 this->relocs_section_
= new Output_data_space(4, "** incremental_relocs");
1180 this->got_plt_section_
= new Output_data_space(4, "** incremental_got_plt");
1183 // Return the sh_entsize value for the .gnu_incremental_relocs section.
1185 Incremental_inputs::relocs_entsize() const
1187 return 8 + 2 * parameters
->target().get_size() / 8;
1190 // Class Output_section_incremental_inputs.
1192 // Finalize the offsets for each input section and supplemental info block,
1193 // and set the final data size of the incremental output sections.
1195 template<int size
, bool big_endian
>
1197 Output_section_incremental_inputs
<size
, big_endian
>::set_final_data_size()
1199 const Incremental_inputs
* inputs
= this->inputs_
;
1200 const unsigned int sizeof_addr
= size
/ 8;
1201 const unsigned int rel_size
= 8 + 2 * sizeof_addr
;
1203 // Offset of each input entry.
1204 unsigned int input_offset
= this->header_size
;
1206 // Offset of each supplemental info block.
1207 unsigned int file_index
= 0;
1208 unsigned int info_offset
= this->header_size
;
1209 info_offset
+= this->input_entry_size
* inputs
->input_file_count();
1211 // Count each input file and its supplemental information block.
1212 for (Incremental_inputs::Input_list::const_iterator p
=
1213 inputs
->input_files().begin();
1214 p
!= inputs
->input_files().end();
1217 // Set the index and offset of the input file entry.
1218 (*p
)->set_offset(file_index
, input_offset
);
1220 input_offset
+= this->input_entry_size
;
1222 // Set the offset of the supplemental info block.
1223 switch ((*p
)->type())
1225 case INCREMENTAL_INPUT_SCRIPT
:
1227 Incremental_script_entry
*entry
= (*p
)->script_entry();
1228 gold_assert(entry
!= NULL
);
1229 (*p
)->set_info_offset(info_offset
);
1233 info_offset
+= (entry
->get_object_count() * 4);
1236 case INCREMENTAL_INPUT_OBJECT
:
1237 case INCREMENTAL_INPUT_ARCHIVE_MEMBER
:
1239 Incremental_object_entry
* entry
= (*p
)->object_entry();
1240 gold_assert(entry
!= NULL
);
1241 (*p
)->set_info_offset(info_offset
);
1242 // Input section count, global symbol count, local symbol offset,
1243 // local symbol count, first dynamic reloc, dynamic reloc count,
1244 // comdat group count.
1246 // Each input section.
1247 info_offset
+= (entry
->get_input_section_count()
1248 * (8 + 2 * sizeof_addr
));
1249 // Each global symbol.
1250 const Object::Symbols
* syms
= entry
->object()->get_global_symbols();
1251 info_offset
+= syms
->size() * 20;
1252 // Each comdat group.
1253 info_offset
+= entry
->get_comdat_group_count() * 4;
1256 case INCREMENTAL_INPUT_SHARED_LIBRARY
:
1258 Incremental_dynobj_entry
* entry
= (*p
)->dynobj_entry();
1259 gold_assert(entry
!= NULL
);
1260 (*p
)->set_info_offset(info_offset
);
1261 // Global symbol count, soname index.
1263 // Each global symbol.
1264 const Object::Symbols
* syms
= entry
->object()->get_global_symbols();
1265 gold_assert(syms
!= NULL
);
1266 unsigned int nsyms
= syms
->size();
1267 unsigned int nsyms_out
= 0;
1268 for (unsigned int i
= 0; i
< nsyms
; ++i
)
1270 const Symbol
* sym
= (*syms
)[i
];
1273 if (sym
->is_forwarder())
1274 sym
= this->symtab_
->resolve_forwards(sym
);
1275 if (sym
->symtab_index() != -1U)
1278 info_offset
+= nsyms_out
* 4;
1281 case INCREMENTAL_INPUT_ARCHIVE
:
1283 Incremental_archive_entry
* entry
= (*p
)->archive_entry();
1284 gold_assert(entry
!= NULL
);
1285 (*p
)->set_info_offset(info_offset
);
1286 // Member count + unused global symbol count.
1289 info_offset
+= (entry
->get_member_count() * 4);
1290 // Each global symbol.
1291 info_offset
+= (entry
->get_unused_global_symbol_count() * 4);
1299 this->set_data_size(info_offset
);
1301 // Set the size of the .gnu_incremental_symtab section.
1302 inputs
->symtab_section()->set_current_data_size(this->symtab_
->output_count()
1303 * sizeof(unsigned int));
1305 // Set the size of the .gnu_incremental_relocs section.
1306 inputs
->relocs_section()->set_current_data_size(inputs
->get_reloc_count()
1309 // Set the size of the .gnu_incremental_got_plt section.
1310 Sized_target
<size
, big_endian
>* target
=
1311 parameters
->sized_target
<size
, big_endian
>();
1312 unsigned int got_count
= target
->got_entry_count();
1313 unsigned int plt_count
= target
->plt_entry_count();
1314 unsigned int got_plt_size
= 8; // GOT entry count, PLT entry count.
1315 got_plt_size
= (got_plt_size
+ got_count
+ 3) & ~3; // GOT type array.
1316 got_plt_size
+= got_count
* 8 + plt_count
* 4; // GOT array, PLT array.
1317 inputs
->got_plt_section()->set_current_data_size(got_plt_size
);
1320 // Write the contents of the .gnu_incremental_inputs and
1321 // .gnu_incremental_symtab sections.
1323 template<int size
, bool big_endian
>
1325 Output_section_incremental_inputs
<size
, big_endian
>::do_write(Output_file
* of
)
1327 const Incremental_inputs
* inputs
= this->inputs_
;
1328 Stringpool
* strtab
= inputs
->get_stringpool();
1330 // Get a view into the .gnu_incremental_inputs section.
1331 const off_t off
= this->offset();
1332 const off_t oview_size
= this->data_size();
1333 unsigned char* const oview
= of
->get_output_view(off
, oview_size
);
1334 unsigned char* pov
= oview
;
1336 // Get a view into the .gnu_incremental_symtab section.
1337 const off_t symtab_off
= inputs
->symtab_section()->offset();
1338 const off_t symtab_size
= inputs
->symtab_section()->data_size();
1339 unsigned char* const symtab_view
= of
->get_output_view(symtab_off
,
1342 // Allocate an array of linked list heads for the .gnu_incremental_symtab
1343 // section. Each element corresponds to a global symbol in the output
1344 // symbol table, and points to the head of the linked list that threads
1345 // through the object file input entries. The value of each element
1346 // is the section-relative offset to a global symbol entry in a
1347 // supplemental information block.
1348 unsigned int global_sym_count
= this->symtab_
->output_count();
1349 unsigned int* global_syms
= new unsigned int[global_sym_count
];
1350 memset(global_syms
, 0, global_sym_count
* sizeof(unsigned int));
1352 // Write the section header.
1353 Stringpool::Key command_line_key
= inputs
->command_line_key();
1354 pov
= this->write_header(pov
, inputs
->input_file_count(),
1355 strtab
->get_offset_from_key(command_line_key
));
1357 // Write the list of input files.
1358 pov
= this->write_input_files(oview
, pov
, strtab
);
1360 // Write the supplemental information blocks for each input file.
1361 pov
= this->write_info_blocks(oview
, pov
, strtab
, global_syms
,
1364 gold_assert(pov
- oview
== oview_size
);
1366 // Write the .gnu_incremental_symtab section.
1367 gold_assert(global_sym_count
* 4 == symtab_size
);
1368 this->write_symtab(symtab_view
, global_syms
, global_sym_count
);
1370 delete[] global_syms
;
1372 // Write the .gnu_incremental_got_plt section.
1373 const off_t got_plt_off
= inputs
->got_plt_section()->offset();
1374 const off_t got_plt_size
= inputs
->got_plt_section()->data_size();
1375 unsigned char* const got_plt_view
= of
->get_output_view(got_plt_off
,
1377 this->write_got_plt(got_plt_view
, got_plt_size
);
1379 of
->write_output_view(off
, oview_size
, oview
);
1380 of
->write_output_view(symtab_off
, symtab_size
, symtab_view
);
1381 of
->write_output_view(got_plt_off
, got_plt_size
, got_plt_view
);
1384 // Write the section header: version, input file count, offset of command line
1385 // in the string table, and 4 bytes of padding.
1387 template<int size
, bool big_endian
>
1389 Output_section_incremental_inputs
<size
, big_endian
>::write_header(
1391 unsigned int input_file_count
,
1392 section_offset_type command_line_offset
)
1394 Swap32::writeval(pov
, INCREMENTAL_LINK_VERSION
);
1395 Swap32::writeval(pov
+ 4, input_file_count
);
1396 Swap32::writeval(pov
+ 8, command_line_offset
);
1397 Swap32::writeval(pov
+ 12, 0);
1398 return pov
+ this->header_size
;
1401 // Write the input file entries.
1403 template<int size
, bool big_endian
>
1405 Output_section_incremental_inputs
<size
, big_endian
>::write_input_files(
1406 unsigned char* oview
,
1410 const Incremental_inputs
* inputs
= this->inputs_
;
1412 for (Incremental_inputs::Input_list::const_iterator p
=
1413 inputs
->input_files().begin();
1414 p
!= inputs
->input_files().end();
1417 gold_assert(static_cast<unsigned int>(pov
- oview
) == (*p
)->get_offset());
1418 section_offset_type filename_offset
=
1419 strtab
->get_offset_from_key((*p
)->get_filename_key());
1420 const Timespec
& mtime
= (*p
)->get_mtime();
1421 unsigned int flags
= (*p
)->type();
1422 if ((*p
)->is_in_system_directory())
1423 flags
|= INCREMENTAL_INPUT_IN_SYSTEM_DIR
;
1424 if ((*p
)->as_needed())
1425 flags
|= INCREMENTAL_INPUT_AS_NEEDED
;
1426 Swap32::writeval(pov
, filename_offset
);
1427 Swap32::writeval(pov
+ 4, (*p
)->get_info_offset());
1428 Swap64::writeval(pov
+ 8, mtime
.seconds
);
1429 Swap32::writeval(pov
+ 16, mtime
.nanoseconds
);
1430 Swap16::writeval(pov
+ 20, flags
);
1431 Swap16::writeval(pov
+ 22, (*p
)->arg_serial());
1432 pov
+= this->input_entry_size
;
1437 // Write the supplemental information blocks.
1439 template<int size
, bool big_endian
>
1441 Output_section_incremental_inputs
<size
, big_endian
>::write_info_blocks(
1442 unsigned char* oview
,
1445 unsigned int* global_syms
,
1446 unsigned int global_sym_count
)
1448 const Incremental_inputs
* inputs
= this->inputs_
;
1449 unsigned int first_global_index
= this->symtab_
->first_global_index();
1451 for (Incremental_inputs::Input_list::const_iterator p
=
1452 inputs
->input_files().begin();
1453 p
!= inputs
->input_files().end();
1456 switch ((*p
)->type())
1458 case INCREMENTAL_INPUT_SCRIPT
:
1460 gold_assert(static_cast<unsigned int>(pov
- oview
)
1461 == (*p
)->get_info_offset());
1462 Incremental_script_entry
* entry
= (*p
)->script_entry();
1463 gold_assert(entry
!= NULL
);
1465 // Write the object count.
1466 unsigned int nobjects
= entry
->get_object_count();
1467 Swap32::writeval(pov
, nobjects
);
1470 // For each object, write the offset to its input file entry.
1471 for (unsigned int i
= 0; i
< nobjects
; ++i
)
1473 Incremental_input_entry
* obj
= entry
->get_object(i
);
1474 Swap32::writeval(pov
, obj
->get_offset());
1480 case INCREMENTAL_INPUT_OBJECT
:
1481 case INCREMENTAL_INPUT_ARCHIVE_MEMBER
:
1483 gold_assert(static_cast<unsigned int>(pov
- oview
)
1484 == (*p
)->get_info_offset());
1485 Incremental_object_entry
* entry
= (*p
)->object_entry();
1486 gold_assert(entry
!= NULL
);
1487 const Object
* obj
= entry
->object();
1488 const Relobj
* relobj
= static_cast<const Relobj
*>(obj
);
1489 const Object::Symbols
* syms
= obj
->get_global_symbols();
1490 // Write the input section count and global symbol count.
1491 unsigned int nsections
= entry
->get_input_section_count();
1492 unsigned int nsyms
= syms
->size();
1493 off_t locals_offset
= relobj
->local_symbol_offset();
1494 unsigned int nlocals
= relobj
->output_local_symbol_count();
1495 unsigned int first_dynrel
= relobj
->first_dyn_reloc();
1496 unsigned int ndynrel
= relobj
->dyn_reloc_count();
1497 unsigned int ncomdat
= entry
->get_comdat_group_count();
1498 Swap32::writeval(pov
, nsections
);
1499 Swap32::writeval(pov
+ 4, nsyms
);
1500 Swap32::writeval(pov
+ 8, static_cast<unsigned int>(locals_offset
));
1501 Swap32::writeval(pov
+ 12, nlocals
);
1502 Swap32::writeval(pov
+ 16, first_dynrel
);
1503 Swap32::writeval(pov
+ 20, ndynrel
);
1504 Swap32::writeval(pov
+ 24, ncomdat
);
1507 // Build a temporary array to map input section indexes
1508 // from the original object file index to the index in the
1509 // incremental info table.
1510 unsigned int* index_map
= new unsigned int[obj
->shnum()];
1511 memset(index_map
, 0, obj
->shnum() * sizeof(unsigned int));
1513 // For each input section, write the name, output section index,
1514 // offset within output section, and input section size.
1515 for (unsigned int i
= 0; i
< nsections
; i
++)
1517 unsigned int shndx
= entry
->get_input_section_index(i
);
1518 index_map
[shndx
] = i
+ 1;
1519 Stringpool::Key key
= entry
->get_input_section_name_key(i
);
1520 off_t name_offset
= 0;
1522 name_offset
= strtab
->get_offset_from_key(key
);
1524 off_t out_offset
= 0;
1526 Output_section
* os
= obj
->output_section(shndx
);
1529 out_shndx
= os
->out_shndx();
1530 out_offset
= obj
->output_section_offset(shndx
);
1531 sh_size
= entry
->get_input_section_size(i
);
1533 Swap32::writeval(pov
, name_offset
);
1534 Swap32::writeval(pov
+ 4, out_shndx
);
1535 Swap::writeval(pov
+ 8, out_offset
);
1536 Swap::writeval(pov
+ 8 + sizeof_addr
, sh_size
);
1537 pov
+= 8 + 2 * sizeof_addr
;
1540 // For each global symbol, write its associated relocations,
1541 // add it to the linked list of globals, then write the
1542 // supplemental information: global symbol table index,
1543 // input section index, linked list chain pointer, relocation
1544 // count, and offset to the relocations.
1545 for (unsigned int i
= 0; i
< nsyms
; i
++)
1547 const Symbol
* sym
= (*syms
)[i
];
1548 if (sym
->is_forwarder())
1549 sym
= this->symtab_
->resolve_forwards(sym
);
1550 unsigned int shndx
= 0;
1551 if (sym
->source() == Symbol::FROM_OBJECT
1552 && sym
->object() == obj
1553 && sym
->is_defined())
1556 unsigned int orig_shndx
= sym
->shndx(&is_ordinary
);
1558 shndx
= index_map
[orig_shndx
];
1560 unsigned int symtab_index
= sym
->symtab_index();
1561 unsigned int chain
= 0;
1562 unsigned int first_reloc
= 0;
1563 unsigned int nrelocs
= obj
->get_incremental_reloc_count(i
);
1566 gold_assert(symtab_index
!= -1U
1567 && (symtab_index
- first_global_index
1568 < global_sym_count
));
1569 first_reloc
= obj
->get_incremental_reloc_base(i
);
1570 chain
= global_syms
[symtab_index
- first_global_index
];
1571 global_syms
[symtab_index
- first_global_index
] =
1574 Swap32::writeval(pov
, symtab_index
);
1575 Swap32::writeval(pov
+ 4, shndx
);
1576 Swap32::writeval(pov
+ 8, chain
);
1577 Swap32::writeval(pov
+ 12, nrelocs
);
1578 Swap32::writeval(pov
+ 16, first_reloc
* 3 * sizeof_addr
);
1582 // For each kept COMDAT group, write the group signature.
1583 for (unsigned int i
= 0; i
< ncomdat
; i
++)
1585 Stringpool::Key key
= entry
->get_comdat_signature_key(i
);
1586 off_t name_offset
= 0;
1588 name_offset
= strtab
->get_offset_from_key(key
);
1589 Swap32::writeval(pov
, name_offset
);
1597 case INCREMENTAL_INPUT_SHARED_LIBRARY
:
1599 gold_assert(static_cast<unsigned int>(pov
- oview
)
1600 == (*p
)->get_info_offset());
1601 Incremental_dynobj_entry
* entry
= (*p
)->dynobj_entry();
1602 gold_assert(entry
!= NULL
);
1603 Object
* obj
= entry
->object();
1604 Dynobj
* dynobj
= obj
->dynobj();
1605 gold_assert(dynobj
!= NULL
);
1606 const Object::Symbols
* syms
= obj
->get_global_symbols();
1608 // Write the soname string table index.
1609 section_offset_type soname_offset
=
1610 strtab
->get_offset_from_key(entry
->get_soname_key());
1611 Swap32::writeval(pov
, soname_offset
);
1614 // Skip the global symbol count for now.
1615 unsigned char* orig_pov
= pov
;
1618 // For each global symbol, write the global symbol table index.
1619 unsigned int nsyms
= syms
->size();
1620 unsigned int nsyms_out
= 0;
1621 for (unsigned int i
= 0; i
< nsyms
; i
++)
1623 const Symbol
* sym
= (*syms
)[i
];
1626 if (sym
->is_forwarder())
1627 sym
= this->symtab_
->resolve_forwards(sym
);
1628 if (sym
->symtab_index() == -1U)
1630 unsigned int flags
= 0;
1631 if (sym
->source() == Symbol::FROM_OBJECT
1632 && sym
->object() == obj
1633 && sym
->is_defined())
1634 flags
= INCREMENTAL_SHLIB_SYM_DEF
;
1635 else if (sym
->is_copied_from_dynobj()
1636 && this->symtab_
->get_copy_source(sym
) == dynobj
)
1637 flags
= INCREMENTAL_SHLIB_SYM_COPY
;
1638 flags
<<= INCREMENTAL_SHLIB_SYM_FLAGS_SHIFT
;
1639 Swap32::writeval(pov
, sym
->symtab_index() | flags
);
1644 // Now write the global symbol count.
1645 Swap32::writeval(orig_pov
, nsyms_out
);
1649 case INCREMENTAL_INPUT_ARCHIVE
:
1651 gold_assert(static_cast<unsigned int>(pov
- oview
)
1652 == (*p
)->get_info_offset());
1653 Incremental_archive_entry
* entry
= (*p
)->archive_entry();
1654 gold_assert(entry
!= NULL
);
1656 // Write the member count and unused global symbol count.
1657 unsigned int nmembers
= entry
->get_member_count();
1658 unsigned int nsyms
= entry
->get_unused_global_symbol_count();
1659 Swap32::writeval(pov
, nmembers
);
1660 Swap32::writeval(pov
+ 4, nsyms
);
1663 // For each member, write the offset to its input file entry.
1664 for (unsigned int i
= 0; i
< nmembers
; ++i
)
1666 Incremental_object_entry
* member
= entry
->get_member(i
);
1667 Swap32::writeval(pov
, member
->get_offset());
1671 // For each global symbol, write the name offset.
1672 for (unsigned int i
= 0; i
< nsyms
; ++i
)
1674 Stringpool::Key key
= entry
->get_unused_global_symbol(i
);
1675 Swap32::writeval(pov
, strtab
->get_offset_from_key(key
));
1688 // Write the contents of the .gnu_incremental_symtab section.
1690 template<int size
, bool big_endian
>
1692 Output_section_incremental_inputs
<size
, big_endian
>::write_symtab(
1694 unsigned int* global_syms
,
1695 unsigned int global_sym_count
)
1697 for (unsigned int i
= 0; i
< global_sym_count
; ++i
)
1699 Swap32::writeval(pov
, global_syms
[i
]);
1704 // This struct holds the view information needed to write the
1705 // .gnu_incremental_got_plt section.
1707 struct Got_plt_view_info
1709 // Start of the GOT type array in the output view.
1710 unsigned char* got_type_p
;
1711 // Start of the GOT descriptor array in the output view.
1712 unsigned char* got_desc_p
;
1713 // Start of the PLT descriptor array in the output view.
1714 unsigned char* plt_desc_p
;
1715 // Number of GOT entries.
1716 unsigned int got_count
;
1717 // Number of PLT entries.
1718 unsigned int plt_count
;
1719 // Offset of the first non-reserved PLT entry (this is a target-dependent value).
1720 unsigned int first_plt_entry_offset
;
1721 // Size of a PLT entry (this is a target-dependent value).
1722 unsigned int plt_entry_size
;
1723 // Symbol index to write in the GOT descriptor array. For global symbols,
1724 // this is the global symbol table index; for local symbols, it is the
1725 // local symbol table index.
1726 unsigned int sym_index
;
1727 // Input file index to write in the GOT descriptor array. For global
1728 // symbols, this is 0; for local symbols, it is the index of the input
1729 // file entry in the .gnu_incremental_inputs section.
1730 unsigned int input_index
;
1733 // Functor class for processing a GOT offset list for local symbols.
1734 // Writes the GOT type and symbol index into the GOT type and descriptor
1735 // arrays in the output section.
1737 template<int size
, bool big_endian
>
1738 class Local_got_offset_visitor
: public Got_offset_list::Visitor
1741 Local_got_offset_visitor(struct Got_plt_view_info
& info
)
1746 visit(unsigned int got_type
, unsigned int got_offset
)
1748 unsigned int got_index
= got_offset
/ this->got_entry_size_
;
1749 gold_assert(got_index
< this->info_
.got_count
);
1750 // We can only handle GOT entry types in the range 0..0x7e
1751 // because we use a byte array to store them, and we use the
1752 // high bit to flag a local symbol.
1753 gold_assert(got_type
< 0x7f);
1754 this->info_
.got_type_p
[got_index
] = got_type
| 0x80;
1755 unsigned char* pov
= this->info_
.got_desc_p
+ got_index
* 8;
1756 elfcpp::Swap
<32, big_endian
>::writeval(pov
, this->info_
.sym_index
);
1757 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, this->info_
.input_index
);
1761 static const unsigned int got_entry_size_
= size
/ 8;
1762 struct Got_plt_view_info
& info_
;
1765 // Functor class for processing a GOT offset list. Writes the GOT type
1766 // and symbol index into the GOT type and descriptor arrays in the output
1769 template<int size
, bool big_endian
>
1770 class Global_got_offset_visitor
: public Got_offset_list::Visitor
1773 Global_got_offset_visitor(struct Got_plt_view_info
& info
)
1778 visit(unsigned int got_type
, unsigned int got_offset
)
1780 unsigned int got_index
= got_offset
/ this->got_entry_size_
;
1781 gold_assert(got_index
< this->info_
.got_count
);
1782 // We can only handle GOT entry types in the range 0..0x7e
1783 // because we use a byte array to store them, and we use the
1784 // high bit to flag a local symbol.
1785 gold_assert(got_type
< 0x7f);
1786 this->info_
.got_type_p
[got_index
] = got_type
;
1787 unsigned char* pov
= this->info_
.got_desc_p
+ got_index
* 8;
1788 elfcpp::Swap
<32, big_endian
>::writeval(pov
, this->info_
.sym_index
);
1789 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, 0);
1793 static const unsigned int got_entry_size_
= size
/ 8;
1794 struct Got_plt_view_info
& info_
;
1797 // Functor class for processing the global symbol table. Processes the
1798 // GOT offset list for the symbol, and writes the symbol table index
1799 // into the PLT descriptor array in the output section.
1801 template<int size
, bool big_endian
>
1802 class Global_symbol_visitor_got_plt
1805 Global_symbol_visitor_got_plt(struct Got_plt_view_info
& info
)
1810 operator()(const Sized_symbol
<size
>* sym
)
1812 typedef Global_got_offset_visitor
<size
, big_endian
> Got_visitor
;
1813 const Got_offset_list
* got_offsets
= sym
->got_offset_list();
1814 if (got_offsets
!= NULL
)
1816 this->info_
.sym_index
= sym
->symtab_index();
1817 this->info_
.input_index
= 0;
1818 Got_visitor
v(this->info_
);
1819 got_offsets
->for_all_got_offsets(&v
);
1821 if (sym
->has_plt_offset())
1823 unsigned int plt_index
=
1824 ((sym
->plt_offset() - this->info_
.first_plt_entry_offset
)
1825 / this->info_
.plt_entry_size
);
1826 gold_assert(plt_index
< this->info_
.plt_count
);
1827 unsigned char* pov
= this->info_
.plt_desc_p
+ plt_index
* 4;
1828 elfcpp::Swap
<32, big_endian
>::writeval(pov
, sym
->symtab_index());
1833 struct Got_plt_view_info
& info_
;
1836 // Write the contents of the .gnu_incremental_got_plt section.
1838 template<int size
, bool big_endian
>
1840 Output_section_incremental_inputs
<size
, big_endian
>::write_got_plt(
1844 Sized_target
<size
, big_endian
>* target
=
1845 parameters
->sized_target
<size
, big_endian
>();
1847 // Set up the view information for the functors.
1848 struct Got_plt_view_info view_info
;
1849 view_info
.got_count
= target
->got_entry_count();
1850 view_info
.plt_count
= target
->plt_entry_count();
1851 view_info
.first_plt_entry_offset
= target
->first_plt_entry_offset();
1852 view_info
.plt_entry_size
= target
->plt_entry_size();
1853 view_info
.got_type_p
= pov
+ 8;
1854 view_info
.got_desc_p
= (view_info
.got_type_p
1855 + ((view_info
.got_count
+ 3) & ~3));
1856 view_info
.plt_desc_p
= view_info
.got_desc_p
+ view_info
.got_count
* 8;
1858 gold_assert(pov
+ view_size
==
1859 view_info
.plt_desc_p
+ view_info
.plt_count
* 4);
1861 // Write the section header.
1862 Swap32::writeval(pov
, view_info
.got_count
);
1863 Swap32::writeval(pov
+ 4, view_info
.plt_count
);
1865 // Initialize the GOT type array to 0xff (reserved).
1866 memset(view_info
.got_type_p
, 0xff, view_info
.got_count
);
1868 // Write the incremental GOT descriptors for local symbols.
1869 typedef Local_got_offset_visitor
<size
, big_endian
> Got_visitor
;
1870 for (Incremental_inputs::Input_list::const_iterator p
=
1871 this->inputs_
->input_files().begin();
1872 p
!= this->inputs_
->input_files().end();
1875 if ((*p
)->type() != INCREMENTAL_INPUT_OBJECT
1876 && (*p
)->type() != INCREMENTAL_INPUT_ARCHIVE_MEMBER
)
1878 Incremental_object_entry
* entry
= (*p
)->object_entry();
1879 gold_assert(entry
!= NULL
);
1880 const Object
* obj
= entry
->object();
1881 gold_assert(obj
!= NULL
);
1882 view_info
.input_index
= (*p
)->get_file_index();
1883 Got_visitor
v(view_info
);
1884 obj
->for_all_local_got_entries(&v
);
1887 // Write the incremental GOT and PLT descriptors for global symbols.
1888 typedef Global_symbol_visitor_got_plt
<size
, big_endian
> Symbol_visitor
;
1889 symtab_
->for_all_symbols
<size
, Symbol_visitor
>(Symbol_visitor(view_info
));
1892 // Class Sized_relobj_incr. Most of these methods are not used for
1893 // Incremental objects, but are required to be implemented by the
1894 // base class Object.
1896 template<int size
, bool big_endian
>
1897 Sized_relobj_incr
<size
, big_endian
>::Sized_relobj_incr(
1898 const std::string
& name
,
1899 Sized_incremental_binary
<size
, big_endian
>* ibase
,
1900 unsigned int input_file_index
)
1901 : Sized_relobj
<size
, big_endian
>(name
, NULL
), ibase_(ibase
),
1902 input_file_index_(input_file_index
),
1903 input_reader_(ibase
->inputs_reader().input_file(input_file_index
)),
1904 local_symbol_count_(0), output_local_dynsym_count_(0),
1905 local_symbol_index_(0), local_symbol_offset_(0), local_dynsym_offset_(0),
1906 symbols_(), incr_reloc_offset_(-1U), incr_reloc_count_(0),
1907 incr_reloc_output_index_(0), incr_relocs_(NULL
), local_symbols_()
1909 if (this->input_reader_
.is_in_system_directory())
1910 this->set_is_in_system_directory();
1911 const unsigned int shnum
= this->input_reader_
.get_input_section_count() + 1;
1912 this->set_shnum(shnum
);
1913 ibase
->set_input_object(input_file_index
, this);
1916 // Read the symbols.
1918 template<int size
, bool big_endian
>
1920 Sized_relobj_incr
<size
, big_endian
>::do_read_symbols(Read_symbols_data
*)
1925 // Lay out the input sections.
1927 template<int size
, bool big_endian
>
1929 Sized_relobj_incr
<size
, big_endian
>::do_layout(
1934 const unsigned int shnum
= this->shnum();
1935 Incremental_inputs
* incremental_inputs
= layout
->incremental_inputs();
1936 gold_assert(incremental_inputs
!= NULL
);
1937 Output_sections
& out_sections(this->output_sections());
1938 out_sections
.resize(shnum
);
1939 this->section_offsets().resize(shnum
);
1940 for (unsigned int i
= 1; i
< shnum
; i
++)
1942 typename
Input_entry_reader::Input_section_info sect
=
1943 this->input_reader_
.get_input_section(i
- 1);
1944 // Add the section to the incremental inputs layout.
1945 incremental_inputs
->report_input_section(this, i
, sect
.name
,
1947 if (sect
.output_shndx
== 0 || sect
.sh_offset
== -1)
1949 Output_section
* os
= this->ibase_
->output_section(sect
.output_shndx
);
1950 gold_assert(os
!= NULL
);
1951 out_sections
[i
] = os
;
1952 this->section_offsets()[i
] = static_cast<Address
>(sect
.sh_offset
);
1955 // Process the COMDAT groups.
1956 unsigned int ncomdat
= this->input_reader_
.get_comdat_group_count();
1957 for (unsigned int i
= 0; i
< ncomdat
; i
++)
1959 const char* signature
= this->input_reader_
.get_comdat_group_signature(i
);
1960 if (signature
== NULL
|| signature
[0] == '\0')
1961 this->error(_("COMDAT group has no signature"));
1962 bool keep
= layout
->find_or_add_kept_section(signature
, this, i
, true,
1965 this->error(_("COMDAT group %s included twice in incremental link"),
1970 // Layout sections whose layout was deferred while waiting for
1971 // input files from a plugin.
1972 template<int size
, bool big_endian
>
1974 Sized_relobj_incr
<size
, big_endian
>::do_layout_deferred_sections(Layout
*)
1978 // Add the symbols to the symbol table.
1980 template<int size
, bool big_endian
>
1982 Sized_relobj_incr
<size
, big_endian
>::do_add_symbols(
1983 Symbol_table
* symtab
,
1987 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
1988 unsigned char symbuf
[sym_size
];
1989 elfcpp::Sym
<size
, big_endian
> sym(symbuf
);
1990 elfcpp::Sym_write
<size
, big_endian
> osym(symbuf
);
1992 typedef typename
elfcpp::Elf_types
<size
>::Elf_WXword Elf_size_type
;
1994 unsigned int nsyms
= this->input_reader_
.get_global_symbol_count();
1995 this->symbols_
.resize(nsyms
);
1997 Incremental_binary::View
symtab_view(NULL
);
1998 unsigned int symtab_count
;
1999 elfcpp::Elf_strtab
strtab(NULL
, 0);
2000 this->ibase_
->get_symtab_view(&symtab_view
, &symtab_count
, &strtab
);
2002 Incremental_symtab_reader
<big_endian
> isymtab(this->ibase_
->symtab_reader());
2003 unsigned int isym_count
= isymtab
.symbol_count();
2004 unsigned int first_global
= symtab_count
- isym_count
;
2006 const unsigned char* sym_p
;
2007 for (unsigned int i
= 0; i
< nsyms
; ++i
)
2009 Incremental_global_symbol_reader
<big_endian
> info
=
2010 this->input_reader_
.get_global_symbol_reader(i
);
2011 unsigned int output_symndx
= info
.output_symndx();
2012 sym_p
= symtab_view
.data() + output_symndx
* sym_size
;
2013 elfcpp::Sym
<size
, big_endian
> gsym(sym_p
);
2015 if (!strtab
.get_c_string(gsym
.get_st_name(), &name
))
2018 typename
elfcpp::Elf_types
<size
>::Elf_Addr v
= gsym
.get_st_value();
2019 unsigned int shndx
= gsym
.get_st_shndx();
2020 elfcpp::STB st_bind
= gsym
.get_st_bind();
2021 elfcpp::STT st_type
= gsym
.get_st_type();
2023 // Local hidden symbols start out as globals, but get converted to
2024 // to local during output.
2025 if (st_bind
== elfcpp::STB_LOCAL
)
2026 st_bind
= elfcpp::STB_GLOBAL
;
2028 unsigned int input_shndx
= info
.shndx();
2029 if (input_shndx
== 0)
2031 shndx
= elfcpp::SHN_UNDEF
;
2034 else if (shndx
!= elfcpp::SHN_ABS
)
2036 // Find the input section and calculate the section-relative value.
2037 gold_assert(shndx
!= elfcpp::SHN_UNDEF
);
2038 Output_section
* os
= this->ibase_
->output_section(shndx
);
2039 gold_assert(os
!= NULL
&& os
->has_fixed_layout());
2040 typename
Input_entry_reader::Input_section_info sect
=
2041 this->input_reader_
.get_input_section(input_shndx
- 1);
2042 gold_assert(sect
.output_shndx
== shndx
);
2043 if (st_type
!= elfcpp::STT_TLS
)
2045 v
-= sect
.sh_offset
;
2046 shndx
= input_shndx
;
2049 osym
.put_st_name(0);
2050 osym
.put_st_value(v
);
2051 osym
.put_st_size(gsym
.get_st_size());
2052 osym
.put_st_info(st_bind
, st_type
);
2053 osym
.put_st_other(gsym
.get_st_other());
2054 osym
.put_st_shndx(shndx
);
2057 symtab
->add_from_incrobj(this, name
, NULL
, &sym
);
2058 this->ibase_
->add_global_symbol(output_symndx
- first_global
,
2063 // Return TRUE if we should include this object from an archive library.
2065 template<int size
, bool big_endian
>
2066 Archive::Should_include
2067 Sized_relobj_incr
<size
, big_endian
>::do_should_include_member(
2076 // Iterate over global symbols, calling a visitor class V for each.
2078 template<int size
, bool big_endian
>
2080 Sized_relobj_incr
<size
, big_endian
>::do_for_all_global_symbols(
2082 Library_base::Symbol_visitor_base
*)
2084 // This routine is not used for incremental objects.
2087 // Get the size of a section.
2089 template<int size
, bool big_endian
>
2091 Sized_relobj_incr
<size
, big_endian
>::do_section_size(unsigned int)
2096 // Get the name of a section.
2098 template<int size
, bool big_endian
>
2100 Sized_relobj_incr
<size
, big_endian
>::do_section_name(unsigned int)
2105 // Return a view of the contents of a section.
2107 template<int size
, bool big_endian
>
2109 Sized_relobj_incr
<size
, big_endian
>::do_section_contents(unsigned int)
2114 // Return section flags.
2116 template<int size
, bool big_endian
>
2118 Sized_relobj_incr
<size
, big_endian
>::do_section_flags(unsigned int)
2123 // Return section entsize.
2125 template<int size
, bool big_endian
>
2127 Sized_relobj_incr
<size
, big_endian
>::do_section_entsize(unsigned int)
2132 // Return section address.
2134 template<int size
, bool big_endian
>
2136 Sized_relobj_incr
<size
, big_endian
>::do_section_address(unsigned int)
2141 // Return section type.
2143 template<int size
, bool big_endian
>
2145 Sized_relobj_incr
<size
, big_endian
>::do_section_type(unsigned int)
2150 // Return the section link field.
2152 template<int size
, bool big_endian
>
2154 Sized_relobj_incr
<size
, big_endian
>::do_section_link(unsigned int)
2159 // Return the section link field.
2161 template<int size
, bool big_endian
>
2163 Sized_relobj_incr
<size
, big_endian
>::do_section_info(unsigned int)
2168 // Return the section alignment.
2170 template<int size
, bool big_endian
>
2172 Sized_relobj_incr
<size
, big_endian
>::do_section_addralign(unsigned int)
2177 // Return the Xindex structure to use.
2179 template<int size
, bool big_endian
>
2181 Sized_relobj_incr
<size
, big_endian
>::do_initialize_xindex()
2186 // Get symbol counts.
2188 template<int size
, bool big_endian
>
2190 Sized_relobj_incr
<size
, big_endian
>::do_get_global_symbol_counts(
2191 const Symbol_table
*, size_t*, size_t*) const
2198 template<int size
, bool big_endian
>
2200 Sized_relobj_incr
<size
, big_endian
>::do_read_relocs(Read_relocs_data
*)
2204 // Process the relocs to find list of referenced sections. Used only
2205 // during garbage collection.
2207 template<int size
, bool big_endian
>
2209 Sized_relobj_incr
<size
, big_endian
>::do_gc_process_relocs(Symbol_table
*,
2216 // Scan the relocs and adjust the symbol table.
2218 template<int size
, bool big_endian
>
2220 Sized_relobj_incr
<size
, big_endian
>::do_scan_relocs(Symbol_table
*,
2224 // Count the incremental relocations for this object.
2225 unsigned int nsyms
= this->input_reader_
.get_global_symbol_count();
2226 this->allocate_incremental_reloc_counts();
2227 for (unsigned int i
= 0; i
< nsyms
; i
++)
2229 Incremental_global_symbol_reader
<big_endian
> sym
=
2230 this->input_reader_
.get_global_symbol_reader(i
);
2231 unsigned int reloc_count
= sym
.reloc_count();
2232 if (reloc_count
> 0 && this->incr_reloc_offset_
== -1U)
2233 this->incr_reloc_offset_
= sym
.reloc_offset();
2234 this->incr_reloc_count_
+= reloc_count
;
2235 for (unsigned int j
= 0; j
< reloc_count
; j
++)
2236 this->count_incremental_reloc(i
);
2238 this->incr_reloc_output_index_
=
2239 layout
->incremental_inputs()->get_reloc_count();
2240 this->finalize_incremental_relocs(layout
, false);
2242 // The incoming incremental relocations may not end up in the same
2243 // location after the incremental update, because the incremental info
2244 // is regenerated in each link. Because the new location may overlap
2245 // with other data in the updated output file, we need to copy the
2246 // relocations into a buffer so that we can still read them safely
2247 // after we start writing updates to the output file.
2248 if (this->incr_reloc_count_
> 0)
2250 const Incremental_relocs_reader
<size
, big_endian
>& relocs_reader
=
2251 this->ibase_
->relocs_reader();
2252 const unsigned int incr_reloc_size
= relocs_reader
.reloc_size
;
2253 unsigned int len
= this->incr_reloc_count_
* incr_reloc_size
;
2254 this->incr_relocs_
= new unsigned char[len
];
2255 memcpy(this->incr_relocs_
,
2256 relocs_reader
.data(this->incr_reloc_offset_
),
2261 // Count the local symbols.
2263 template<int size
, bool big_endian
>
2265 Sized_relobj_incr
<size
, big_endian
>::do_count_local_symbols(
2266 Stringpool_template
<char>* pool
,
2267 Stringpool_template
<char>*)
2269 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2271 // Set the count of local symbols based on the incremental info.
2272 unsigned int nlocals
= this->input_reader_
.get_local_symbol_count();
2273 this->local_symbol_count_
= nlocals
;
2274 this->local_symbols_
.reserve(nlocals
);
2276 // Get views of the base file's symbol table and string table.
2277 Incremental_binary::View
symtab_view(NULL
);
2278 unsigned int symtab_count
;
2279 elfcpp::Elf_strtab
strtab(NULL
, 0);
2280 this->ibase_
->get_symtab_view(&symtab_view
, &symtab_count
, &strtab
);
2282 // Read the local symbols from the base file's symbol table.
2283 off_t off
= this->input_reader_
.get_local_symbol_offset();
2284 const unsigned char* symp
= symtab_view
.data() + off
;
2285 for (unsigned int i
= 0; i
< nlocals
; ++i
, symp
+= sym_size
)
2287 elfcpp::Sym
<size
, big_endian
> sym(symp
);
2289 if (!strtab
.get_c_string(sym
.get_st_name(), &name
))
2291 gold_debug(DEBUG_INCREMENTAL
, "Local symbol %d: %s", i
, name
);
2292 name
= pool
->add(name
, true, NULL
);
2293 this->local_symbols_
.push_back(Local_symbol(name
,
2302 // Finalize the local symbols.
2304 template<int size
, bool big_endian
>
2306 Sized_relobj_incr
<size
, big_endian
>::do_finalize_local_symbols(
2311 this->local_symbol_index_
= index
;
2312 this->local_symbol_offset_
= off
;
2313 return index
+ this->local_symbol_count_
;
2316 // Set the offset where local dynamic symbol information will be stored.
2318 template<int size
, bool big_endian
>
2320 Sized_relobj_incr
<size
, big_endian
>::do_set_local_dynsym_indexes(
2323 // FIXME: set local dynsym indexes.
2327 // Set the offset where local dynamic symbol information will be stored.
2329 template<int size
, bool big_endian
>
2331 Sized_relobj_incr
<size
, big_endian
>::do_set_local_dynsym_offset(off_t
)
2336 // Relocate the input sections and write out the local symbols.
2337 // We don't actually do any relocation here. For unchanged input files,
2338 // we reapply relocations only for symbols that have changed; that happens
2339 // in queue_final_tasks. We do need to rewrite the incremental relocations
2342 template<int size
, bool big_endian
>
2344 Sized_relobj_incr
<size
, big_endian
>::do_relocate(const Symbol_table
*,
2345 const Layout
* layout
,
2348 if (this->incr_reloc_count_
== 0)
2351 const unsigned int incr_reloc_size
=
2352 Incremental_relocs_reader
<size
, big_endian
>::reloc_size
;
2354 // Get a view for the .gnu_incremental_relocs section.
2355 Incremental_inputs
* inputs
= layout
->incremental_inputs();
2356 gold_assert(inputs
!= NULL
);
2357 const off_t relocs_off
= inputs
->relocs_section()->offset();
2358 const off_t relocs_size
= inputs
->relocs_section()->data_size();
2359 unsigned char* const view
= of
->get_output_view(relocs_off
, relocs_size
);
2361 // Copy the relocations from the buffer.
2362 off_t off
= this->incr_reloc_output_index_
* incr_reloc_size
;
2363 unsigned int len
= this->incr_reloc_count_
* incr_reloc_size
;
2364 memcpy(view
+ off
, this->incr_relocs_
, len
);
2366 // The output section table may have changed, so we need to map
2367 // the old section index to the new section index for each relocation.
2368 for (unsigned int i
= 0; i
< this->incr_reloc_count_
; ++i
)
2370 unsigned char* pov
= view
+ off
+ i
* incr_reloc_size
;
2371 unsigned int shndx
= elfcpp::Swap
<32, big_endian
>::readval(pov
+ 4);
2372 Output_section
* os
= this->ibase_
->output_section(shndx
);
2373 gold_assert(os
!= NULL
);
2374 shndx
= os
->out_shndx();
2375 elfcpp::Swap
<32, big_endian
>::writeval(pov
+ 4, shndx
);
2378 of
->write_output_view(off
, len
, view
);
2380 // Get views into the output file for the portions of the symbol table
2381 // and the dynamic symbol table that we will be writing.
2382 off_t symtab_off
= layout
->symtab_section()->offset();
2383 off_t output_size
= this->local_symbol_count_
* This::sym_size
;
2384 unsigned char* oview
= NULL
;
2385 if (output_size
> 0)
2386 oview
= of
->get_output_view(symtab_off
+ this->local_symbol_offset_
,
2389 off_t dyn_output_size
= this->output_local_dynsym_count_
* sym_size
;
2390 unsigned char* dyn_oview
= NULL
;
2391 if (dyn_output_size
> 0)
2392 dyn_oview
= of
->get_output_view(this->local_dynsym_offset_
,
2395 // Write the local symbols.
2396 unsigned char* ov
= oview
;
2397 unsigned char* dyn_ov
= dyn_oview
;
2398 const Stringpool
* sympool
= layout
->sympool();
2399 const Stringpool
* dynpool
= layout
->dynpool();
2400 Output_symtab_xindex
* symtab_xindex
= layout
->symtab_xindex();
2401 Output_symtab_xindex
* dynsym_xindex
= layout
->dynsym_xindex();
2402 for (unsigned int i
= 0; i
< this->local_symbol_count_
; ++i
)
2404 Local_symbol
& lsym(this->local_symbols_
[i
]);
2407 unsigned int st_shndx
= this->adjust_sym_shndx(i
, lsym
.st_shndx
,
2411 Output_section
* os
= this->ibase_
->output_section(st_shndx
);
2412 st_shndx
= os
->out_shndx();
2413 if (st_shndx
>= elfcpp::SHN_LORESERVE
)
2415 symtab_xindex
->add(this->local_symbol_index_
+ i
, st_shndx
);
2416 if (lsym
.needs_dynsym_entry
)
2417 dynsym_xindex
->add(lsym
.output_dynsym_index
, st_shndx
);
2418 st_shndx
= elfcpp::SHN_XINDEX
;
2422 // Write the symbol to the output symbol table.
2424 elfcpp::Sym_write
<size
, big_endian
> osym(ov
);
2425 osym
.put_st_name(sympool
->get_offset(lsym
.name
));
2426 osym
.put_st_value(lsym
.st_value
);
2427 osym
.put_st_size(lsym
.st_size
);
2428 osym
.put_st_info(elfcpp::STB_LOCAL
,
2429 static_cast<elfcpp::STT
>(lsym
.st_type
));
2430 osym
.put_st_other(0);
2431 osym
.put_st_shndx(st_shndx
);
2435 // Write the symbol to the output dynamic symbol table.
2436 if (lsym
.needs_dynsym_entry
)
2438 gold_assert(dyn_ov
< dyn_oview
+ dyn_output_size
);
2439 elfcpp::Sym_write
<size
, big_endian
> osym(dyn_ov
);
2440 osym
.put_st_name(dynpool
->get_offset(lsym
.name
));
2441 osym
.put_st_value(lsym
.st_value
);
2442 osym
.put_st_size(lsym
.st_size
);
2443 osym
.put_st_info(elfcpp::STB_LOCAL
,
2444 static_cast<elfcpp::STT
>(lsym
.st_type
));
2445 osym
.put_st_other(0);
2446 osym
.put_st_shndx(st_shndx
);
2451 if (output_size
> 0)
2453 gold_assert(ov
- oview
== output_size
);
2454 of
->write_output_view(symtab_off
+ this->local_symbol_offset_
,
2455 output_size
, oview
);
2458 if (dyn_output_size
> 0)
2460 gold_assert(dyn_ov
- dyn_oview
== dyn_output_size
);
2461 of
->write_output_view(this->local_dynsym_offset_
, dyn_output_size
,
2466 // Set the offset of a section.
2468 template<int size
, bool big_endian
>
2470 Sized_relobj_incr
<size
, big_endian
>::do_set_section_offset(unsigned int,
2475 // Class Sized_incr_dynobj. Most of these methods are not used for
2476 // Incremental objects, but are required to be implemented by the
2477 // base class Object.
2479 template<int size
, bool big_endian
>
2480 Sized_incr_dynobj
<size
, big_endian
>::Sized_incr_dynobj(
2481 const std::string
& name
,
2482 Sized_incremental_binary
<size
, big_endian
>* ibase
,
2483 unsigned int input_file_index
)
2484 : Dynobj(name
, NULL
), ibase_(ibase
),
2485 input_file_index_(input_file_index
),
2486 input_reader_(ibase
->inputs_reader().input_file(input_file_index
)),
2489 if (this->input_reader_
.is_in_system_directory())
2490 this->set_is_in_system_directory();
2491 if (this->input_reader_
.as_needed())
2492 this->set_as_needed();
2493 this->set_soname_string(this->input_reader_
.get_soname());
2497 // Read the symbols.
2499 template<int size
, bool big_endian
>
2501 Sized_incr_dynobj
<size
, big_endian
>::do_read_symbols(Read_symbols_data
*)
2506 // Lay out the input sections.
2508 template<int size
, bool big_endian
>
2510 Sized_incr_dynobj
<size
, big_endian
>::do_layout(
2517 // Add the symbols to the symbol table.
2519 template<int size
, bool big_endian
>
2521 Sized_incr_dynobj
<size
, big_endian
>::do_add_symbols(
2522 Symbol_table
* symtab
,
2526 const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
2527 unsigned char symbuf
[sym_size
];
2528 elfcpp::Sym
<size
, big_endian
> sym(symbuf
);
2529 elfcpp::Sym_write
<size
, big_endian
> osym(symbuf
);
2531 typedef typename
elfcpp::Elf_types
<size
>::Elf_WXword Elf_size_type
;
2533 unsigned int nsyms
= this->input_reader_
.get_global_symbol_count();
2534 this->symbols_
.resize(nsyms
);
2536 Incremental_binary::View
symtab_view(NULL
);
2537 unsigned int symtab_count
;
2538 elfcpp::Elf_strtab
strtab(NULL
, 0);
2539 this->ibase_
->get_symtab_view(&symtab_view
, &symtab_count
, &strtab
);
2541 Incremental_symtab_reader
<big_endian
> isymtab(this->ibase_
->symtab_reader());
2542 unsigned int isym_count
= isymtab
.symbol_count();
2543 unsigned int first_global
= symtab_count
- isym_count
;
2545 // We keep a set of symbols that we have generated COPY relocations
2546 // for, indexed by the symbol value. We do not need more than one
2547 // COPY relocation per address.
2548 typedef typename
std::set
<Address
> Copied_symbols
;
2549 Copied_symbols copied_symbols
;
2551 const unsigned char* sym_p
;
2552 for (unsigned int i
= 0; i
< nsyms
; ++i
)
2556 unsigned int output_symndx
=
2557 this->input_reader_
.get_output_symbol_index(i
, &is_def
, &is_copy
);
2558 sym_p
= symtab_view
.data() + output_symndx
* sym_size
;
2559 elfcpp::Sym
<size
, big_endian
> gsym(sym_p
);
2561 if (!strtab
.get_c_string(gsym
.get_st_name(), &name
))
2566 elfcpp::STB st_bind
= gsym
.get_st_bind();
2567 elfcpp::STT st_type
= gsym
.get_st_type();
2569 // Local hidden symbols start out as globals, but get converted to
2570 // to local during output.
2571 if (st_bind
== elfcpp::STB_LOCAL
)
2572 st_bind
= elfcpp::STB_GLOBAL
;
2576 shndx
= elfcpp::SHN_UNDEF
;
2581 // For a symbol defined in a shared object, the section index
2582 // is meaningless, as long as it's not SHN_UNDEF.
2584 v
= gsym
.get_st_value();
2587 osym
.put_st_name(0);
2588 osym
.put_st_value(v
);
2589 osym
.put_st_size(gsym
.get_st_size());
2590 osym
.put_st_info(st_bind
, st_type
);
2591 osym
.put_st_other(gsym
.get_st_other());
2592 osym
.put_st_shndx(shndx
);
2594 Sized_symbol
<size
>* res
=
2595 symtab
->add_from_incrobj
<size
, big_endian
>(this, name
, NULL
, &sym
);
2596 this->symbols_
[i
] = res
;
2597 this->ibase_
->add_global_symbol(output_symndx
- first_global
,
2602 std::pair
<typename
Copied_symbols::iterator
, bool> ins
=
2603 copied_symbols
.insert(v
);
2606 unsigned int shndx
= gsym
.get_st_shndx();
2607 Output_section
* os
= this->ibase_
->output_section(shndx
);
2608 off_t offset
= v
- os
->address();
2609 this->ibase_
->add_copy_reloc(this->symbols_
[i
], os
, offset
);
2615 // Return TRUE if we should include this object from an archive library.
2617 template<int size
, bool big_endian
>
2618 Archive::Should_include
2619 Sized_incr_dynobj
<size
, big_endian
>::do_should_include_member(
2628 // Iterate over global symbols, calling a visitor class V for each.
2630 template<int size
, bool big_endian
>
2632 Sized_incr_dynobj
<size
, big_endian
>::do_for_all_global_symbols(
2634 Library_base::Symbol_visitor_base
*)
2636 // This routine is not used for dynamic libraries.
2639 // Iterate over local symbols, calling a visitor class V for each GOT offset
2640 // associated with a local symbol.
2642 template<int size
, bool big_endian
>
2644 Sized_incr_dynobj
<size
, big_endian
>::do_for_all_local_got_entries(
2645 Got_offset_list::Visitor
*) const
2649 // Get the size of a section.
2651 template<int size
, bool big_endian
>
2653 Sized_incr_dynobj
<size
, big_endian
>::do_section_size(unsigned int)
2658 // Get the name of a section.
2660 template<int size
, bool big_endian
>
2662 Sized_incr_dynobj
<size
, big_endian
>::do_section_name(unsigned int)
2667 // Return a view of the contents of a section.
2669 template<int size
, bool big_endian
>
2671 Sized_incr_dynobj
<size
, big_endian
>::do_section_contents(unsigned int)
2676 // Return section flags.
2678 template<int size
, bool big_endian
>
2680 Sized_incr_dynobj
<size
, big_endian
>::do_section_flags(unsigned int)
2685 // Return section entsize.
2687 template<int size
, bool big_endian
>
2689 Sized_incr_dynobj
<size
, big_endian
>::do_section_entsize(unsigned int)
2694 // Return section address.
2696 template<int size
, bool big_endian
>
2698 Sized_incr_dynobj
<size
, big_endian
>::do_section_address(unsigned int)
2703 // Return section type.
2705 template<int size
, bool big_endian
>
2707 Sized_incr_dynobj
<size
, big_endian
>::do_section_type(unsigned int)
2712 // Return the section link field.
2714 template<int size
, bool big_endian
>
2716 Sized_incr_dynobj
<size
, big_endian
>::do_section_link(unsigned int)
2721 // Return the section link field.
2723 template<int size
, bool big_endian
>
2725 Sized_incr_dynobj
<size
, big_endian
>::do_section_info(unsigned int)
2730 // Return the section alignment.
2732 template<int size
, bool big_endian
>
2734 Sized_incr_dynobj
<size
, big_endian
>::do_section_addralign(unsigned int)
2739 // Return the Xindex structure to use.
2741 template<int size
, bool big_endian
>
2743 Sized_incr_dynobj
<size
, big_endian
>::do_initialize_xindex()
2748 // Get symbol counts.
2750 template<int size
, bool big_endian
>
2752 Sized_incr_dynobj
<size
, big_endian
>::do_get_global_symbol_counts(
2753 const Symbol_table
*, size_t*, size_t*) const
2758 // Allocate an incremental object of the appropriate size and endianness.
2761 make_sized_incremental_object(
2762 Incremental_binary
* ibase
,
2763 unsigned int input_file_index
,
2764 Incremental_input_type input_type
,
2765 const Incremental_binary::Input_reader
* input_reader
)
2768 std::string
name(input_reader
->filename());
2770 switch (parameters
->size_and_endianness())
2772 #ifdef HAVE_TARGET_32_LITTLE
2773 case Parameters::TARGET_32_LITTLE
:
2775 Sized_incremental_binary
<32, false>* sized_ibase
=
2776 static_cast<Sized_incremental_binary
<32, false>*>(ibase
);
2777 if (input_type
== INCREMENTAL_INPUT_SHARED_LIBRARY
)
2778 obj
= new Sized_incr_dynobj
<32, false>(name
, sized_ibase
,
2781 obj
= new Sized_relobj_incr
<32, false>(name
, sized_ibase
,
2786 #ifdef HAVE_TARGET_32_BIG
2787 case Parameters::TARGET_32_BIG
:
2789 Sized_incremental_binary
<32, true>* sized_ibase
=
2790 static_cast<Sized_incremental_binary
<32, true>*>(ibase
);
2791 if (input_type
== INCREMENTAL_INPUT_SHARED_LIBRARY
)
2792 obj
= new Sized_incr_dynobj
<32, true>(name
, sized_ibase
,
2795 obj
= new Sized_relobj_incr
<32, true>(name
, sized_ibase
,
2800 #ifdef HAVE_TARGET_64_LITTLE
2801 case Parameters::TARGET_64_LITTLE
:
2803 Sized_incremental_binary
<64, false>* sized_ibase
=
2804 static_cast<Sized_incremental_binary
<64, false>*>(ibase
);
2805 if (input_type
== INCREMENTAL_INPUT_SHARED_LIBRARY
)
2806 obj
= new Sized_incr_dynobj
<64, false>(name
, sized_ibase
,
2809 obj
= new Sized_relobj_incr
<64, false>(name
, sized_ibase
,
2814 #ifdef HAVE_TARGET_64_BIG
2815 case Parameters::TARGET_64_BIG
:
2817 Sized_incremental_binary
<64, true>* sized_ibase
=
2818 static_cast<Sized_incremental_binary
<64, true>*>(ibase
);
2819 if (input_type
== INCREMENTAL_INPUT_SHARED_LIBRARY
)
2820 obj
= new Sized_incr_dynobj
<64, true>(name
, sized_ibase
,
2823 obj
= new Sized_relobj_incr
<64, true>(name
, sized_ibase
,
2832 gold_assert(obj
!= NULL
);
2836 // Copy the unused symbols from the incremental input info.
2837 // We need to do this because we may be overwriting the incremental
2838 // input info in the base file before we write the new incremental
2841 Incremental_library::copy_unused_symbols()
2843 unsigned int symcount
= this->input_reader_
->get_unused_symbol_count();
2844 this->unused_symbols_
.reserve(symcount
);
2845 for (unsigned int i
= 0; i
< symcount
; ++i
)
2847 std::string
name(this->input_reader_
->get_unused_symbol(i
));
2848 this->unused_symbols_
.push_back(name
);
2852 // Iterator for unused global symbols in the library.
2854 Incremental_library::do_for_all_unused_symbols(Symbol_visitor_base
* v
) const
2856 for (Symbol_list::const_iterator p
= this->unused_symbols_
.begin();
2857 p
!= this->unused_symbols_
.end();
2859 v
->visit(p
->c_str());
2862 // Instantiate the templates we need.
2864 #ifdef HAVE_TARGET_32_LITTLE
2866 class Sized_incremental_binary
<32, false>;
2869 class Sized_relobj_incr
<32, false>;
2872 class Sized_incr_dynobj
<32, false>;
2875 #ifdef HAVE_TARGET_32_BIG
2877 class Sized_incremental_binary
<32, true>;
2880 class Sized_relobj_incr
<32, true>;
2883 class Sized_incr_dynobj
<32, true>;
2886 #ifdef HAVE_TARGET_64_LITTLE
2888 class Sized_incremental_binary
<64, false>;
2891 class Sized_relobj_incr
<64, false>;
2894 class Sized_incr_dynobj
<64, false>;
2897 #ifdef HAVE_TARGET_64_BIG
2899 class Sized_incremental_binary
<64, true>;
2902 class Sized_relobj_incr
<64, true>;
2905 class Sized_incr_dynobj
<64, true>;
2908 } // End namespace gold.