* archive.cc (Archive::include_member): Adjust call to

report_object.
	(Add_archive_symbols::run): Track argument serial numbers.
	(Lib_group::include_member): Likewise.
	(Add_lib_group_symbols::run): Adjust call to report_archive_begin.
	* archive.h (Incremental_archive_entry::Archive_member):
	Initialize arg_serial_.
	(Archive_member::arg_serial_): New data member.
	* dynobj.cc (Dynobj::Dynobj): Allow input_file_ to be NULL.
	(Sized_dynobj::do_add_symbols): Track symbols when doing an
	incremental link.
	(Sized_dynobj::do_for_all_local_got_entries): New function.
	* dynobj.h: (Sized_dynobj::do_for_all_local_got_entries): New
	function.
	* fileread.cc (get_mtime): New function.
	* fileread.h (get_mtime): New function.
	* gold.cc (queue_initial_tasks): Check for incremental update.
	(process_incremental_input): New function.
	(queue_middle_tasks): Don't force valid target for incremental
	update.
	* incremental-dump.cc (find_input_containing_global): Adjust
	size of symbol info entry.
	(dump_incremental_inputs): Dump argument serial number and
	in_system_directory flag; bias shndx by 1; print symbol names
	when dumping per-file symbol lists; use new symbol info readers.
	* incremental.cc
	(Output_section_incremental_inputs:update_data_size): New function.
	(Sized_incremental_binary::setup_readers): Setup input readers
	for each input file; build maps for files added from libraries
	and scripts.
	(Sized_incremental_binary::check_input_args): New function.
	(Sized_incremental_binary::do_check_inputs): Build map of argument
	serial numbers to input arguments.
	(Sized_incremental_binary::do_file_has_changed): Rename
	do_file_is_unchanged to this; compare file modification times.
	(Sized_incremental_binary::do_init_layout): New function.
	(Sized_incremental_binary::do_reserve_layout): New function.
	(Sized_incremental_binary::do_get_input_reader): Remove.
	(Sized_incremental_binary::get_symtab_view): New function.
	(Incremental_checker::can_incrementally_link_output_file): Remove.
	(Incremental_inputs::report_command_line): Exclude --debug options.
	(Incremental_inputs::report_archive_begin): Add parameter; track
	argument serial numbers; don't put input file entry for archive
	before archive members.
	(Incremental_inputs::report_archive_end): Put input file entry
	for archive after archive members.
	(Incremental_inputs::report_object): Add parameter; track argument
	serial numbers and in_system_directory flag.
	(Incremental_inputs::report_script): Add parameter; track argument
	serial numbers.
	(Output_section_incremental_inputs::set_final_data_size): Adjust
	size of symbol info entry; check for forwarding symbols.
	(Output_section_incremental_inputs::write_input_files): Write
	in_system_directory flag and argument serial number.
	(Output_section_incremental_inputs::write_info_blocks): Map section
	indices between incremental info and original input file; store
	input section index for each symbol.
	(class Local_got_offset_visitor): Derive from Got_offset_list::Visitor;
	change operator() to visit().
	(class Global_got_offset_visitor): Likewise.
	(class Global_symbol_visitor_got_plt):
	(Output_section_incremental_inputs::write_got_plt): Use new visitor
	classes.
	(Sized_incr_relobj::Sized_incr_relobj): New constructor.
	(Sized_incr_relobj::do_read_symbols): New function.
	(Sized_incr_relobj::do_layout): New function.
	(Sized_incr_relobj::do_layout_deferred_sections): New function.
	(Sized_incr_relobj::do_add_symbols): New function.
	(Sized_incr_relobj::do_should_include_member): New function.
	(Sized_incr_relobj::do_for_all_global_symbols): New function.
	(Sized_incr_relobj::do_for_all_local_got_entries): New function.
	(Sized_incr_relobj::do_section_size): New function.
	(Sized_incr_relobj::do_section_name): New function.
	(Sized_incr_relobj::do_section_contents): New function.
	(Sized_incr_relobj::do_section_flags): New function.
	(Sized_incr_relobj::do_section_entsize): New function.
	(Sized_incr_relobj::do_section_address): New function.
	(Sized_incr_relobj::do_section_type): New function.
	(Sized_incr_relobj::do_section_link): New function.
	(Sized_incr_relobj::do_section_info): New function.
	(Sized_incr_relobj::do_section_addralign): New function.
	(Sized_incr_relobj::do_initialize_xindex): New function.
	(Sized_incr_relobj::do_get_global_symbol_counts): New function.
	(Sized_incr_relobj::do_read_relocs): New function.
	(Sized_incr_relobj::do_gc_process_relocs): New function.
	(Sized_incr_relobj::do_scan_relocs): New function.
	(Sized_incr_relobj::do_count_local_symbols): New function.
	(Sized_incr_relobj::do_finalize_local_symbols): New function.
	(Sized_incr_relobj::do_set_local_dynsym_indexes): New function.
	(Sized_incr_relobj::do_set_local_dynsym_offset): New function.
	(Sized_incr_relobj::do_relocate): New function.
	(Sized_incr_relobj::do_set_section_offset): New function.
	(Sized_incr_dynobj::Sized_incr_dynobj): New function.
	(Sized_incr_dynobj::do_read_symbols): New function.
	(Sized_incr_dynobj::do_layout): New function.
	(Sized_incr_dynobj::do_add_symbols): New function.
	(Sized_incr_dynobj::do_should_include_member): New function.
	(Sized_incr_dynobj::do_for_all_global_symbols): New function.
	(Sized_incr_dynobj::do_for_all_local_got_entries): New function.
	(Sized_incr_dynobj::do_section_size): New function.
	(Sized_incr_dynobj::do_section_name): New function.
	(Sized_incr_dynobj::do_section_contents): New function.
	(Sized_incr_dynobj::do_section_flags): New function.
	(Sized_incr_dynobj::do_section_entsize): New function.
	(Sized_incr_dynobj::do_section_address): New function.
	(Sized_incr_dynobj::do_section_type): New function.
	(Sized_incr_dynobj::do_section_link): New function.
	(Sized_incr_dynobj::do_section_info): New function.
	(Sized_incr_dynobj::do_section_addralign): New function.
	(Sized_incr_dynobj::do_initialize_xindex): New function.
	(Sized_incr_dynobj::do_get_global_symbol_counts): New function.
	(make_sized_incremental_object): New function.
	(Incremental_library::copy_unused_symbols): New function.
	(Incremental_library::do_for_all_unused_symbols): New function.
	* incremental.h (enum Incremental_input_flags): New type.
	(class Incremental_checker): Remove.
	(Incremental_input_entry::Incremental_input_entry): Add argument
	serial number.
	(Incremental_input_entry::arg_serial): New function.
	(Incremental_input_entry::set_is_in_system_directory): New function.
	(Incremental_input_entry::is_in_system_directory): New function.
	(Incremental_input_entry::arg_serial_): New data member.
	(Incremental_input_entry::is_in_system_directory_): New data member.
	(class Script_info): Move here from script.h.
	(Script_info::Script_info): Add filename parameter.
	(Script_info::filename): New function.
	(Script_info::filename_): New data member.
	(Incremental_script_entry::Incremental_script_entry): Add argument
	serial number.
	(Incremental_object_entry::Incremental_object_entry): Likewise.
	(Incremental_object_entry::add_input_section): Build list of input
	sections with map to original shndx.
	(Incremental_object_entry::get_input_section_index): New function.
	(Incremental_object_entry::shndx_): New data member.
	(Incremental_object_entry::name_key_): Rename; adjust all refs.
	(Incremental_object_entry::sh_size_): Rename; adjust all refs.
	(Incremental_archive_entry::Incremental_archive_entry): Add argument
	serial number.
	(Incremental_inputs::report_archive_begin): Likewise.
	(Incremental_inputs::report_object): Likewise.
	(Incremental_inputs::report_script): Likewise.
	(class Incremental_global_symbol_reader): New class.
	(Incremental_input_entry_reader::Incremental_input_entry_reader): Read
	and store flags and input file type.
	(Incremental_input_entry_reader::arg_serial): New function.
	(Incremental_input_entry_reader::type): Extract type from flags.
	(Incremental_input_entry_reader::is_in_system_directory): New function.
	(Incremental_input_entry_reader::get_input_section_count): Call
	accessor function for type.
	(Incremental_input_entry_reader::get_symbol_offset): Call accessor
	function for type; adjust size of global symbol entry.
	(Incremental_input_entry_reader::get_global_symbol_count): Call
	accessor function for type.
	(Incremental_input_entry_reader::get_object_count): Likewise.
	(Incremental_input_entry_reader::get_object_offset): Likewise.
	(Incremental_input_entry_reader::get_member_count): Likewise.
	(Incremental_input_entry_reader::get_unused_symbol_count): Likewise.
	(Incremental_input_entry_reader::get_member_offset): Likewise.
	(Incremental_input_entry_reader::get_unused_symbol): Likewise.
	(Incremental_input_entry_reader::Global_symbol_info): Remove.
	(Incremental_input_entry_reader::get_global_symbol_info): Remove.
	(Incremental_input_entry_reader::get_global_symbol_reader): New
	function.
	(Incremental_input_entry_reader::get_output_symbol_index): New
	function.
	(Incremental_input_entry_reader::type_): Remove.
	(Incremental_input_entry_reader::flags_): New data member.
	(Incremental_inputs_reader::input_file_offset): New function.
	(Incremental_inputs_reader::input_file_index): New function.
	(Incremental_inputs_reader::input_file): Call input_file_offset.
	(Incremental_inputs_reader::input_file_at_offset): New function.
	(Incremental_relocs_reader::get_r_type): Reformat.
	(Incremental_relocs_reader::get_r_shndx): Reformat.
	(Incremental_relocs_reader::get_r_offset): Reformat.
	(Incremental_relocs_reader::data): New function.
	(Incremental_binary::Incremental_binary): Initialize new data members.
	(Incremental_binary::check_inputs): Add cmdline parameter.
	(Incremental_binary::file_is_unchanged): Remove.
	(Input_reader::arg_serial): New function.
	(Input_reader::get_unused_symbol_count): New function.
	(Input_reader::get_unused_symbol): New function.
	(Input_reader::do_arg_serial): New function.
	(Input_reader::do_get_unused_symbol_count): New function.
	(Input_reader::do_get_unused_symbol): New function.
	(Incremental_binary::input_file_count): New function.
	(Incremental_binary::get_input_reader): Change signature to use
	index instead of filename.
	(Incremental_binary::file_has_changed): New function.
	(Incremental_binary::get_input_argument): New function.
	(Incremental_binary::get_library): New function.
	(Incremental_binary::get_script_info): New function.
	(Incremental_binary::init_layout): New function.
	(Incremental_binary::reserve_layout): New function.
	(Incremental_binary::output_file): New function.
	(Incremental_binary::do_check_inputs): New function.
	(Incremental_binary::do_file_is_unchanged): Remove.
	(Incremental_binary::do_file_has_changed): New function.
	(Incremental_binary::do_init_layout): New function.
	(Incremental_binary::do_reserve_layout): New function.
	(Incremental_binary::do_input_file_count): New function.
	(Incremental_binary::do_get_input_reader): Change signature.
	(Incremental_binary::input_args_map_): New data member.
	(Incremental_binary::library_map_): New data member.
	(Incremental_binary::script_map_): New data member.
	(Sized_incremental_binary::Sized_incremental_binary): Initialize
	new data members.
	(Sized_incremental_binary::output_section): New function.
	(Sized_incremental_binary::inputs_reader): Add const.
	(Sized_incremental_binary::symtab_reader): Add const.
	(Sized_incremental_binary::relocs_reader): Add const.
	(Sized_incremental_binary::got_plt_reader): Add const.
	(Sized_incremental_binary::get_symtab_view): New function.
	(Sized_incremental_binary::Inputs_reader): New typedef.
	(Sized_incremental_binary::Input_entry_reader): New typedef.
	(Sized_incremental_binary::do_check_inputs): Add cmdline parameter.
	(Sized_incremental_binary::do_file_is_unchanged): Remove.
	(Sized_incremental_binary::do_file_has_changed): New function.
	(Sized_incremental_binary::do_init_layout): New function.
	(Sized_incremental_binary::do_reserve_layout): New function.
	(Sized_input_reader::Inputs_reader): Remove.
	(Sized_input_reader::Input_entry_reader): Remove.
	(Sized_input_reader::do_arg_serial): New function.
	(Sized_input_reader::do_get_unused_symbol_count): New function.
	(Sized_input_reader::do_get_unused_symbol): New function.
	(Sized_incremental_binary::do_input_file_count): New function.
	(Sized_incremental_binary::do_get_input_reader): Change signature;
	use index instead of filename.
	(Sized_incremental_binary::section_map_): New data member.
	(Sized_incremental_binary::input_entry_readers_): New data member.
	(class Sized_incr_relobj): New class.
	(class Sized_incr_dynobj): New class.
	(make_sized_incremental_object): New function.
	(class Incremental_library): New class.
	* layout.cc (Free_list::num_lists): New static data member.
	(Free_list::num_nodes): New static data member.
	(Free_list::num_removes): New static data member.
	(Free_list::num_remove_visits): New static data member.
	(Free_list::num_allocates): New static data member.
	(Free_list::num_allocate_visits): New static data member.
	(Free_list::init): New function.
	(Free_list::remove): New function.
	(Free_list::allocate): New function.
	(Free_list::dump): New function.
	(Free_list::print_stats): New function.
	(Layout_task_runner::run): Resize output file for incremental updates.
	(Layout::Layout): Initialize new data members.
	(Layout::set_incremental_base): New function.
	(Layout::init_fixed_output_section): New function.
	(Layout::layout_eh_frame): Do not build .eh_frame_hdr section for
	incremental updates.
	(Layout::create_gold_note): Do not create gold note section for
	incremental updates.
	(Layout::set_segment_offsets): Do not recalculate RELRO alignment
	for incremental updates.
	(Layout::set_section_offsets): For incremental updates, allocate space
	from free list.
	(Layout::create_symtab_sections): Layout with offsets relative to
	start of section; for incremental updates, allocate space from free
	list.
	(Layout::create_shdrs): For incremental updates, allocate space from
	free list.
	(Layout::finish_dynamic_section): For incremental updates, do not
	check --as-needed (fixed in subsequent patch).
	* layout.h (class Free_list): New class.
	(Layout::set_incremental_base): New function.
	(Layout::incremental_base): New function.
	(Layout::init_fixed_output_section): New function.
	(Layout::allocate): New function.
	(Layout::incremental_base_): New data member.
	(Layout::free_list_): New data member.
	* main.cc (main): Print Free_list statistics.
	* object.cc (Relobj::finalize_incremental_relocs): Add
	clear_counts parameter; clear counts only when clear_counts is set.
	(Sized_relobj::Sized_relobj): Initialize new base class.
	(Sized_relobj::do_layout): Don't report special sections.
	(Sized_relobj::do_for_all_local_got_entries): New function.
	(Sized_relobj::write_local_symbols): Add symtab_off parameter; add
	symtab_off to all symbol table offsets.
	(Sized_relobj::do_get_global_symbol_counts): Add typename keyword.
	* object.h (class Got_offset_list): Move to top of file.
	(Object::Object): Allow case where input_file == NULL.
	(Object::~Object): Likewise.
	(Object::input_file): Assert that input_file != NULL.
	(Object::lock): Allow case where input_file == NULL.
	(Object::unlock): Likewise.
	(Object::is_locked): Likewise.
	(Object::token): Likewise.
	(Object::release): Likewise.
	(Object::is_incremental): New function.
	(Object::get_mtime): New function.
	(Object::for_all_local_got_entries): New function.
	(Object::clear_view_cache_marks): Allow case where input_file == NULL.
	(Object::set_is_in_system_directory): New function.
	(Object::is_in_system_directory): New function.
	(Object::do_is_incremental): New function.
	(Object::do_get_mtime): New function.
	(Object::do_for_all_local_got_entries): New function.
	(Object::is_in_system_directory_): New data member.
	(Relobj::finalize_incremental_relocs): Add clear_counts parameter.
	(class Sized_relobj_base): New class.
	(class Sized_relobj): Derive from Sized_relobj_base.
	(class Sized_relobj::Symbols): Redeclare from base class.
	(class Sized_relobj::local_got_offset_list): Remove.
	(class Sized_relobj::Output_sections): Redeclare from base class.
	(class Sized_relobj::do_for_all_local_got_entries): New function.
	(class Sized_relobj::write_local_symbols): Add offset parameter.
	(class Sized_relobj::local_symbol_offset_): Update comment.
	(class Sized_relobj::local_dynsym_offset_): Update comment.
	* options.cc (Input_arguments::add_file): Remove const.
	* options.h (Input_file_argument::Input_file_argument):
	Initialize arg_serial_ (all constructors).
	(Input_file_argument::set_arg_serial): New function.
	(Input_file_argument::arg_serial): New function.
	(Input_file_argument::arg_serial_): New data member.
	(Input_arguments::Input_arguments): Initialize file_count_.
	(Input_arguments::add_file): Remove const.
	(Input_arguments::number_of_input_files): New function.
	(Input_arguments::file_count_): New data member.
	(Command_line::number_of_input_files): Call
	Input_arguments::number_of_input_files.
	* output.cc (Output_segment_headers::Output_segment_headers):
	Set current size.
	(Output_section::Input_section::current_data_size): New function.
	(Output_section::Output_section): Initialize new data members.
	(Output_section::add_input_section): Don't do merge sections for
	an incremental link; allocate space from free list for an
	incremental update.
	(Output_section::add_output_section_data): Allocate space from
	free list for an incremental update.
	(Output_section::update_data_size): New function.
	(Output_section::set_fixed_layout): New function.
	(Output_section::reserve): New function.
	(Output_segment::set_section_addresses): Remove const.
	(Output_segment::set_section_list_addresses): Remove const; allocate
	space from free list for an incremental update.
	(Output_segment::set_offset): Adjust size of RELRO segment for an
	incremental update.
	* output.h (Output_data::current_data_size): Move here from
	child classes.
	(Output_data::pre_finalize_data_size): New function.
	(Output_data::update_data_size): New function.
	(Output_section_headers::update_data_size): new function.
	(Output_section_data_build::current_data_size): Move to Output_data.
	(Output_data_strtab::update_data_size): New function.
	(Output_section::current_data_size): Move to Output_data.
	(Output_section::set_fixed_layout): New function.
	(Output_section::has_fixed_layout): New function.
	(Output_section::reserve): New function.
	(Output_section::update_data_size): New function.
	(Output_section::has_fixed_layout_): New data member.
	(Output_section::free_list_): New data member.
	(Output_segment::set_section_addresses): Remove const.
	(Output_segment::set_section_list_addresses): Remove const.
	* plugin.cc (Sized_pluginobj::do_for_all_local_got_entries):
	New function.
	* plugin.h (Sized_pluginobj::do_for_all_local_got_entries):
	New function.
	* readsyms.cc (Read_symbols::do_read_symbols): Add library
	parameter when calling Add_symbols constructor; store argument
	serial number for members of a lib group.
	(Add_symbols::locks): Allow case where token == NULL.
	(Add_symbols::run): Report libraries denoted by --start-lib/--end-lib.
	(Read_member::~Read_member): New function.
	(Read_member::is_runnable): New function.
	(Read_member::locks): New function.
	(Read_member::run): New function.
	(Check_script::~Check_script): New function.
	(Check_script::is_runnable): New function.
	(Check_script::locks): New function.
	(Check_script::run): New function.
	(Check_library::~Check_library): New function.
	(Check_library::is_runnable): New function.
	(Check_library::locks): New function.
	(Check_library::run): New function.
	* readsyms.h (Add_symbols::Add_symbols): Add library parameter.
	(Add_symbols::library_): New data member.
	(class Read_member): New class.
	(class Check_script): New class.
	(class Check_library): New class.
	* reloc.cc (Read_relocs::is_runnable): Allow case where
	token == NULL.
	(Read_relocs::locks): Likewise.
	(Scan_relocs::locks): Likewise.
	(Relocate_task::locks): Likewise.
	(Sized_relobj::do_scan_relocs): Tell finalize_incremental_relocs
	to clear counters.
	(Sized_relobj::incremental_relocs_scan): Fix comment.
	(Sized_relobj::do_relocate): Pass output file offset to
	write_local_symbols.
	(Sized_relobj::incremental_relocs_write_reltype): Use reloc_size
	from class declaration.
	* script.cc (read_input_script): Allocate Script_info; pass
	argument serial number to report_script.
	* script.h (class Script_info): Move to incremental.h.
	* symtab.cc (Symbol_table::add_from_incrobj): New function.
	* symtab.h (Symbol_table::add_from_incrobj): New function.
	(Symbol_table::set_file_offset): New function.
This commit is contained in:
Cary Coutant 2011-04-12 00:44:48 +00:00
parent f390c311be
commit cdc29364d1
29 changed files with 4187 additions and 569 deletions

View File

@ -1,3 +1,403 @@
2011-04-11 Cary Coutant <ccoutant@google.com>
* archive.cc (Archive::include_member): Adjust call to
report_object.
(Add_archive_symbols::run): Track argument serial numbers.
(Lib_group::include_member): Likewise.
(Add_lib_group_symbols::run): Adjust call to report_archive_begin.
* archive.h (Incremental_archive_entry::Archive_member):
Initialize arg_serial_.
(Archive_member::arg_serial_): New data member.
* dynobj.cc (Dynobj::Dynobj): Allow input_file_ to be NULL.
(Sized_dynobj::do_add_symbols): Track symbols when doing an
incremental link.
(Sized_dynobj::do_for_all_local_got_entries): New function.
* dynobj.h: (Sized_dynobj::do_for_all_local_got_entries): New
function.
* fileread.cc (get_mtime): New function.
* fileread.h (get_mtime): New function.
* gold.cc (queue_initial_tasks): Check for incremental update.
(process_incremental_input): New function.
(queue_middle_tasks): Don't force valid target for incremental
update.
* incremental-dump.cc (find_input_containing_global): Adjust
size of symbol info entry.
(dump_incremental_inputs): Dump argument serial number and
in_system_directory flag; bias shndx by 1; print symbol names
when dumping per-file symbol lists; use new symbol info readers.
* incremental.cc
(Output_section_incremental_inputs:update_data_size): New function.
(Sized_incremental_binary::setup_readers): Setup input readers
for each input file; build maps for files added from libraries
and scripts.
(Sized_incremental_binary::check_input_args): New function.
(Sized_incremental_binary::do_check_inputs): Build map of argument
serial numbers to input arguments.
(Sized_incremental_binary::do_file_has_changed): Rename
do_file_is_unchanged to this; compare file modification times.
(Sized_incremental_binary::do_init_layout): New function.
(Sized_incremental_binary::do_reserve_layout): New function.
(Sized_incremental_binary::do_get_input_reader): Remove.
(Sized_incremental_binary::get_symtab_view): New function.
(Incremental_checker::can_incrementally_link_output_file): Remove.
(Incremental_inputs::report_command_line): Exclude --debug options.
(Incremental_inputs::report_archive_begin): Add parameter; track
argument serial numbers; don't put input file entry for archive
before archive members.
(Incremental_inputs::report_archive_end): Put input file entry
for archive after archive members.
(Incremental_inputs::report_object): Add parameter; track argument
serial numbers and in_system_directory flag.
(Incremental_inputs::report_script): Add parameter; track argument
serial numbers.
(Output_section_incremental_inputs::set_final_data_size): Adjust
size of symbol info entry; check for forwarding symbols.
(Output_section_incremental_inputs::write_input_files): Write
in_system_directory flag and argument serial number.
(Output_section_incremental_inputs::write_info_blocks): Map section
indices between incremental info and original input file; store
input section index for each symbol.
(class Local_got_offset_visitor): Derive from Got_offset_list::Visitor;
change operator() to visit().
(class Global_got_offset_visitor): Likewise.
(class Global_symbol_visitor_got_plt):
(Output_section_incremental_inputs::write_got_plt): Use new visitor
classes.
(Sized_incr_relobj::Sized_incr_relobj): New constructor.
(Sized_incr_relobj::do_read_symbols): New function.
(Sized_incr_relobj::do_layout): New function.
(Sized_incr_relobj::do_layout_deferred_sections): New function.
(Sized_incr_relobj::do_add_symbols): New function.
(Sized_incr_relobj::do_should_include_member): New function.
(Sized_incr_relobj::do_for_all_global_symbols): New function.
(Sized_incr_relobj::do_for_all_local_got_entries): New function.
(Sized_incr_relobj::do_section_size): New function.
(Sized_incr_relobj::do_section_name): New function.
(Sized_incr_relobj::do_section_contents): New function.
(Sized_incr_relobj::do_section_flags): New function.
(Sized_incr_relobj::do_section_entsize): New function.
(Sized_incr_relobj::do_section_address): New function.
(Sized_incr_relobj::do_section_type): New function.
(Sized_incr_relobj::do_section_link): New function.
(Sized_incr_relobj::do_section_info): New function.
(Sized_incr_relobj::do_section_addralign): New function.
(Sized_incr_relobj::do_initialize_xindex): New function.
(Sized_incr_relobj::do_get_global_symbol_counts): New function.
(Sized_incr_relobj::do_read_relocs): New function.
(Sized_incr_relobj::do_gc_process_relocs): New function.
(Sized_incr_relobj::do_scan_relocs): New function.
(Sized_incr_relobj::do_count_local_symbols): New function.
(Sized_incr_relobj::do_finalize_local_symbols): New function.
(Sized_incr_relobj::do_set_local_dynsym_indexes): New function.
(Sized_incr_relobj::do_set_local_dynsym_offset): New function.
(Sized_incr_relobj::do_relocate): New function.
(Sized_incr_relobj::do_set_section_offset): New function.
(Sized_incr_dynobj::Sized_incr_dynobj): New function.
(Sized_incr_dynobj::do_read_symbols): New function.
(Sized_incr_dynobj::do_layout): New function.
(Sized_incr_dynobj::do_add_symbols): New function.
(Sized_incr_dynobj::do_should_include_member): New function.
(Sized_incr_dynobj::do_for_all_global_symbols): New function.
(Sized_incr_dynobj::do_for_all_local_got_entries): New function.
(Sized_incr_dynobj::do_section_size): New function.
(Sized_incr_dynobj::do_section_name): New function.
(Sized_incr_dynobj::do_section_contents): New function.
(Sized_incr_dynobj::do_section_flags): New function.
(Sized_incr_dynobj::do_section_entsize): New function.
(Sized_incr_dynobj::do_section_address): New function.
(Sized_incr_dynobj::do_section_type): New function.
(Sized_incr_dynobj::do_section_link): New function.
(Sized_incr_dynobj::do_section_info): New function.
(Sized_incr_dynobj::do_section_addralign): New function.
(Sized_incr_dynobj::do_initialize_xindex): New function.
(Sized_incr_dynobj::do_get_global_symbol_counts): New function.
(make_sized_incremental_object): New function.
(Incremental_library::copy_unused_symbols): New function.
(Incremental_library::do_for_all_unused_symbols): New function.
* incremental.h (enum Incremental_input_flags): New type.
(class Incremental_checker): Remove.
(Incremental_input_entry::Incremental_input_entry): Add argument
serial number.
(Incremental_input_entry::arg_serial): New function.
(Incremental_input_entry::set_is_in_system_directory): New function.
(Incremental_input_entry::is_in_system_directory): New function.
(Incremental_input_entry::arg_serial_): New data member.
(Incremental_input_entry::is_in_system_directory_): New data member.
(class Script_info): Move here from script.h.
(Script_info::Script_info): Add filename parameter.
(Script_info::filename): New function.
(Script_info::filename_): New data member.
(Incremental_script_entry::Incremental_script_entry): Add argument
serial number.
(Incremental_object_entry::Incremental_object_entry): Likewise.
(Incremental_object_entry::add_input_section): Build list of input
sections with map to original shndx.
(Incremental_object_entry::get_input_section_index): New function.
(Incremental_object_entry::shndx_): New data member.
(Incremental_object_entry::name_key_): Rename; adjust all refs.
(Incremental_object_entry::sh_size_): Rename; adjust all refs.
(Incremental_archive_entry::Incremental_archive_entry): Add argument
serial number.
(Incremental_inputs::report_archive_begin): Likewise.
(Incremental_inputs::report_object): Likewise.
(Incremental_inputs::report_script): Likewise.
(class Incremental_global_symbol_reader): New class.
(Incremental_input_entry_reader::Incremental_input_entry_reader): Read
and store flags and input file type.
(Incremental_input_entry_reader::arg_serial): New function.
(Incremental_input_entry_reader::type): Extract type from flags.
(Incremental_input_entry_reader::is_in_system_directory): New function.
(Incremental_input_entry_reader::get_input_section_count): Call
accessor function for type.
(Incremental_input_entry_reader::get_symbol_offset): Call accessor
function for type; adjust size of global symbol entry.
(Incremental_input_entry_reader::get_global_symbol_count): Call
accessor function for type.
(Incremental_input_entry_reader::get_object_count): Likewise.
(Incremental_input_entry_reader::get_object_offset): Likewise.
(Incremental_input_entry_reader::get_member_count): Likewise.
(Incremental_input_entry_reader::get_unused_symbol_count): Likewise.
(Incremental_input_entry_reader::get_member_offset): Likewise.
(Incremental_input_entry_reader::get_unused_symbol): Likewise.
(Incremental_input_entry_reader::Global_symbol_info): Remove.
(Incremental_input_entry_reader::get_global_symbol_info): Remove.
(Incremental_input_entry_reader::get_global_symbol_reader): New
function.
(Incremental_input_entry_reader::get_output_symbol_index): New
function.
(Incremental_input_entry_reader::type_): Remove.
(Incremental_input_entry_reader::flags_): New data member.
(Incremental_inputs_reader::input_file_offset): New function.
(Incremental_inputs_reader::input_file_index): New function.
(Incremental_inputs_reader::input_file): Call input_file_offset.
(Incremental_inputs_reader::input_file_at_offset): New function.
(Incremental_relocs_reader::get_r_type): Reformat.
(Incremental_relocs_reader::get_r_shndx): Reformat.
(Incremental_relocs_reader::get_r_offset): Reformat.
(Incremental_relocs_reader::data): New function.
(Incremental_binary::Incremental_binary): Initialize new data members.
(Incremental_binary::check_inputs): Add cmdline parameter.
(Incremental_binary::file_is_unchanged): Remove.
(Input_reader::arg_serial): New function.
(Input_reader::get_unused_symbol_count): New function.
(Input_reader::get_unused_symbol): New function.
(Input_reader::do_arg_serial): New function.
(Input_reader::do_get_unused_symbol_count): New function.
(Input_reader::do_get_unused_symbol): New function.
(Incremental_binary::input_file_count): New function.
(Incremental_binary::get_input_reader): Change signature to use
index instead of filename.
(Incremental_binary::file_has_changed): New function.
(Incremental_binary::get_input_argument): New function.
(Incremental_binary::get_library): New function.
(Incremental_binary::get_script_info): New function.
(Incremental_binary::init_layout): New function.
(Incremental_binary::reserve_layout): New function.
(Incremental_binary::output_file): New function.
(Incremental_binary::do_check_inputs): New function.
(Incremental_binary::do_file_is_unchanged): Remove.
(Incremental_binary::do_file_has_changed): New function.
(Incremental_binary::do_init_layout): New function.
(Incremental_binary::do_reserve_layout): New function.
(Incremental_binary::do_input_file_count): New function.
(Incremental_binary::do_get_input_reader): Change signature.
(Incremental_binary::input_args_map_): New data member.
(Incremental_binary::library_map_): New data member.
(Incremental_binary::script_map_): New data member.
(Sized_incremental_binary::Sized_incremental_binary): Initialize
new data members.
(Sized_incremental_binary::output_section): New function.
(Sized_incremental_binary::inputs_reader): Add const.
(Sized_incremental_binary::symtab_reader): Add const.
(Sized_incremental_binary::relocs_reader): Add const.
(Sized_incremental_binary::got_plt_reader): Add const.
(Sized_incremental_binary::get_symtab_view): New function.
(Sized_incremental_binary::Inputs_reader): New typedef.
(Sized_incremental_binary::Input_entry_reader): New typedef.
(Sized_incremental_binary::do_check_inputs): Add cmdline parameter.
(Sized_incremental_binary::do_file_is_unchanged): Remove.
(Sized_incremental_binary::do_file_has_changed): New function.
(Sized_incremental_binary::do_init_layout): New function.
(Sized_incremental_binary::do_reserve_layout): New function.
(Sized_input_reader::Inputs_reader): Remove.
(Sized_input_reader::Input_entry_reader): Remove.
(Sized_input_reader::do_arg_serial): New function.
(Sized_input_reader::do_get_unused_symbol_count): New function.
(Sized_input_reader::do_get_unused_symbol): New function.
(Sized_incremental_binary::do_input_file_count): New function.
(Sized_incremental_binary::do_get_input_reader): Change signature;
use index instead of filename.
(Sized_incremental_binary::section_map_): New data member.
(Sized_incremental_binary::input_entry_readers_): New data member.
(class Sized_incr_relobj): New class.
(class Sized_incr_dynobj): New class.
(make_sized_incremental_object): New function.
(class Incremental_library): New class.
* layout.cc (Free_list::num_lists): New static data member.
(Free_list::num_nodes): New static data member.
(Free_list::num_removes): New static data member.
(Free_list::num_remove_visits): New static data member.
(Free_list::num_allocates): New static data member.
(Free_list::num_allocate_visits): New static data member.
(Free_list::init): New function.
(Free_list::remove): New function.
(Free_list::allocate): New function.
(Free_list::dump): New function.
(Free_list::print_stats): New function.
(Layout_task_runner::run): Resize output file for incremental updates.
(Layout::Layout): Initialize new data members.
(Layout::set_incremental_base): New function.
(Layout::init_fixed_output_section): New function.
(Layout::layout_eh_frame): Do not build .eh_frame_hdr section for
incremental updates.
(Layout::create_gold_note): Do not create gold note section for
incremental updates.
(Layout::set_segment_offsets): Do not recalculate RELRO alignment
for incremental updates.
(Layout::set_section_offsets): For incremental updates, allocate space
from free list.
(Layout::create_symtab_sections): Layout with offsets relative to
start of section; for incremental updates, allocate space from free
list.
(Layout::create_shdrs): For incremental updates, allocate space from
free list.
(Layout::finish_dynamic_section): For incremental updates, do not
check --as-needed (fixed in subsequent patch).
* layout.h (class Free_list): New class.
(Layout::set_incremental_base): New function.
(Layout::incremental_base): New function.
(Layout::init_fixed_output_section): New function.
(Layout::allocate): New function.
(Layout::incremental_base_): New data member.
(Layout::free_list_): New data member.
* main.cc (main): Print Free_list statistics.
* object.cc (Relobj::finalize_incremental_relocs): Add
clear_counts parameter; clear counts only when clear_counts is set.
(Sized_relobj::Sized_relobj): Initialize new base class.
(Sized_relobj::do_layout): Don't report special sections.
(Sized_relobj::do_for_all_local_got_entries): New function.
(Sized_relobj::write_local_symbols): Add symtab_off parameter; add
symtab_off to all symbol table offsets.
(Sized_relobj::do_get_global_symbol_counts): Add typename keyword.
* object.h (class Got_offset_list): Move to top of file.
(Object::Object): Allow case where input_file == NULL.
(Object::~Object): Likewise.
(Object::input_file): Assert that input_file != NULL.
(Object::lock): Allow case where input_file == NULL.
(Object::unlock): Likewise.
(Object::is_locked): Likewise.
(Object::token): Likewise.
(Object::release): Likewise.
(Object::is_incremental): New function.
(Object::get_mtime): New function.
(Object::for_all_local_got_entries): New function.
(Object::clear_view_cache_marks): Allow case where input_file == NULL.
(Object::set_is_in_system_directory): New function.
(Object::is_in_system_directory): New function.
(Object::do_is_incremental): New function.
(Object::do_get_mtime): New function.
(Object::do_for_all_local_got_entries): New function.
(Object::is_in_system_directory_): New data member.
(Relobj::finalize_incremental_relocs): Add clear_counts parameter.
(class Sized_relobj_base): New class.
(class Sized_relobj): Derive from Sized_relobj_base.
(class Sized_relobj::Symbols): Redeclare from base class.
(class Sized_relobj::local_got_offset_list): Remove.
(class Sized_relobj::Output_sections): Redeclare from base class.
(class Sized_relobj::do_for_all_local_got_entries): New function.
(class Sized_relobj::write_local_symbols): Add offset parameter.
(class Sized_relobj::local_symbol_offset_): Update comment.
(class Sized_relobj::local_dynsym_offset_): Update comment.
* options.cc (Input_arguments::add_file): Remove const.
* options.h (Input_file_argument::Input_file_argument):
Initialize arg_serial_ (all constructors).
(Input_file_argument::set_arg_serial): New function.
(Input_file_argument::arg_serial): New function.
(Input_file_argument::arg_serial_): New data member.
(Input_arguments::Input_arguments): Initialize file_count_.
(Input_arguments::add_file): Remove const.
(Input_arguments::number_of_input_files): New function.
(Input_arguments::file_count_): New data member.
(Command_line::number_of_input_files): Call
Input_arguments::number_of_input_files.
* output.cc (Output_segment_headers::Output_segment_headers):
Set current size.
(Output_section::Input_section::current_data_size): New function.
(Output_section::Output_section): Initialize new data members.
(Output_section::add_input_section): Don't do merge sections for
an incremental link; allocate space from free list for an
incremental update.
(Output_section::add_output_section_data): Allocate space from
free list for an incremental update.
(Output_section::update_data_size): New function.
(Output_section::set_fixed_layout): New function.
(Output_section::reserve): New function.
(Output_segment::set_section_addresses): Remove const.
(Output_segment::set_section_list_addresses): Remove const; allocate
space from free list for an incremental update.
(Output_segment::set_offset): Adjust size of RELRO segment for an
incremental update.
* output.h (Output_data::current_data_size): Move here from
child classes.
(Output_data::pre_finalize_data_size): New function.
(Output_data::update_data_size): New function.
(Output_section_headers::update_data_size): new function.
(Output_section_data_build::current_data_size): Move to Output_data.
(Output_data_strtab::update_data_size): New function.
(Output_section::current_data_size): Move to Output_data.
(Output_section::set_fixed_layout): New function.
(Output_section::has_fixed_layout): New function.
(Output_section::reserve): New function.
(Output_section::update_data_size): New function.
(Output_section::has_fixed_layout_): New data member.
(Output_section::free_list_): New data member.
(Output_segment::set_section_addresses): Remove const.
(Output_segment::set_section_list_addresses): Remove const.
* plugin.cc (Sized_pluginobj::do_for_all_local_got_entries):
New function.
* plugin.h (Sized_pluginobj::do_for_all_local_got_entries):
New function.
* readsyms.cc (Read_symbols::do_read_symbols): Add library
parameter when calling Add_symbols constructor; store argument
serial number for members of a lib group.
(Add_symbols::locks): Allow case where token == NULL.
(Add_symbols::run): Report libraries denoted by --start-lib/--end-lib.
(Read_member::~Read_member): New function.
(Read_member::is_runnable): New function.
(Read_member::locks): New function.
(Read_member::run): New function.
(Check_script::~Check_script): New function.
(Check_script::is_runnable): New function.
(Check_script::locks): New function.
(Check_script::run): New function.
(Check_library::~Check_library): New function.
(Check_library::is_runnable): New function.
(Check_library::locks): New function.
(Check_library::run): New function.
* readsyms.h (Add_symbols::Add_symbols): Add library parameter.
(Add_symbols::library_): New data member.
(class Read_member): New class.
(class Check_script): New class.
(class Check_library): New class.
* reloc.cc (Read_relocs::is_runnable): Allow case where
token == NULL.
(Read_relocs::locks): Likewise.
(Scan_relocs::locks): Likewise.
(Relocate_task::locks): Likewise.
(Sized_relobj::do_scan_relocs): Tell finalize_incremental_relocs
to clear counters.
(Sized_relobj::incremental_relocs_scan): Fix comment.
(Sized_relobj::do_relocate): Pass output file offset to
write_local_symbols.
(Sized_relobj::incremental_relocs_write_reltype): Use reloc_size
from class declaration.
* script.cc (read_input_script): Allocate Script_info; pass
argument serial number to report_script.
* script.h (class Script_info): Move to incremental.h.
* symtab.cc (Symbol_table::add_from_incrobj): New function.
* symtab.h (Symbol_table::add_from_incrobj): New function.
(Symbol_table::set_file_offset): New function.
2011-04-05 Cary Coutant <ccoutant@google.com>
* incremental-dump.cc (dump_incremental_inputs): Change signature

View File

@ -960,7 +960,7 @@ Archive::include_member(Symbol_table* symtab, Layout* layout,
{
{
if (layout->incremental_inputs() != NULL)
layout->incremental_inputs()->report_object(obj, this, NULL);
layout->incremental_inputs()->report_object(obj, 0, this, NULL);
Read_symbols_data sd;
obj->read_symbols(&sd);
obj->layout(symtab, layout, &sd);
@ -1040,8 +1040,12 @@ Add_archive_symbols::run(Workqueue* workqueue)
// For an incremental link, begin recording layout information.
Incremental_inputs* incremental_inputs = this->layout_->incremental_inputs();
if (incremental_inputs != NULL)
incremental_inputs->report_archive_begin(this->archive_,
this->input_argument_->script_info());
{
unsigned int arg_serial = this->input_argument_->file().arg_serial();
Script_info* script_info = this->input_argument_->script_info();
incremental_inputs->report_archive_begin(this->archive_, arg_serial,
script_info);
}
bool added = this->archive_->add_symbols(this->symtab_, this->layout_,
this->input_objects_,
@ -1103,7 +1107,7 @@ Lib_group::Lib_group(const Input_file_lib* lib, Task* task)
const std::string&
Lib_group::do_filename() const
{
std::string *filename = new std::string("<group>");
std::string *filename = new std::string("/group/");
return *filename;
}
@ -1197,7 +1201,8 @@ Lib_group::include_member(Symbol_table* symtab, Layout* layout,
if (input_objects->add_object(obj))
{
if (layout->incremental_inputs() != NULL)
layout->incremental_inputs()->report_object(obj, this, NULL);
layout->incremental_inputs()->report_object(obj, member.arg_serial_,
this, NULL);
obj->layout(symtab, layout, sd);
obj->add_symbols(symtab, sd, layout);
}
@ -1257,7 +1262,7 @@ Add_lib_group_symbols::run(Workqueue*)
// For an incremental link, begin recording layout information.
Incremental_inputs* incremental_inputs = this->layout_->incremental_inputs();
if (incremental_inputs != NULL)
incremental_inputs->report_archive_begin(this->lib_, NULL);
incremental_inputs->report_archive_begin(this->lib_, 0, NULL);
this->lib_->add_symbols(this->symtab_, this->layout_, this->input_objects_);

View File

@ -48,7 +48,7 @@ class Incremental_archive_entry;
struct Archive_member
{
Archive_member()
: obj_(NULL), sd_(NULL)
: obj_(NULL), sd_(NULL), arg_serial_(0)
{ }
Archive_member(Object* obj, Read_symbols_data* sd)
: obj_(obj), sd_(sd)
@ -57,6 +57,8 @@ struct Archive_member
Object* obj_;
// The data to pass from read_symbols() to add_symbols().
Read_symbols_data* sd_;
// The serial number of the file in the argument list.
unsigned int arg_serial_;
};
// This class serves as a base class for Archive and Lib_group objects.

View File

@ -49,16 +49,23 @@ Dynobj::Dynobj(const std::string& name, Input_file* input_file, off_t offset)
// object's filename. The only exception is when the dynamic object
// is part of an archive (so the filename is the archive's
// filename). In that case, we use just the dynobj's name-in-archive.
this->soname_ = this->input_file()->found_name();
if (this->offset() != 0)
if (input_file == NULL)
this->soname_ = name;
else
{
std::string::size_type open_paren = this->name().find('(');
std::string::size_type close_paren = this->name().find(')');
if (open_paren != std::string::npos && close_paren != std::string::npos)
this->soname_ = input_file->found_name();
if (this->offset() != 0)
{
// It's an archive, and name() is of the form 'foo.a(bar.so)'.
this->soname_ = this->name().substr(open_paren + 1,
close_paren - (open_paren + 1));
std::string::size_type open_paren = this->name().find('(');
std::string::size_type close_paren = this->name().find(')');
if (open_paren != std::string::npos
&& close_paren != std::string::npos)
{
// It's an archive, and name() is of the form 'foo.a(bar.so)'.
open_paren += 1;
this->soname_ = this->name().substr(open_paren,
close_paren - open_paren);
}
}
}
}
@ -705,10 +712,11 @@ Sized_dynobj<size, big_endian>::do_add_symbols(Symbol_table* symtab,
Version_map version_map;
this->make_version_map(sd, &version_map);
// If printing symbol counts or a cross reference table, we want to
// track symbols.
// If printing symbol counts or a cross reference table or
// preparing for an incremental link, we want to track symbols.
if (parameters->options().user_set_print_symbol_counts()
|| parameters->options().cref())
|| parameters->options().cref()
|| parameters->incremental())
{
this->symbols_ = new Symbols();
this->symbols_->resize(symcount);
@ -787,6 +795,16 @@ Sized_dynobj<size, big_endian>::do_for_all_global_symbols(
}
}
// Iterate over local symbols, calling a visitor class V for each GOT offset
// associated with a local symbol.
template<int size, bool big_endian>
void
Sized_dynobj<size, big_endian>::do_for_all_local_got_entries(
Got_offset_list::Visitor*) const
{
}
// Get symbol counts.
template<int size, bool big_endian>

View File

@ -186,6 +186,11 @@ class Sized_dynobj : public Dynobj
do_for_all_global_symbols(Read_symbols_data* sd,
Library_base::Symbol_visitor_base* v);
// Iterate over local symbols, calling a visitor class V for each GOT offset
// associated with a local symbol.
void
do_for_all_local_got_entries(Got_offset_list::Visitor* v) const;
// Get the size of a section.
uint64_t
do_section_size(unsigned int shndx)

View File

@ -58,6 +58,25 @@ readv(int, const iovec*, int)
namespace gold
{
// Get the last modified time of an unopened file.
bool
get_mtime(const char* filename, Timespec* mtime)
{
struct stat file_stat;
if (stat(filename, &file_stat) < 0)
return false;
#ifdef HAVE_STAT_ST_MTIM
mtime->seconds = file_stat.st_mtim.tv_sec;
mtime->nanoseconds = file_stat.st_mtim.tv_nsec;
#else
mtime->seconds = file_stat.st_mtime;
mtime->nanoseconds = 0;
#endif
return true;
}
// Class File_read.
// A lock for the File_read static variables.
@ -851,7 +870,7 @@ File_read::get_mtime()
{
struct stat file_stat;
this->reopen_descriptor();
if (fstat(this->descriptor_, &file_stat) < 0)
gold_fatal(_("%s: stat failed: %s"), this->name_.c_str(),
strerror(errno));

View File

@ -52,6 +52,12 @@ struct Timespec
int nanoseconds;
};
// Get the last modified time of an unopened file. Returns false if the
// file does not exist.
bool
get_mtime(const char* filename, Timespec* mtime);
class Position_dependent_options;
class Input_file_argument;
class Dirsearch;

View File

@ -48,8 +48,15 @@
namespace gold
{
class Object;
const char* program_name;
static Task*
process_incremental_input(Incremental_binary*, unsigned int, Input_objects*,
Symbol_table*, Layout*, Dirsearch*, Mapfile*,
Task_token*, Task_token*);
void
gold_exit(bool status)
{
@ -178,19 +185,50 @@ queue_initial_tasks(const General_options& options,
thread_count = cmdline.number_of_input_files();
workqueue->set_thread_count(thread_count);
// For incremental links, the base output file.
Incremental_binary* ibase = NULL;
if (parameters->incremental())
{
Incremental_checker incremental_checker(
parameters->options().output_file_name(),
layout->incremental_inputs());
if (incremental_checker.can_incrementally_link_output_file())
{
// TODO: remove when incremental linking implemented.
printf("Incremental linking might be possible "
"(not implemented yet)\n");
}
// TODO: If we decide on an incremental build, fewer tasks
// should be scheduled.
if (options.relocatable())
gold_error(_("incremental linking is incompatible with -r"));
if (options.emit_relocs())
gold_error(_("incremental linking is incompatible with --emit-relocs"));
if (options.gc_sections())
gold_error(_("incremental linking is incompatible with --gc-sections"));
if (options.icf_enabled())
gold_error(_("incremental linking is incompatible with --icf"));
if (options.has_plugins())
gold_error(_("incremental linking is incompatible with --plugin"));
if (parameters->incremental_update())
{
Output_file* of = new Output_file(options.output_file_name());
if (!of->open_for_modification())
gold_info(_("incremental update not possible: "
"cannot open %s"),
options.output_file_name());
else
{
ibase = open_incremental_binary(of);
if (ibase != NULL
&& ibase->check_inputs(cmdline, layout->incremental_inputs()))
ibase->init_layout(layout);
else
{
delete ibase;
ibase = NULL;
of->close();
}
}
if (ibase == NULL)
{
if (set_parameters_incremental_full())
gold_info(_("linking with --incremental-full"));
else
gold_fatal(_("restart link with --incremental-full"));
}
}
}
// Read the input files. We have to add the symbols to the symbol
@ -198,16 +236,45 @@ queue_initial_tasks(const General_options& options,
// each input file. We associate the blocker with the following
// input file, to give us a convenient place to delete it.
Task_token* this_blocker = NULL;
for (Command_line::const_iterator p = cmdline.begin();
p != cmdline.end();
++p)
if (ibase == NULL)
{
Task_token* next_blocker = new Task_token(true);
next_blocker->add_blocker();
workqueue->queue(new Read_symbols(input_objects, symtab, layout,
&search_path, 0, mapfile, &*p, NULL,
NULL, this_blocker, next_blocker));
this_blocker = next_blocker;
// Normal link. Queue a Read_symbols task for each input file
// on the command line.
for (Command_line::const_iterator p = cmdline.begin();
p != cmdline.end();
++p)
{
Task_token* next_blocker = new Task_token(true);
next_blocker->add_blocker();
workqueue->queue(new Read_symbols(input_objects, symtab, layout,
&search_path, 0, mapfile, &*p, NULL,
NULL, this_blocker, next_blocker));
this_blocker = next_blocker;
}
}
else
{
// Incremental update link. Process the list of input files
// stored in the base file, and queue a task for each file:
// a Read_symbols task for a changed file, and an Add_symbols task
// for an unchanged file. We need to mark all the space used by
// unchanged files before we can start any tasks running.
unsigned int input_file_count = ibase->input_file_count();
std::vector<Task*> tasks;
tasks.reserve(input_file_count);
for (unsigned int i = 0; i < input_file_count; ++i)
{
Task_token* next_blocker = new Task_token(true);
next_blocker->add_blocker();
Task* t = process_incremental_input(ibase, i, input_objects, symtab,
layout, &search_path, mapfile,
this_blocker, next_blocker);
tasks.push_back(t);
this_blocker = next_blocker;
}
// Now we can queue the tasks.
for (unsigned int i = 0; i < tasks.size(); i++)
workqueue->queue(tasks[i]);
}
if (options.has_plugins())
@ -220,13 +287,11 @@ queue_initial_tasks(const General_options& options,
this_blocker = next_blocker;
}
if (parameters->options().relocatable()
&& (parameters->options().gc_sections()
|| parameters->options().icf_enabled()))
if (options.relocatable()
&& (options.gc_sections() || options.icf_enabled()))
gold_error(_("cannot mix -r with --gc-sections or --icf"));
if (parameters->options().gc_sections()
|| parameters->options().icf_enabled())
if (options.gc_sections() || options.icf_enabled())
{
workqueue->queue(new Task_function(new Gc_runner(options,
input_objects,
@ -248,6 +313,129 @@ queue_initial_tasks(const General_options& options,
}
}
// Process an incremental input file: if it is unchanged from the previous
// link, return a task to add its symbols from the base file's incremental
// info; if it has changed, return a normal Read_symbols task. We create a
// task for every input file, if only to report the file for rebuilding the
// incremental info.
static Task*
process_incremental_input(Incremental_binary* ibase,
unsigned int input_file_index,
Input_objects* input_objects,
Symbol_table* symtab,
Layout* layout,
Dirsearch* search_path,
Mapfile* mapfile,
Task_token* this_blocker,
Task_token* next_blocker)
{
const Incremental_binary::Input_reader* input_reader =
ibase->get_input_reader(input_file_index);
Incremental_input_type input_type = input_reader->type();
// Get the input argument corresponding to this input file, matching on
// the argument serial number. If the input file cannot be matched
// to an existing input argument, synthesize a new one.
const Input_argument* input_argument =
ibase->get_input_argument(input_file_index);
if (input_argument == NULL)
{
Input_file_argument file(input_reader->filename(),
Input_file_argument::INPUT_FILE_TYPE_FILE,
"", false, parameters->options());
Input_argument* arg = new Input_argument(file);
arg->set_script_info(ibase->get_script_info(input_file_index));
input_argument = arg;
}
gold_debug(DEBUG_INCREMENTAL, "Incremental object: %s, type %d",
input_reader->filename(), input_type);
if (input_type == INCREMENTAL_INPUT_SCRIPT)
{
// Incremental_binary::check_inputs should have cancelled the
// incremental update if the script has changed.
gold_assert(!ibase->file_has_changed(input_file_index));
return new Check_script(layout, ibase, input_file_index, input_reader,
this_blocker, next_blocker);
}
if (input_type == INCREMENTAL_INPUT_ARCHIVE)
{
Incremental_library* lib = ibase->get_library(input_file_index);
gold_assert(lib != NULL);
if (lib->filename() == "/group/"
|| !ibase->file_has_changed(input_file_index))
{
// Queue a task to check that no references have been added to any
// of the library's unused symbols.
return new Check_library(symtab, layout, ibase, input_file_index,
input_reader, this_blocker, next_blocker);
}
else
{
// Queue a Read_symbols task to process the archive normally.
return new Read_symbols(input_objects, symtab, layout, search_path,
0, mapfile, input_argument, NULL, NULL,
this_blocker, next_blocker);
}
}
if (input_type == INCREMENTAL_INPUT_ARCHIVE_MEMBER)
{
// For archive members, check the timestamp of the containing archive.
Incremental_library* lib = ibase->get_library(input_file_index);
gold_assert(lib != NULL);
// Process members of a --start-lib/--end-lib group as normal objects.
if (lib->filename() != "/group/")
{
if (ibase->file_has_changed(lib->input_file_index()))
{
return new Read_member(input_objects, symtab, layout, mapfile,
input_reader, this_blocker, next_blocker);
}
else
{
// The previous contributions from this file will be kept.
// Mark the pieces of output sections contributed by this
// object.
ibase->reserve_layout(input_file_index);
Object* obj = make_sized_incremental_object(ibase,
input_file_index,
input_type,
input_reader);
return new Add_symbols(input_objects, symtab, layout,
search_path, 0, mapfile, input_argument,
obj, lib, NULL, this_blocker,
next_blocker);
}
}
}
// Normal object file or shared library. Check if the file has changed
// since the last incremental link.
if (ibase->file_has_changed(input_file_index))
{
return new Read_symbols(input_objects, symtab, layout, search_path, 0,
mapfile, input_argument, NULL, NULL,
this_blocker, next_blocker);
}
else
{
// The previous contributions from this file will be kept.
// Mark the pieces of output sections contributed by this object.
ibase->reserve_layout(input_file_index);
Object* obj = make_sized_incremental_object(ibase,
input_file_index,
input_type,
input_reader);
return new Add_symbols(input_objects, symtab, layout, search_path, 0,
mapfile, input_argument, obj, NULL, NULL,
this_blocker, next_blocker);
}
}
// Queue up a set of tasks to be done before queueing the middle set
// of tasks. This is only necessary when garbage collection
// (--gc-sections) of unused sections is desired. The relocs are read
@ -396,7 +584,8 @@ queue_middle_tasks(const General_options& options,
// generate an empty file. Existing builds depend on being able to
// pass an empty archive to the linker and get an empty object file
// out. In order to do this we need to use a default target.
if (input_objects->number_of_input_objects() == 0)
if (input_objects->number_of_input_objects() == 0
&& layout->incremental_base() == NULL)
parameters_force_valid_target();
int thread_count = options.thread_count_middle();

View File

@ -63,7 +63,7 @@ find_input_containing_global(
if (offset >= input_file.get_symbol_offset(0)
&& offset < input_file.get_symbol_offset(nsyms))
{
*symndx = (offset - input_file.get_symbol_offset(0)) / 16;
*symndx = (offset - input_file.get_symbol_offset(0)) / 20;
return input_file;
}
}
@ -129,6 +129,10 @@ dump_incremental_inputs(const char* argv0, const char* filename,
mtime.nanoseconds,
ctime(&mtime.seconds));
printf(" Serial Number: %d\n", input_file.arg_serial());
printf(" In System Directory: %s\n",
input_file.is_in_system_directory() ? "true" : "false");
Incremental_input_type input_type = input_file.type();
printf(" Type: ");
switch (input_type)
@ -195,7 +199,7 @@ dump_incremental_inputs(const char* argv0, const char* filename,
{
typename Entry_reader::Input_section_info info(
input_file.get_input_section(shndx));
printf(" %3d %6d %8lld %8lld %s\n", shndx,
printf(" %3d %6d %8lld %8lld %s\n", shndx + 1,
info.output_shndx,
static_cast<long long>(info.sh_offset),
static_cast<long long>(info.sh_size),
@ -203,42 +207,6 @@ dump_incremental_inputs(const char* argv0, const char* filename,
}
}
printf("\nGlobal symbols per input file:\n");
for (unsigned int i = 0; i < incremental_inputs.input_file_count(); ++i)
{
Entry_reader input_file(incremental_inputs.input_file(i));
if (input_file.type() != INCREMENTAL_INPUT_OBJECT
&& input_file.type() != INCREMENTAL_INPUT_ARCHIVE_MEMBER)
continue;
const char* objname = input_file.filename();
if (objname == NULL)
{
fprintf(stderr,"%s: %s: failed to get file name for object %u\n",
argv0, filename, i);
exit(1);
}
printf("[%d] %s\n", i, objname);
unsigned int nsyms = input_file.get_global_symbol_count();
if (nsyms > 0)
printf(" %6s %8s %8s %8s %8s\n",
"outndx", "offset", "chain", "#relocs", "rbase");
for (unsigned int symndx = 0; symndx < nsyms; ++symndx)
{
typename Entry_reader::Global_symbol_info info(
input_file.get_global_symbol_info(symndx));
printf(" %6d %8d %8d %8d %8d\n",
info.output_symndx,
input_file.get_symbol_offset(symndx),
info.next_offset,
info.reloc_count,
info.reloc_offset);
}
}
// Get a view of the .symtab section.
elfcpp::Elf_file<size, big_endian, Incremental_binary> elf_file(inc);
@ -280,8 +248,77 @@ dump_incremental_inputs(const char* argv0, const char* filename,
unsigned int nsyms = symtab_location.data_size / sym_size;
unsigned int nglobals = isymtab.symbol_count();
unsigned int first_global = nsyms - nglobals;
unsigned const char* sym_p = symtab_view.data() + first_global * sym_size;
unsigned const char* sym_p;
printf("\nGlobal symbols per input file:\n");
for (unsigned int i = 0; i < incremental_inputs.input_file_count(); ++i)
{
Entry_reader input_file(incremental_inputs.input_file(i));
if (input_file.type() != INCREMENTAL_INPUT_OBJECT
&& input_file.type() != INCREMENTAL_INPUT_ARCHIVE_MEMBER
&& input_file.type() != INCREMENTAL_INPUT_SHARED_LIBRARY)
continue;
const char* objname = input_file.filename();
if (objname == NULL)
{
fprintf(stderr,"%s: %s: failed to get file name for object %u\n",
argv0, filename, i);
exit(1);
}
printf("[%d] %s\n", i, objname);
unsigned int nsyms = input_file.get_global_symbol_count();
if (nsyms > 0)
printf(" %6s %6s %8s %8s %8s %8s\n",
"outndx", "shndx", "offset", "chain", "#relocs", "rbase");
if (input_file.type() == INCREMENTAL_INPUT_SHARED_LIBRARY)
{
for (unsigned int symndx = 0; symndx < nsyms; ++symndx)
{
bool is_def;
unsigned int output_symndx =
input_file.get_output_symbol_index(symndx, &is_def);
sym_p = symtab_view.data() + output_symndx * sym_size;
elfcpp::Sym<size, big_endian> sym(sym_p);
const char* symname;
if (!strtab.get_c_string(sym.get_st_name(), &symname))
symname = "<unknown>";
printf(" %6d %6s %8s %8s %8s %8s %-5s %s\n",
output_symndx,
"", "", "", "", "",
is_def ? "DEF" : "UNDEF",
symname);
}
}
else
{
for (unsigned int symndx = 0; symndx < nsyms; ++symndx)
{
Incremental_global_symbol_reader<big_endian> info(
input_file.get_global_symbol_reader(symndx));
unsigned int output_symndx = info.output_symndx();
sym_p = symtab_view.data() + output_symndx * sym_size;
elfcpp::Sym<size, big_endian> sym(sym_p);
const char* symname;
if (!strtab.get_c_string(sym.get_st_name(), &symname))
symname = "<unknown>";
printf(" %6d %6d %8d %8d %8d %8d %-5s %s\n",
output_symndx,
info.shndx(),
input_file.get_symbol_offset(symndx),
info.next_offset(),
info.reloc_count(),
info.reloc_offset(),
info.shndx() != elfcpp::SHN_UNDEF ? "DEF" : "UNDEF",
symname);
}
}
}
sym_p = symtab_view.data() + first_global * sym_size;
printf("\nGlobal symbol table:\n");
for (unsigned int i = 0; i < nglobals; i++)
{
@ -297,19 +334,19 @@ dump_incremental_inputs(const char* argv0, const char* filename,
Entry_reader input_file =
find_input_containing_global<size, big_endian>(incremental_inputs,
offset, &sym_ndx);
typename Entry_reader::Global_symbol_info sym_info(
input_file.get_global_symbol_info(sym_ndx));
Incremental_global_symbol_reader<big_endian> sym_info(
input_file.get_global_symbol_reader(sym_ndx));
printf(" %s (first reloc: %d, reloc count: %d)",
input_file.filename(), sym_info.reloc_offset,
sym_info.reloc_count);
if (sym_info.output_symndx != first_global + i)
printf(" ** wrong output symndx (%d) **", sym_info.output_symndx);
input_file.filename(), sym_info.reloc_offset(),
sym_info.reloc_count());
if (sym_info.output_symndx() != first_global + i)
printf(" ** wrong output symndx (%d) **", sym_info.output_symndx());
printf("\n");
// Dump the relocations from this input file for this symbol.
unsigned int r_off = sym_info.reloc_offset;
for (unsigned int j = 0; j < sym_info.reloc_count; j++)
unsigned int r_off = sym_info.reloc_offset();
for (unsigned int j = 0; j < sym_info.reloc_count(); j++)
{
printf(" %4d relocation type %3d shndx %d"
printf(" %4d relocation type %3d shndx %2d"
" offset %016llx addend %016llx %s\n",
r_off,
irelocs.get_r_type(r_off),
@ -319,7 +356,7 @@ dump_incremental_inputs(const char* argv0, const char* filename,
symname);
r_off += irelocs.reloc_size;
}
offset = sym_info.next_offset;
offset = sym_info.next_offset();
}
sym_p += sym_size;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -55,6 +55,168 @@
namespace gold
{
// Class Free_list.
// The total number of free lists used.
unsigned int Free_list::num_lists = 0;
// The total number of free list nodes used.
unsigned int Free_list::num_nodes = 0;
// The total number of calls to Free_list::remove.
unsigned int Free_list::num_removes = 0;
// The total number of nodes visited during calls to Free_list::remove.
unsigned int Free_list::num_remove_visits = 0;
// The total number of calls to Free_list::allocate.
unsigned int Free_list::num_allocates = 0;
// The total number of nodes visited during calls to Free_list::allocate.
unsigned int Free_list::num_allocate_visits = 0;
// Initialize the free list. Creates a single free list node that
// describes the entire region of length LEN. If EXTEND is true,
// allocate() is allowed to extend the region beyond its initial
// length.
void
Free_list::init(off_t len, bool extend)
{
this->list_.push_front(Free_list_node(0, len));
this->last_remove_ = this->list_.begin();
this->extend_ = extend;
this->length_ = len;
++Free_list::num_lists;
++Free_list::num_nodes;
}
// Remove a chunk from the free list. Because we start with a single
// node that covers the entire section, and remove chunks from it one
// at a time, we do not need to coalesce chunks or handle cases that
// span more than one free node. We expect to remove chunks from the
// free list in order, and we expect to have only a few chunks of free
// space left (corresponding to files that have changed since the last
// incremental link), so a simple linear list should provide sufficient
// performance.
void
Free_list::remove(off_t start, off_t end)
{
if (start == end)
return;
gold_assert(start < end);
++Free_list::num_removes;
Iterator p = this->last_remove_;
if (p->start_ > start)
p = this->list_.begin();
for (; p != this->list_.end(); ++p)
{
++Free_list::num_remove_visits;
// Find a node that wholly contains the indicated region.
if (p->start_ <= start && p->end_ >= end)
{
// Case 1: the indicated region spans the whole node.
// Add some fuzz to avoid creating tiny free chunks.
if (p->start_ + 3 >= start && p->end_ <= end + 3)
p = this->list_.erase(p);
// Case 2: remove a chunk from the start of the node.
else if (p->start_ + 3 >= start)
p->start_ = end;
// Case 3: remove a chunk from the end of the node.
else if (p->end_ <= end + 3)
p->end_ = start;
// Case 4: remove a chunk from the middle, and split
// the node into two.
else
{
Free_list_node newnode(p->start_, start);
p->start_ = end;
this->list_.insert(p, newnode);
++Free_list::num_nodes;
}
this->last_remove_ = p;
return;
}
}
// Did not find a node containing the given chunk. This could happen
// because a small chunk was already removed due to the fuzz.
gold_debug(DEBUG_INCREMENTAL,
"Free_list::remove(%d,%d) not found",
static_cast<int>(start), static_cast<int>(end));
}
// Allocate a chunk of size LEN from the free list. Returns -1ULL
// if a sufficiently large chunk of free space is not found.
// We use a simple first-fit algorithm.
off_t
Free_list::allocate(off_t len, uint64_t align, off_t minoff)
{
gold_debug(DEBUG_INCREMENTAL,
"Free_list::allocate(%08lx, %d, %08lx)",
static_cast<long>(len), static_cast<int>(align),
static_cast<long>(minoff));
if (len == 0)
return align_address(minoff, align);
++Free_list::num_allocates;
for (Iterator p = this->list_.begin(); p != this->list_.end(); ++p)
{
++Free_list::num_allocate_visits;
off_t start = p->start_ > minoff ? p->start_ : minoff;
start = align_address(start, align);
off_t end = start + len;
if (end <= p->end_)
{
if (p->start_ + 3 >= start && p->end_ <= end + 3)
this->list_.erase(p);
else if (p->start_ + 3 >= start)
p->start_ = end;
else if (p->end_ <= end + 3)
p->end_ = start;
else
{
Free_list_node newnode(p->start_, start);
p->start_ = end;
this->list_.insert(p, newnode);
++Free_list::num_nodes;
}
return start;
}
}
return -1;
}
// Dump the free list (for debugging).
void
Free_list::dump()
{
gold_info("Free list:\n start end length\n");
for (Iterator p = this->list_.begin(); p != this->list_.end(); ++p)
gold_info(" %08lx %08lx %08lx", static_cast<long>(p->start_),
static_cast<long>(p->end_),
static_cast<long>(p->end_ - p->start_));
}
// Print the statistics for the free lists.
void
Free_list::print_stats()
{
fprintf(stderr, _("%s: total free lists: %u\n"),
program_name, Free_list::num_lists);
fprintf(stderr, _("%s: total free list nodes: %u\n"),
program_name, Free_list::num_nodes);
fprintf(stderr, _("%s: calls to Free_list::remove: %u\n"),
program_name, Free_list::num_removes);
fprintf(stderr, _("%s: nodes visited: %u\n"),
program_name, Free_list::num_remove_visits);
fprintf(stderr, _("%s: calls to Free_list::allocate: %u\n"),
program_name, Free_list::num_allocates);
fprintf(stderr, _("%s: nodes visited: %u\n"),
program_name, Free_list::num_allocate_visits);
}
// Layout::Relaxation_debug_check methods.
// Check that sections and special data are in reset states.
@ -150,10 +312,19 @@ Layout_task_runner::run(Workqueue* workqueue, const Task* task)
this->layout_->print_to_mapfile(this->mapfile_);
}
Output_file* of = new Output_file(parameters->options().output_file_name());
if (this->options_.oformat_enum() != General_options::OBJECT_FORMAT_ELF)
of->set_is_temporary();
of->open(file_size);
Output_file* of;
if (this->layout_->incremental_base() == NULL)
{
of = new Output_file(parameters->options().output_file_name());
if (this->options_.oformat_enum() != General_options::OBJECT_FORMAT_ELF)
of->set_is_temporary();
of->open(file_size);
}
else
{
of = this->layout_->incremental_base()->output_file();
of->resize(file_size);
}
// Queue up the final set of tasks.
gold::queue_final_tasks(this->options_, this->input_objects_,
@ -207,7 +378,9 @@ Layout::Layout(int number_of_input_files, Script_options* script_options)
record_output_section_data_from_script_(false),
script_output_section_data_list_(),
segment_states_(NULL),
relaxation_debug_check_(NULL)
relaxation_debug_check_(NULL),
incremental_base_(NULL),
free_list_()
{
// Make space for more than enough segments for a typical file.
// This is just for efficiency--it's OK if we wind up needing more.
@ -226,6 +399,15 @@ Layout::Layout(int number_of_input_files, Script_options* script_options)
this->namepool_.set_optimize();
}
// For incremental links, record the base file to be modified.
void
Layout::set_incremental_base(Incremental_binary* base)
{
this->incremental_base_ = base;
this->free_list_.init(base->output_file()->filesize(), true);
}
// Hash a key we use to look up an output section mapping.
size_t
@ -639,6 +821,41 @@ Layout::choose_output_section(const Relobj* relobj, const char* name,
return this->get_output_section(name, name_key, type, flags, order, is_relro);
}
// For incremental links, record the initial fixed layout of a section
// from the base file, and return a pointer to the Output_section.
template<int size, bool big_endian>
Output_section*
Layout::init_fixed_output_section(const char* name,
elfcpp::Shdr<size, big_endian>& shdr)
{
unsigned int sh_type = shdr.get_sh_type();
// We preserve the layout of PROGBITS, NOBITS, and NOTE sections.
// All others will be created from scratch and reallocated.
if (sh_type != elfcpp::SHT_PROGBITS
&& sh_type != elfcpp::SHT_NOBITS
&& sh_type != elfcpp::SHT_NOTE)
return NULL;
typename elfcpp::Elf_types<size>::Elf_Addr sh_addr = shdr.get_sh_addr();
typename elfcpp::Elf_types<size>::Elf_Off sh_offset = shdr.get_sh_offset();
typename elfcpp::Elf_types<size>::Elf_WXword sh_size = shdr.get_sh_size();
typename elfcpp::Elf_types<size>::Elf_WXword sh_flags = shdr.get_sh_flags();
typename elfcpp::Elf_types<size>::Elf_WXword sh_addralign =
shdr.get_sh_addralign();
// Make the output section.
Stringpool::Key name_key;
name = this->namepool_.add(name, true, &name_key);
Output_section* os = this->get_output_section(name, name_key, sh_type,
sh_flags, ORDER_INVALID, false);
os->set_fixed_layout(sh_addr, sh_offset, sh_size, sh_addralign);
if (sh_type != elfcpp::SHT_NOBITS)
this->free_list_.remove(sh_offset, sh_offset + sh_size);
return os;
}
// Return the output section to use for input section SHNDX, with name
// NAME, with header HEADER, from object OBJECT. RELOC_SHNDX is the
// index of a relocation section which applies to this section, or 0
@ -869,7 +1086,9 @@ Layout::layout_eh_frame(Sized_relobj<size, big_endian>* object,
this->eh_frame_section_ = os;
this->eh_frame_data_ = new Eh_frame();
if (parameters->options().eh_frame_hdr())
// For incremental linking, we do not optimize .eh_frame sections
// or create a .eh_frame_hdr section.
if (parameters->options().eh_frame_hdr() && !parameters->incremental())
{
Output_section* hdr_os =
this->choose_output_section(NULL, ".eh_frame_hdr",
@ -901,14 +1120,15 @@ Layout::layout_eh_frame(Sized_relobj<size, big_endian>* object,
gold_assert(this->eh_frame_section_ == os);
if (this->eh_frame_data_->add_ehframe_input_section(object,
symbols,
symbols_size,
symbol_names,
symbol_names_size,
shndx,
reloc_shndx,
reloc_type))
if (!parameters->incremental()
&& this->eh_frame_data_->add_ehframe_input_section(object,
symbols,
symbols_size,
symbol_names,
symbol_names_size,
shndx,
reloc_shndx,
reloc_type))
{
os->update_flags_for_input_section(shdr.get_sh_flags());
@ -2147,7 +2367,8 @@ Layout::create_note(const char* name, int note_type,
void
Layout::create_gold_note()
{
if (parameters->options().relocatable())
if (parameters->options().relocatable()
|| parameters->incremental_update())
return;
std::string desc = std::string("gold ") + gold::get_version_string();
@ -2709,7 +2930,10 @@ Layout::set_segment_offsets(const Target* target, Output_segment* load_seg,
// aligned so that the relro data ends at a page boundary,
// we do not try to realign it.
if (!are_addresses_set && !has_relro && aligned_addr != addr)
if (!are_addresses_set
&& !has_relro
&& aligned_addr != addr
&& !parameters->incremental_update())
{
uint64_t first_off = (common_pagesize
- (aligned_addr
@ -2826,6 +3050,9 @@ Layout::set_relocatable_section_offsets(Output_data* file_header,
off_t
Layout::set_section_offsets(off_t off, Layout::Section_offset_pass pass)
{
off_t startoff = off;
off_t maxoff = off;
for (Section_list::iterator p = this->unattached_section_list_.begin();
p != this->unattached_section_list_.end();
++p)
@ -2857,16 +3084,53 @@ Layout::set_section_offsets(off_t off, Layout::Section_offset_pass pass)
|| (*p)->type() != elfcpp::SHT_STRTAB))
continue;
off = align_address(off, (*p)->addralign());
(*p)->set_file_offset(off);
(*p)->finalize_data_size();
if (!parameters->incremental_update())
{
off = align_address(off, (*p)->addralign());
(*p)->set_file_offset(off);
(*p)->finalize_data_size();
}
else
{
// Incremental update: allocate file space from free list.
(*p)->pre_finalize_data_size();
off_t current_size = (*p)->current_data_size();
off = this->allocate(current_size, (*p)->addralign(), startoff);
if (off == -1)
{
if (is_debugging_enabled(DEBUG_INCREMENTAL))
this->free_list_.dump();
gold_assert((*p)->output_section() != NULL);
gold_fatal(_("out of patch space for section %s; "
"relink with --incremental-full"),
(*p)->output_section()->name());
}
(*p)->set_file_offset(off);
(*p)->finalize_data_size();
if ((*p)->data_size() > current_size)
{
gold_assert((*p)->output_section() != NULL);
gold_fatal(_("%s: section changed size; "
"relink with --incremental-full"),
(*p)->output_section()->name());
}
gold_debug(DEBUG_INCREMENTAL,
"set_section_offsets: %08lx %08lx %s",
static_cast<long>(off),
static_cast<long>((*p)->data_size()),
((*p)->output_section() != NULL
? (*p)->output_section()->name() : "(special)"));
}
off += (*p)->data_size();
if (off > maxoff)
maxoff = off;
// At this point the name must be set.
if (pass != STRTAB_AFTER_POSTPROCESSING_SECTIONS_PASS)
this->namepool_.add((*p)->name(), false, NULL);
}
return off;
return maxoff;
}
// Set the section indexes of all the sections not associated with a
@ -2980,9 +3244,8 @@ Layout::create_symtab_sections(const Input_objects* input_objects,
else
gold_unreachable();
off_t off = *poff;
off = align_address(off, align);
off_t startoff = off;
// Compute file offsets relative to the start of the symtab section.
off_t off = 0;
// Save space for the dummy symbol at the start of the section. We
// never bother to write this out--it will just be left as zero.
@ -3015,7 +3278,7 @@ Layout::create_symtab_sections(const Input_objects* input_objects,
}
unsigned int local_symcount = local_symbol_index;
gold_assert(static_cast<off_t>(local_symcount * symsize) == off - startoff);
gold_assert(static_cast<off_t>(local_symcount * symsize) == off);
off_t dynoff;
size_t dyn_global_index;
@ -3036,6 +3299,7 @@ Layout::create_symtab_sections(const Input_objects* input_objects,
== this->dynsym_section_->data_size() - locsize);
}
off_t global_off = off;
off = symtab->finalize(off, dynoff, dyn_global_index, dyncount,
&this->sympool_, &local_symcount);
@ -3050,8 +3314,7 @@ Layout::create_symtab_sections(const Input_objects* input_objects,
false);
this->symtab_section_ = osymtab;
Output_section_data* pos = new Output_data_fixed_space(off - startoff,
align,
Output_section_data* pos = new Output_data_fixed_space(off, align,
"** symtab");
osymtab->add_output_section_data(pos);
@ -3071,7 +3334,7 @@ Layout::create_symtab_sections(const Input_objects* input_objects,
elfcpp::SHT_SYMTAB_SHNDX, 0,
ORDER_INVALID, false);
size_t symcount = (off - startoff) / symsize;
size_t symcount = off / symsize;
this->symtab_xindex_ = new Output_symtab_xindex(symcount);
osymtab_xindex->add_output_section_data(this->symtab_xindex_);
@ -3097,13 +3360,30 @@ Layout::create_symtab_sections(const Input_objects* input_objects,
Output_section_data* pstr = new Output_data_strtab(&this->sympool_);
ostrtab->add_output_section_data(pstr);
osymtab->set_file_offset(startoff);
off_t symtab_off;
if (!parameters->incremental_update())
symtab_off = align_address(*poff, align);
else
{
symtab_off = this->allocate(off, align, *poff);
if (off == -1)
gold_fatal(_("out of patch space for symbol table; "
"relink with --incremental-full"));
gold_debug(DEBUG_INCREMENTAL,
"create_symtab_sections: %08lx %08lx .symtab",
static_cast<long>(symtab_off),
static_cast<long>(off));
}
symtab->set_file_offset(symtab_off + global_off);
osymtab->set_file_offset(symtab_off);
osymtab->finalize_data_size();
osymtab->set_link_section(ostrtab);
osymtab->set_info(local_symcount);
osymtab->set_entsize(symsize);
*poff = off;
if (symtab_off + off > *poff)
*poff = symtab_off + off;
}
}
@ -3150,10 +3430,25 @@ Layout::create_shdrs(const Output_section* shstrtab_section, off_t* poff)
&this->unattached_section_list_,
&this->namepool_,
shstrtab_section);
off_t off = align_address(*poff, oshdrs->addralign());
off_t off;
if (!parameters->incremental_update())
off = align_address(*poff, oshdrs->addralign());
else
{
oshdrs->pre_finalize_data_size();
off = this->allocate(oshdrs->data_size(), oshdrs->addralign(), *poff);
if (off == -1)
gold_fatal(_("out of patch space for section header table; "
"relink with --incremental-full"));
gold_debug(DEBUG_INCREMENTAL,
"create_shdrs: %08lx %08lx (section header table)",
static_cast<long>(off),
static_cast<long>(off + oshdrs->data_size()));
}
oshdrs->set_address_and_file_offset(0, off);
off += oshdrs->data_size();
*poff = off;
if (off > *poff)
*poff = off;
this->section_headers_ = oshdrs;
}
@ -3667,6 +3962,7 @@ Layout::finish_dynamic_section(const Input_objects* input_objects,
++p)
{
if (!(*p)->is_needed()
&& !(*p)->is_incremental()
&& (*p)->input_file()->options().as_needed())
{
// This dynamic object was linked with --as-needed, but it
@ -4421,6 +4717,38 @@ Close_task_runner::run(Workqueue*, const Task*)
// Instantiate the templates we need. We could use the configure
// script to restrict this to only the ones for implemented targets.
#ifdef HAVE_TARGET_32_LITTLE
template
Output_section*
Layout::init_fixed_output_section<32, false>(
const char* name,
elfcpp::Shdr<32, false>& shdr);
#endif
#ifdef HAVE_TARGET_32_BIG
template
Output_section*
Layout::init_fixed_output_section<32, true>(
const char* name,
elfcpp::Shdr<32, true>& shdr);
#endif
#ifdef HAVE_TARGET_64_LITTLE
template
Output_section*
Layout::init_fixed_output_section<64, false>(
const char* name,
elfcpp::Shdr<64, false>& shdr);
#endif
#ifdef HAVE_TARGET_64_BIG
template
Output_section*
Layout::init_fixed_output_section<64, true>(
const char* name,
elfcpp::Shdr<64, true>& shdr);
#endif
#ifdef HAVE_TARGET_32_LITTLE
template
Output_section*

View File

@ -41,6 +41,7 @@ namespace gold
class General_options;
class Incremental_inputs;
class Incremental_binary;
class Input_objects;
class Mapfile;
class Symbol_table;
@ -64,6 +65,69 @@ struct Timespec;
extern bool
is_compressed_debug_section(const char* secname);
// Maintain a list of free space within a section, segment, or file.
// Used for incremental update links.
class Free_list
{
public:
Free_list()
: list_(), last_remove_(list_.begin()), extend_(false), length_(0)
{ }
void
init(off_t len, bool extend);
void
remove(off_t start, off_t end);
off_t
allocate(off_t len, uint64_t align, off_t minoff);
void
dump();
static void
print_stats();
private:
struct Free_list_node
{
Free_list_node(off_t start, off_t end)
: start_(start), end_(end)
{ }
off_t start_;
off_t end_;
};
typedef std::list<Free_list_node>::iterator Iterator;
// The free list.
std::list<Free_list_node> list_;
// The last node visited during a remove operation.
Iterator last_remove_;
// Whether we can extend past the original length.
bool extend_;
// The total length of the section, segment, or file.
off_t length_;
// Statistics:
// The total number of free lists used.
static unsigned int num_lists;
// The total number of free list nodes used.
static unsigned int num_nodes;
// The total number of calls to Free_list::remove.
static unsigned int num_removes;
// The total number of nodes visited during calls to Free_list::remove.
static unsigned int num_remove_visits;
// The total number of calls to Free_list::allocate.
static unsigned int num_allocates;
// The total number of nodes visited during calls to Free_list::allocate.
static unsigned int num_allocate_visits;
};
// This task function handles mapping the input sections to output
// sections and laying them out in memory.
@ -401,6 +465,20 @@ class Layout
delete this->segment_states_;
}
// For incremental links, record the base file to be modified.
void
set_incremental_base(Incremental_binary* base);
Incremental_binary*
incremental_base()
{ return this->incremental_base_; }
// For incremental links, record the initial fixed layout of a section
// from the base file, and return a pointer to the Output_section.
template<int size, bool big_endian>
Output_section*
init_fixed_output_section(const char*, elfcpp::Shdr<size, big_endian>&);
// Given an input section SHNDX, named NAME, with data in SHDR, from
// the object file OBJECT, return the output section where this
// input section should go. RELOC_SHNDX is the index of a
@ -414,6 +492,12 @@ class Layout
const char* name, const elfcpp::Shdr<size, big_endian>& shdr,
unsigned int reloc_shndx, unsigned int reloc_type, off_t* offset);
// For incremental updates, allocate a block of memory from the
// free list. Find a block starting at or after MINOFF.
off_t
allocate(off_t len, uint64_t align, off_t minoff)
{ return this->free_list_.allocate(len, align, minoff); }
unsigned int
find_section_order_index(const std::string&);
@ -1151,6 +1235,10 @@ class Layout
Unordered_map<std::string, unsigned int> input_section_position_;
// Vector of glob only patterns in the section_ordering file.
std::vector<std::string> input_section_glob_;
// For incremental links, the base file to be modified.
Incremental_binary* incremental_base_;
// For incremental links, a list of free space within the file.
Free_list free_list_;
};
// This task handles writing out data in output sections which is not

View File

@ -269,6 +269,7 @@ main(int argc, char** argv)
program_name, static_cast<long long>(layout.output_file_size()));
symtab.print_stats();
layout.print_stats();
Free_list::print_stats();
}
// Issue defined symbol report.

View File

@ -349,11 +349,11 @@ Relobj::is_section_name_included(const char* name)
// Finalize the incremental relocation information. Allocates a block
// of relocation entries for each symbol, and sets the reloc_bases_
// array to point to the first entry in each block. Returns the next
// available relocation index.
// array to point to the first entry in each block. If CLEAR_COUNTS
// is TRUE, also clear the per-symbol relocation counters.
void
Relobj::finalize_incremental_relocs(Layout* layout)
Relobj::finalize_incremental_relocs(Layout* layout, bool clear_counts)
{
unsigned int nsyms = this->get_global_symbols()->size();
this->reloc_bases_ = new unsigned int[nsyms];
@ -366,7 +366,8 @@ Relobj::finalize_incremental_relocs(Layout* layout)
{
this->reloc_bases_[i] = rindex;
rindex += this->reloc_counts_[i];
this->reloc_counts_[i] = 0;
if (clear_counts)
this->reloc_counts_[i] = 0;
}
layout->incremental_inputs()->set_reloc_count(rindex);
}
@ -379,7 +380,7 @@ Sized_relobj<size, big_endian>::Sized_relobj(
Input_file* input_file,
off_t offset,
const elfcpp::Ehdr<size, big_endian>& ehdr)
: Relobj(name, input_file, offset),
: Sized_relobj_base<size, big_endian>(name, input_file, offset),
elf_file_(this, ehdr),
symtab_shndx_(-1U),
local_symbol_count_(0),
@ -1265,9 +1266,12 @@ Sized_relobj<size, big_endian>::do_layout(Symbol_table* symtab,
// Add the section to the incremental inputs layout.
Incremental_inputs* incremental_inputs = layout->incremental_inputs();
if (incremental_inputs != NULL)
incremental_inputs->report_input_section(this, i,
discard ? NULL : name,
if (incremental_inputs != NULL
&& !discard
&& (shdr.get_sh_type() == elfcpp::SHT_PROGBITS
|| shdr.get_sh_type() == elfcpp::SHT_NOBITS
|| shdr.get_sh_type() == elfcpp::SHT_NOTE))
incremental_inputs->report_input_section(this, i, name,
shdr.get_sh_size());
if (discard)
@ -1281,7 +1285,7 @@ Sized_relobj<size, big_endian>::do_layout(Symbol_table* symtab,
if (is_gc_pass_one && parameters->options().gc_sections())
{
if (is_section_name_included(name)
if (this->is_section_name_included(name)
|| shdr.get_sh_type() == elfcpp::SHT_INIT_ARRAY
|| shdr.get_sh_type() == elfcpp::SHT_FINI_ARRAY)
{
@ -1716,6 +1720,26 @@ Sized_relobj<size, big_endian>::do_for_all_global_symbols(
}
}
// Iterate over local symbols, calling a visitor class V for each GOT offset
// associated with a local symbol.
template<int size, bool big_endian>
void
Sized_relobj<size, big_endian>::do_for_all_local_got_entries(
Got_offset_list::Visitor* v) const
{
unsigned int nsyms = this->local_symbol_count();
for (unsigned int i = 0; i < nsyms; i++)
{
Local_got_offsets::const_iterator p = this->local_got_offsets_.find(i);
if (p != this->local_got_offsets_.end())
{
const Got_offset_list* got_offsets = p->second;
got_offsets->for_all_got_offsets(v);
}
}
}
// Return whether the local symbol SYMNDX has a PLT offset.
template<int size, bool big_endian>
@ -2199,7 +2223,8 @@ Sized_relobj<size, big_endian>::write_local_symbols(
const Stringpool* sympool,
const Stringpool* dynpool,
Output_symtab_xindex* symtab_xindex,
Output_symtab_xindex* dynsym_xindex)
Output_symtab_xindex* dynsym_xindex,
off_t symtab_off)
{
const bool strip_all = parameters->options().strip_all();
if (strip_all)
@ -2244,7 +2269,8 @@ Sized_relobj<size, big_endian>::write_local_symbols(
off_t output_size = this->output_local_symbol_count_ * sym_size;
unsigned char* oview = NULL;
if (output_size > 0)
oview = of->get_output_view(this->local_symbol_offset_, output_size);
oview = of->get_output_view(symtab_off + this->local_symbol_offset_,
output_size);
off_t dyn_output_size = this->output_local_dynsym_count_ * sym_size;
unsigned char* dyn_oview = NULL;
@ -2324,7 +2350,8 @@ Sized_relobj<size, big_endian>::write_local_symbols(
if (output_size > 0)
{
gold_assert(ov - oview == output_size);
of->write_output_view(this->local_symbol_offset_, output_size, oview);
of->write_output_view(symtab_off + this->local_symbol_offset_,
output_size, oview);
}
if (dyn_output_size > 0)
@ -2450,7 +2477,7 @@ Sized_relobj<size, big_endian>::do_get_global_symbol_counts(
{
*defined = this->defined_count_;
size_t count = 0;
for (Symbols::const_iterator p = this->symbols_.begin();
for (typename Symbols::const_iterator p = this->symbols_.begin();
p != this->symbols_.end();
++p)
if (*p != NULL

View File

@ -203,6 +203,117 @@ class Xindex
Symtab_xindex symtab_xindex_;
};
// A GOT offset list. A symbol may have more than one GOT offset
// (e.g., when mixing modules compiled with two different TLS models),
// but will usually have at most one. GOT_TYPE identifies the type of
// GOT entry; its values are specific to each target.
class Got_offset_list
{
public:
Got_offset_list()
: got_type_(-1U), got_offset_(0), got_next_(NULL)
{ }
Got_offset_list(unsigned int got_type, unsigned int got_offset)
: got_type_(got_type), got_offset_(got_offset), got_next_(NULL)
{ }
~Got_offset_list()
{
if (this->got_next_ != NULL)
{
delete this->got_next_;
this->got_next_ = NULL;
}
}
// Initialize the fields to their default values.
void
init()
{
this->got_type_ = -1U;
this->got_offset_ = 0;
this->got_next_ = NULL;
}
// Set the offset for the GOT entry of type GOT_TYPE.
void
set_offset(unsigned int got_type, unsigned int got_offset)
{
if (this->got_type_ == -1U)
{
this->got_type_ = got_type;
this->got_offset_ = got_offset;
}
else
{
for (Got_offset_list* g = this; g != NULL; g = g->got_next_)
{
if (g->got_type_ == got_type)
{
g->got_offset_ = got_offset;
return;
}
}
Got_offset_list* g = new Got_offset_list(got_type, got_offset);
g->got_next_ = this->got_next_;
this->got_next_ = g;
}
}
// Return the offset for a GOT entry of type GOT_TYPE.
unsigned int
get_offset(unsigned int got_type) const
{
for (const Got_offset_list* g = this; g != NULL; g = g->got_next_)
{
if (g->got_type_ == got_type)
return g->got_offset_;
}
return -1U;
}
// Return a pointer to the list, or NULL if the list is empty.
const Got_offset_list*
get_list() const
{
if (this->got_type_ == -1U)
return NULL;
return this;
}
// Abstract visitor class for iterating over GOT offsets.
class Visitor
{
public:
Visitor()
{ }
virtual
~Visitor()
{ }
virtual void
visit(unsigned int, unsigned int) = 0;
};
// Loop over all GOT offset entries, calling a visitor class V for each.
void
for_all_got_offsets(Visitor* v) const
{
if (this->got_type_ == -1U)
return;
for (const Got_offset_list* g = this; g != NULL; g = g->got_next_)
v->visit(g->got_type_, g->got_offset_);
}
private:
unsigned int got_type_;
unsigned int got_offset_;
Got_offset_list* got_next_;
};
// Object is an abstract base class which represents either a 32-bit
// or a 64-bit input object. This can be a regular object file
// (ET_REL) or a shared object (ET_DYN).
@ -220,11 +331,21 @@ class Object
off_t offset = 0)
: name_(name), input_file_(input_file), offset_(offset), shnum_(-1U),
is_dynamic_(is_dynamic), is_needed_(false), uses_split_stack_(false),
has_no_split_stack_(false), no_export_(false), xindex_(NULL)
{ input_file->file().add_object(); }
has_no_split_stack_(false), no_export_(false),
is_in_system_directory_(false), xindex_(NULL)
{
if (input_file != NULL)
{
input_file->file().add_object();
this->is_in_system_directory_ = input_file->is_in_system_directory();
}
}
virtual ~Object()
{ this->input_file_->file().remove_object(); }
{
if (this->input_file_ != NULL)
this->input_file_->file().remove_object();
}
// Return the name of the object as we would report it to the tuser.
const std::string&
@ -274,42 +395,71 @@ class Object
// Get the file. We pass on const-ness.
Input_file*
input_file()
{ return this->input_file_; }
{
gold_assert(this->input_file_ != NULL);
return this->input_file_;
}
const Input_file*
input_file() const
{ return this->input_file_; }
{
gold_assert(this->input_file_ != NULL);
return this->input_file_;
}
// Lock the underlying file.
void
lock(const Task* t)
{ this->input_file()->file().lock(t); }
{
if (this->input_file_ != NULL)
this->input_file_->file().lock(t);
}
// Unlock the underlying file.
void
unlock(const Task* t)
{ this->input_file()->file().unlock(t); }
{
if (this->input_file_ != NULL)
this->input_file()->file().unlock(t);
}
// Return whether the underlying file is locked.
bool
is_locked() const
{ return this->input_file()->file().is_locked(); }
{ return this->input_file_ != NULL && this->input_file_->file().is_locked(); }
// Return the token, so that the task can be queued.
Task_token*
token()
{ return this->input_file()->file().token(); }
{
if (this->input_file_ == NULL)
return NULL;
return this->input_file()->file().token();
}
// Release the underlying file.
void
release()
{ this->input_file_->file().release(); }
{
if (this->input_file_ != NULL)
this->input_file()->file().release();
}
// Return whether we should just read symbols from this file.
bool
just_symbols() const
{ return this->input_file()->just_symbols(); }
// Return whether this is an incremental object.
bool
is_incremental() const
{ return this->do_is_incremental(); }
// Return the last modified time of the file.
Timespec
get_mtime()
{ return this->do_get_mtime(); }
// Get the number of sections.
unsigned int
shnum() const
@ -428,6 +578,12 @@ class Object
Library_base::Symbol_visitor_base* v)
{ return this->do_for_all_global_symbols(sd, v); }
// Iterate over local symbols, calling a visitor class V for each GOT offset
// associated with a local symbol.
void
for_all_local_got_entries(Got_offset_list::Visitor* v) const
{ this->do_for_all_local_got_entries(v); }
// Functions and types for the elfcpp::Elf_file interface. This
// permit us to use Object as the File template parameter for
// elfcpp::Elf_file.
@ -504,7 +660,10 @@ class Object
// Stop caching views in the underlying file.
void
clear_view_cache_marks()
{ this->input_file()->file().clear_view_cache_marks(); }
{
if (this->input_file_ != NULL)
this->input_file_->file().clear_view_cache_marks();
}
// Get the number of global symbols defined by this object, and the
// number of the symbols whose final definition came from this
@ -519,10 +678,15 @@ class Object
get_global_symbols() const
{ return this->do_get_global_symbols(); }
// Set flag that this object was found in a system directory.
void
set_is_in_system_directory()
{ this->is_in_system_directory_ = true; }
// Return whether this object was found in a system directory.
bool
is_in_system_directory() const
{ return this->input_file()->is_in_system_directory(); }
{ return this->is_in_system_directory_; }
// Return whether we found this object by searching a directory.
bool
@ -561,6 +725,20 @@ class Object
do_pluginobj()
{ return NULL; }
// Return TRUE if this is an incremental (unchanged) input file.
// We return FALSE by default; the incremental object classes
// override this method.
virtual bool
do_is_incremental() const
{ return false; }
// Return the last modified time of the file. This method may be
// overridden for subclasses that don't use an actual file (e.g.,
// Incremental objects).
virtual Timespec
do_get_mtime()
{ return this->input_file()->file().get_mtime(); }
// Read the symbols--implemented by child class.
virtual void
do_read_symbols(Read_symbols_data*) = 0;
@ -583,6 +761,11 @@ class Object
do_for_all_global_symbols(Read_symbols_data* sd,
Library_base::Symbol_visitor_base* v) = 0;
// Iterate over local symbols, calling a visitor class V for each GOT offset
// associated with a local symbol.
virtual void
do_for_all_local_got_entries(Got_offset_list::Visitor* v) const = 0;
// Return the location of the contents of a section. Implemented by
// child class.
virtual Location
@ -726,6 +909,8 @@ class Object
// True if exclude this object from automatic symbol export.
// This is used only for archive objects.
bool no_export_ : 1;
// True if the object was found in a system directory.
bool is_in_system_directory_ : 1;
// Many sections for objects with more than SHN_LORESERVE sections.
Xindex* xindex_;
};
@ -1019,7 +1204,7 @@ class Relobj : public Object
// Finalize the incremental relocation information.
void
finalize_incremental_relocs(Layout* layout);
finalize_incremental_relocs(Layout* layout, bool clear_counts);
// Return the index of the next relocation to be written for global symbol
// SYMNDX. Only valid after finalize_incremental_relocs() has been called.
@ -1443,103 +1628,6 @@ class Symbol_value
} u_;
};
// A GOT offset list. A symbol may have more than one GOT offset
// (e.g., when mixing modules compiled with two different TLS models),
// but will usually have at most one. GOT_TYPE identifies the type of
// GOT entry; its values are specific to each target.
class Got_offset_list
{
public:
Got_offset_list()
: got_type_(-1U), got_offset_(0), got_next_(NULL)
{ }
Got_offset_list(unsigned int got_type, unsigned int got_offset)
: got_type_(got_type), got_offset_(got_offset), got_next_(NULL)
{ }
~Got_offset_list()
{
if (this->got_next_ != NULL)
{
delete this->got_next_;
this->got_next_ = NULL;
}
}
// Initialize the fields to their default values.
void
init()
{
this->got_type_ = -1U;
this->got_offset_ = 0;
this->got_next_ = NULL;
}
// Set the offset for the GOT entry of type GOT_TYPE.
void
set_offset(unsigned int got_type, unsigned int got_offset)
{
if (this->got_type_ == -1U)
{
this->got_type_ = got_type;
this->got_offset_ = got_offset;
}
else
{
for (Got_offset_list* g = this; g != NULL; g = g->got_next_)
{
if (g->got_type_ == got_type)
{
g->got_offset_ = got_offset;
return;
}
}
Got_offset_list* g = new Got_offset_list(got_type, got_offset);
g->got_next_ = this->got_next_;
this->got_next_ = g;
}
}
// Return the offset for a GOT entry of type GOT_TYPE.
unsigned int
get_offset(unsigned int got_type) const
{
for (const Got_offset_list* g = this; g != NULL; g = g->got_next_)
{
if (g->got_type_ == got_type)
return g->got_offset_;
}
return -1U;
}
// Return a pointer to the list, or NULL if the list is empty.
const Got_offset_list*
get_list() const
{
if (this->got_type_ == -1U)
return NULL;
return this;
}
// Loop over all GOT offset entries, applying the function F to each.
template<typename F>
void
for_all_got_offsets(F f) const
{
if (this->got_type_ == -1U)
return;
for (const Got_offset_list* g = this; g != NULL; g = g->got_next_)
f(g->got_type_, g->got_offset_);
}
private:
unsigned int got_type_;
unsigned int got_offset_;
Got_offset_list* got_next_;
};
// This type is used to modify relocations for -fsplit-stack. It is
// indexed by relocation index, and means that the relocation at that
// index should use the symbol from the vector, rather than the one
@ -1568,14 +1656,41 @@ class Reloc_symbol_changes
typedef std::map<unsigned int, section_size_type> Compressed_section_map;
// Abstract base class for a regular object file, either a real object file
// or an incremental (unchanged) object. This is size and endian specific.
template<int size, bool big_endian>
class Sized_relobj_base : public Relobj
{
public:
typedef Relobj::Symbols Symbols;
Sized_relobj_base(const std::string& name, Input_file* input_file)
: Relobj(name, input_file)
{ }
Sized_relobj_base(const std::string& name, Input_file* input_file,
off_t offset)
: Relobj(name, input_file, offset)
{ }
~Sized_relobj_base()
{ }
protected:
typedef Relobj::Output_sections Output_sections;
private:
};
// A regular object file. This is size and endian specific.
template<int size, bool big_endian>
class Sized_relobj : public Relobj
class Sized_relobj : public Sized_relobj_base<size, big_endian>
{
public:
typedef typename elfcpp::Elf_types<size>::Elf_Addr Address;
typedef std::vector<Symbol*> Symbols;
typedef typename Sized_relobj_base<size, big_endian>::Symbols Symbols;
typedef std::vector<Symbol_value<size> > Local_values;
static const Address invalid_address = static_cast<Address>(0) - 1;
@ -1726,17 +1841,6 @@ class Sized_relobj : public Relobj
}
}
// Return the GOT offset list for the local symbol SYMNDX.
const Got_offset_list*
local_got_offset_list(unsigned int symndx) const
{
Local_got_offsets::const_iterator p =
this->local_got_offsets_.find(symndx);
if (p == this->local_got_offsets_.end())
return NULL;
return p->second;
}
// Return whether the local symbol SYMNDX has a PLT offset.
bool
local_has_plt_offset(unsigned int symndx) const;
@ -1791,6 +1895,9 @@ class Sized_relobj : public Relobj
const Symbol_table* symtab);
protected:
typedef typename Sized_relobj_base<size, big_endian>::Output_sections
Output_sections;
// Set up.
virtual void
do_setup();
@ -1826,6 +1933,11 @@ class Sized_relobj : public Relobj
do_for_all_global_symbols(Read_symbols_data* sd,
Library_base::Symbol_visitor_base* v);
// Iterate over local symbols, calling a visitor class V for each GOT offset
// associated with a local symbol.
void
do_for_all_local_got_entries(Got_offset_list::Visitor* v) const;
// Read the relocs.
void
do_read_relocs(Read_relocs_data*);
@ -2179,7 +2291,8 @@ class Sized_relobj : public Relobj
const Stringpool_template<char>*,
const Stringpool_template<char>*,
Output_symtab_xindex*,
Output_symtab_xindex*);
Output_symtab_xindex*,
off_t);
// Record a mapping from discarded section SHNDX to the corresponding
// kept section.
@ -2269,9 +2382,9 @@ class Sized_relobj : public Relobj
Symbols symbols_;
// Number of symbols defined in object file itself.
size_t defined_count_;
// File offset for local symbols.
// File offset for local symbols (relative to start of symbol table).
off_t local_symbol_offset_;
// File offset for local dynamic symbols.
// File offset for local dynamic symbols (absolute).
off_t local_dynsym_offset_;
// Values of local symbols.
Local_values local_values_;

View File

@ -1215,8 +1215,9 @@ Search_directory::add_sysroot(const char* sysroot,
// Add a file to the list.
Input_argument&
Input_arguments::add_file(const Input_file_argument& file)
Input_arguments::add_file(Input_file_argument& file)
{
file.set_arg_serial(++this->file_count_);
if (this->in_group_)
{
gold_assert(!this->input_argument_list_.empty());

View File

@ -57,6 +57,7 @@ class Input_file_lib;
class Position_dependent_options;
class Target;
class Plugin_manager;
class Script_info;
// Incremental build action for a specific file, as selected by the user.
@ -1519,7 +1520,7 @@ class Input_file_argument
// command line, such as --whole-archive.
Input_file_argument()
: name_(), type_(INPUT_FILE_TYPE_FILE), extra_search_path_(""),
just_symbols_(false), options_()
just_symbols_(false), options_(), arg_serial_(0)
{ }
Input_file_argument(const char* name, Input_file_type type,
@ -1527,7 +1528,7 @@ class Input_file_argument
bool just_symbols,
const Position_dependent_options& options)
: name_(name), type_(type), extra_search_path_(extra_search_path),
just_symbols_(just_symbols), options_(options)
just_symbols_(just_symbols), options_(options), arg_serial_(0)
{ }
// You can also pass in a General_options instance instead of a
@ -1539,7 +1540,7 @@ class Input_file_argument
bool just_symbols,
const General_options& options)
: name_(name), type_(type), extra_search_path_(extra_search_path),
just_symbols_(just_symbols), options_(options)
just_symbols_(just_symbols), options_(options), arg_serial_(0)
{ }
const char*
@ -1581,6 +1582,16 @@ class Input_file_argument
|| !this->extra_search_path_.empty());
}
// Set the serial number for this argument.
void
set_arg_serial(unsigned int arg_serial)
{ this->arg_serial_ = arg_serial; }
// Get the serial number.
unsigned int
arg_serial() const
{ return this->arg_serial_; }
private:
// We use std::string, not const char*, here for convenience when
// using script files, so that we do not have to preserve the string
@ -1590,6 +1601,8 @@ class Input_file_argument
std::string extra_search_path_;
bool just_symbols_;
Position_dependent_options options_;
// A unique index for this file argument in the argument list.
unsigned int arg_serial_;
};
// A file or library, or a group, from the command line.
@ -1772,12 +1785,12 @@ class Input_arguments
typedef Input_argument_list::const_iterator const_iterator;
Input_arguments()
: input_argument_list_(), in_group_(false), in_lib_(false)
: input_argument_list_(), in_group_(false), in_lib_(false), file_count_(0)
{ }
// Add a file.
Input_argument&
add_file(const Input_file_argument& arg);
add_file(Input_file_argument& arg);
// Start a group (the --start-group option).
void
@ -1825,10 +1838,18 @@ class Input_arguments
empty() const
{ return this->input_argument_list_.empty(); }
// Return the number of input files. This may be larger than
// input_argument_list_.size(), because of files that are part
// of groups or libs.
int
number_of_input_files() const
{ return this->file_count_; }
private:
Input_argument_list input_argument_list_;
bool in_group_;
bool in_lib_;
unsigned int file_count_;
};
@ -1885,7 +1906,7 @@ class Command_line
// The number of input files.
int
number_of_input_files() const
{ return this->inputs_.size(); }
{ return this->inputs_.number_of_input_files(); }
// Iterators to iterate over the list of input files.

View File

@ -280,6 +280,7 @@ Output_segment_headers::Output_segment_headers(
const Layout::Segment_list& segment_list)
: segment_list_(segment_list)
{
this->set_current_data_size_for_child(this->do_size());
}
void
@ -1794,6 +1795,21 @@ Output_symtab_xindex::endian_do_write(unsigned char* const oview)
// Output_section::Input_section methods.
// Return the current data size. For an input section we store the size here.
// For an Output_section_data, we have to ask it for the size.
off_t
Output_section::Input_section::current_data_size() const
{
if (this->is_input_section())
return this->u1_.data_size;
else
{
this->u2_.posd->pre_finalize_data_size();
return this->u2_.posd->current_data_size();
}
}
// Return the data size. For an input section we store the size here.
// For an Output_section_data, we have to ask it for the size.
@ -2003,9 +2019,11 @@ Output_section::Output_section(const char* name, elfcpp::Elf_Word type,
section_offsets_need_adjustment_(false),
is_noload_(false),
always_keeps_input_sections_(false),
has_fixed_layout_(false),
tls_offset_(0),
checkpoint_(NULL),
lookup_maps_(new Output_section_lookup_maps)
lookup_maps_(new Output_section_lookup_maps),
free_list_()
{
// An unallocated section has no address. Forcing this means that
// we don't need special treatment for symbols defined in debug
@ -2086,9 +2104,11 @@ Output_section::add_input_section(Layout* layout,
// a Output_data_merge. We don't try to handle relocations for such
// a section. We don't try to handle empty merge sections--they
// mess up the mappings, and are useless anyhow.
// FIXME: Need to handle merge sections during incremental update.
if ((sh_flags & elfcpp::SHF_MERGE) != 0
&& reloc_shndx == 0
&& shdr.get_sh_size() > 0)
&& shdr.get_sh_size() > 0
&& !parameters->incremental())
{
// Keep information about merged input sections for rebuilding fast
// lookup maps if we have sections-script or we do relaxation.
@ -2105,9 +2125,30 @@ Output_section::add_input_section(Layout* layout,
}
}
off_t offset_in_section = this->current_data_size_for_child();
off_t aligned_offset_in_section = align_address(offset_in_section,
addralign);
section_size_type input_section_size = shdr.get_sh_size();
section_size_type uncompressed_size;
if (object->section_is_compressed(shndx, &uncompressed_size))
input_section_size = uncompressed_size;
off_t offset_in_section;
off_t aligned_offset_in_section;
if (this->has_fixed_layout())
{
// For incremental updates, find a chunk of unused space in the section.
offset_in_section = this->free_list_.allocate(input_section_size,
addralign, 0);
if (offset_in_section == -1)
gold_fatal(_("out of patch space; relink with --incremental-full"));
aligned_offset_in_section = offset_in_section;
}
else
{
offset_in_section = this->current_data_size_for_child();
aligned_offset_in_section = align_address(offset_in_section,
addralign);
this->set_current_data_size_for_child(aligned_offset_in_section
+ input_section_size);
}
// Determine if we want to delay code-fill generation until the output
// section is written. When the target is relaxing, we want to delay fill
@ -2144,14 +2185,6 @@ Output_section::add_input_section(Layout* layout,
}
}
section_size_type input_section_size = shdr.get_sh_size();
section_size_type uncompressed_size;
if (object->section_is_compressed(shndx, &uncompressed_size))
input_section_size = uncompressed_size;
this->set_current_data_size_for_child(aligned_offset_in_section
+ input_section_size);
// We need to keep track of this section if we are already keeping
// track of sections, or if we are relaxing. Also, if this is a
// section which requires sorting, or which may require sorting in
@ -2178,6 +2211,14 @@ Output_section::add_input_section(Layout* layout,
this->set_input_section_order_specified();
}
}
if (this->has_fixed_layout())
{
// For incremental updates, finalize the address and offset now.
uint64_t addr = this->address();
isecn.set_address_and_file_offset(addr + aligned_offset_in_section,
aligned_offset_in_section,
this->offset());
}
this->input_sections_.push_back(isecn);
}
@ -2194,11 +2235,38 @@ Output_section::add_output_section_data(Output_section_data* posd)
if (posd->is_data_size_valid())
{
off_t offset_in_section = this->current_data_size_for_child();
off_t aligned_offset_in_section = align_address(offset_in_section,
posd->addralign());
this->set_current_data_size_for_child(aligned_offset_in_section
+ posd->data_size());
off_t offset_in_section;
if (this->has_fixed_layout())
{
// For incremental updates, find a chunk of unused space.
offset_in_section = this->free_list_.allocate(posd->data_size(),
posd->addralign(), 0);
if (offset_in_section == -1)
gold_fatal(_("out of patch space; relink with --incremental-full"));
// Finalize the address and offset now.
uint64_t addr = this->address();
off_t offset = this->offset();
posd->set_address_and_file_offset(addr + offset_in_section,
offset + offset_in_section);
}
else
{
offset_in_section = this->current_data_size_for_child();
off_t aligned_offset_in_section = align_address(offset_in_section,
posd->addralign());
this->set_current_data_size_for_child(aligned_offset_in_section
+ posd->data_size());
}
}
else if (this->has_fixed_layout())
{
// For incremental updates, arrange for the data to have a fixed layout.
// This will mean that additions to the data must be allocated from
// free space within the containing output section.
uint64_t addr = this->address();
posd->set_address(addr);
posd->set_file_offset(0);
// FIXME: Mark *POSD as part of a fixed-layout section.
}
}
@ -2713,6 +2781,30 @@ Output_section::find_starting_output_address(const Relobj* object,
return false;
}
// Update the data size of an Output_section.
void
Output_section::update_data_size()
{
if (this->input_sections_.empty())
return;
if (this->must_sort_attached_input_sections()
|| this->input_section_order_specified())
this->sort_attached_input_sections();
off_t off = this->first_input_offset_;
for (Input_section_list::iterator p = this->input_sections_.begin();
p != this->input_sections_.end();
++p)
{
off = align_address(off, p->addralign());
off += p->current_data_size();
}
this->set_current_data_size_for_child(off);
}
// Set the data size of an Output_section. This is where we handle
// setting the addresses of any Output_section_data objects.
@ -3483,6 +3575,30 @@ Output_section::print_merge_stats()
p->print_merge_stats(this->name_);
}
// Set a fixed layout for the section. Used for incremental update links.
void
Output_section::set_fixed_layout(uint64_t sh_addr, off_t sh_offset,
off_t sh_size, uint64_t sh_addralign)
{
this->addralign_ = sh_addralign;
this->set_current_data_size(sh_size);
if ((this->flags_ & elfcpp::SHF_ALLOC) != 0)
this->set_address(sh_addr);
this->set_file_offset(sh_offset);
this->finalize_data_size();
this->free_list_.init(sh_size, false);
this->has_fixed_layout_ = true;
}
// Reserve space within the fixed layout for the section. Used for
// incremental update links.
void
Output_section::reserve(uint64_t sh_offset, uint64_t sh_size)
{
this->free_list_.remove(sh_offset, sh_offset + sh_size);
}
// Output segment methods.
Output_segment::Output_segment(elfcpp::Elf_Word type, elfcpp::Elf_Word flags)
@ -3692,7 +3808,7 @@ Output_segment::has_dynamic_reloc_list(const Output_data_list* pdl) const
// and *PSHNDX.
uint64_t
Output_segment::set_section_addresses(const Layout* layout, bool reset,
Output_segment::set_section_addresses(Layout* layout, bool reset,
uint64_t addr,
unsigned int* increase_relro,
bool* has_relro,
@ -3839,13 +3955,16 @@ Output_segment::set_section_addresses(const Layout* layout, bool reset,
// structures.
uint64_t
Output_segment::set_section_list_addresses(const Layout* layout, bool reset,
Output_segment::set_section_list_addresses(Layout* layout, bool reset,
Output_data_list* pdl,
uint64_t addr, off_t* poff,
unsigned int* pshndx,
bool* in_tls)
{
off_t startoff = *poff;
// For incremental updates, we may allocate non-fixed sections from
// free space in the file. This keeps track of the high-water mark.
off_t maxoff = startoff;
off_t off = startoff;
for (Output_data_list::iterator p = pdl->begin();
@ -3855,8 +3974,8 @@ Output_segment::set_section_list_addresses(const Layout* layout, bool reset,
if (reset)
(*p)->reset_address_and_file_offset();
// When using a linker script the section will most likely
// already have an address.
// When doing an incremental update or when using a linker script,
// the section will most likely already have an address.
if (!(*p)->is_address_valid())
{
uint64_t align = (*p)->addralign();
@ -3894,9 +4013,43 @@ Output_segment::set_section_list_addresses(const Layout* layout, bool reset,
}
}
off = align_address(off, align);
(*p)->set_address_and_file_offset(addr + (off - startoff), off);
// FIXME: Need to handle TLS and .bss with incremental update.
if (!parameters->incremental_update()
|| (*p)->is_section_flag_set(elfcpp::SHF_TLS)
|| (*p)->is_section_type(elfcpp::SHT_NOBITS))
{
off = align_address(off, align);
(*p)->set_address_and_file_offset(addr + (off - startoff), off);
}
else
{
// Incremental update: allocate file space from free list.
(*p)->pre_finalize_data_size();
off_t current_size = (*p)->current_data_size();
off = layout->allocate(current_size, align, startoff);
if (off == -1)
{
gold_assert((*p)->output_section() != NULL);
gold_fatal(_("out of patch space for section %s; "
"relink with --incremental-full"),
(*p)->output_section()->name());
}
(*p)->set_address_and_file_offset(addr + (off - startoff), off);
if ((*p)->data_size() > current_size)
{
gold_assert((*p)->output_section() != NULL);
gold_fatal(_("%s: section changed size; "
"relink with --incremental-full"),
(*p)->output_section()->name());
}
}
}
else if (parameters->incremental_update())
{
// For incremental updates, use the fixed offset for the
// high-water mark computation.
off = (*p)->offset();
}
else
{
// The script may have inserted a skip forward, but it
@ -3930,6 +4083,13 @@ Output_segment::set_section_list_addresses(const Layout* layout, bool reset,
(*p)->finalize_data_size();
}
gold_debug(DEBUG_INCREMENTAL,
"set_section_list_addresses: %08lx %08lx %s",
static_cast<long>(off),
static_cast<long>((*p)->data_size()),
((*p)->output_section() != NULL
? (*p)->output_section()->name() : "(special)"));
// We want to ignore the size of a SHF_TLS or SHT_NOBITS
// section. Such a section does not affect the size of a
// PT_LOAD segment.
@ -3937,6 +4097,9 @@ Output_segment::set_section_list_addresses(const Layout* layout, bool reset,
|| !(*p)->is_section_type(elfcpp::SHT_NOBITS))
off += (*p)->data_size();
if (off > maxoff)
maxoff = off;
if ((*p)->is_section())
{
(*p)->set_out_shndx(*pshndx);
@ -3944,8 +4107,8 @@ Output_segment::set_section_list_addresses(const Layout* layout, bool reset,
}
}
*poff = off;
return addr + (off - startoff);
*poff = maxoff;
return addr + (maxoff - startoff);
}
// For a non-PT_LOAD segment, set the offset from the sections, if
@ -4029,7 +4192,15 @@ Output_segment::set_offset(unsigned int increase)
{
uint64_t page_align = parameters->target().common_pagesize();
uint64_t segment_end = this->vaddr_ + this->memsz_;
gold_assert(segment_end == align_address(segment_end, page_align));
if (parameters->incremental_update())
{
// The INCREASE_RELRO calculation is bypassed for an incremental
// update, so we need to adjust the segment size manually here.
segment_end = align_address(segment_end, page_align);
this->memsz_ = segment_end - this->vaddr_;
}
else
gold_assert(segment_end == align_address(segment_end, page_align));
}
// If this is a TLS segment, align the memory size. The code in

View File

@ -81,6 +81,11 @@ class Output_data
return this->data_size_;
}
// Get the current data size.
off_t
current_data_size() const
{ return this->current_data_size_for_child(); }
// Return true if data size is fixed.
bool
is_data_size_fixed() const
@ -193,6 +198,17 @@ class Output_data
this->is_offset_valid_ = true;
}
// Update the data size without finalizing it.
void
pre_finalize_data_size()
{
if (!this->is_data_size_valid_)
{
// Tell the child class to update the data size.
this->update_data_size();
}
}
// Finalize the data size.
void
finalize_data_size()
@ -320,6 +336,17 @@ class Output_data
do_set_out_shndx(unsigned int)
{ gold_unreachable(); }
// This is a hook for derived classes to set the preliminary data size.
// This is called by pre_finalize_data_size, normally called during
// Layout::finalize, before the section address is set, and is used
// during an incremental update, when we need to know the size of a
// section before allocating space in the output file. For classes
// where the current data size is up to date, this default version of
// the method can be inherited.
virtual void
update_data_size()
{ }
// This is a hook for derived classes to set the data size. This is
// called by finalize_data_size, normally called during
// Layout::finalize, when the section address is set.
@ -462,6 +489,11 @@ class Output_section_headers : public Output_data
do_print_to_mapfile(Mapfile* mapfile) const
{ mapfile->print_output_data(this, _("** section headers")); }
// Update the data size.
void
update_data_size()
{ this->set_data_size(this->do_size()); }
// Set final data size.
void
set_final_data_size()
@ -732,11 +764,6 @@ class Output_section_data_build : public Output_section_data
: Output_section_data(addralign)
{ }
// Get the current data size.
off_t
current_data_size() const
{ return this->current_data_size_for_child(); }
// Set the current data size.
void
set_current_data_size(off_t data_size)
@ -918,6 +945,12 @@ class Output_data_strtab : public Output_section_data
{ }
protected:
// This is called to update the section size prior to assigning
// the address and file offset.
void
update_data_size()
{ this->set_final_data_size(); }
// This is called to set the address and file offset. Here we make
// sure that the Stringpool is finalized.
void
@ -3035,6 +3068,10 @@ class Output_section : public Output_data
}
}
// Return the current required size, without finalization.
off_t
current_data_size() const;
// Return the required size.
off_t
data_size() const;
@ -3258,11 +3295,6 @@ class Output_section : public Output_data
set_current_data_size(off_t size)
{ this->set_current_data_size_for_child(size); }
// Get the current size of the output section.
off_t
current_data_size() const
{ return this->current_data_size_for_child(); }
// End of linker script support.
// Save states before doing section layout.
@ -3317,6 +3349,21 @@ class Output_section : public Output_data
void
print_merge_stats();
// Set a fixed layout for the section. Used for incremental update links.
void
set_fixed_layout(uint64_t sh_addr, off_t sh_offset, off_t sh_size,
uint64_t sh_addralign);
// Return TRUE if the section has a fixed layout.
bool
has_fixed_layout() const
{ return this->has_fixed_layout_; }
// Reserve space within the fixed layout for the section. Used for
// incremental update links.
void
reserve(uint64_t sh_offset, uint64_t sh_size);
protected:
// Return the output section--i.e., the object itself.
Output_section*
@ -3343,6 +3390,13 @@ class Output_section : public Output_data
this->out_shndx_ = shndx;
}
// Update the data size of the Output_section. For a typical
// Output_section, there is nothing to do, but if there are any
// Output_section_data objects we need to do a trial layout
// here.
virtual void
update_data_size();
// Set the final data size of the Output_section. For a typical
// Output_section, there is nothing to do, but if there are any
// Output_section_data objects we need to set their final addresses
@ -3761,6 +3815,8 @@ class Output_section : public Output_data
bool is_noload_ : 1;
// Whether this always keeps input section.
bool always_keeps_input_sections_ : 1;
// Whether this section has a fixed layout, for incremental update links.
bool has_fixed_layout_ : 1;
// For SHT_TLS sections, the offset of this section relative to the base
// of the TLS segment.
uint64_t tls_offset_;
@ -3768,6 +3824,9 @@ class Output_section : public Output_data
Checkpoint_output_section* checkpoint_;
// Fast lookup maps for merged and relaxed input sections.
Output_section_lookup_maps* lookup_maps_;
// List of available regions within the section, for incremental
// update links.
Free_list free_list_;
};
// An output segment. PT_LOAD segments are built from collections of
@ -3910,7 +3969,7 @@ class Output_segment
// address of the immediately following segment. Update *POFF and
// *PSHNDX. This should only be called for a PT_LOAD segment.
uint64_t
set_section_addresses(const Layout*, bool reset, uint64_t addr,
set_section_addresses(Layout*, bool reset, uint64_t addr,
unsigned int* increase_relro, bool* has_relro,
off_t* poff, unsigned int* pshndx);
@ -3970,7 +4029,7 @@ class Output_segment
// Set the section addresses in an Output_data_list.
uint64_t
set_section_list_addresses(const Layout*, bool reset, Output_data_list*,
set_section_list_addresses(Layout*, bool reset, Output_data_list*,
uint64_t addr, off_t* poff, unsigned int* pshndx,
bool* in_tls);

View File

@ -1001,6 +1001,16 @@ Sized_pluginobj<size, big_endian>::do_for_all_global_symbols(
}
}
// Iterate over local symbols, calling a visitor class V for each GOT offset
// associated with a local symbol.
template<int size, bool big_endian>
void
Sized_pluginobj<size, big_endian>::do_for_all_local_got_entries(
Got_offset_list::Visitor*) const
{
gold_unreachable();
}
// Get the size of a section. Not used for plugin objects.
template<int size, bool big_endian>

View File

@ -454,6 +454,11 @@ class Sized_pluginobj : public Pluginobj
do_for_all_global_symbols(Read_symbols_data* sd,
Library_base::Symbol_visitor_base* v);
// Iterate over local symbols, calling a visitor class V for each GOT offset
// associated with a local symbol.
void
do_for_all_local_got_entries(Got_offset_list::Visitor* v) const;
// Get the size of a section.
uint64_t
do_section_size(unsigned int shndx);

View File

@ -347,6 +347,7 @@ Read_symbols::do_read_symbols(Workqueue* workqueue)
this->mapfile_,
this->input_argument_,
obj,
NULL,
NULL,
this->this_blocker_,
this->next_blocker_));
@ -397,6 +398,8 @@ Read_symbols::do_read_symbols(Workqueue* workqueue)
{
this->member_->sd_ = sd;
this->member_->obj_ = obj;
this->member_->arg_serial_ =
this->input_argument_->file().arg_serial();
return true;
}
@ -410,6 +413,7 @@ Read_symbols::do_read_symbols(Workqueue* workqueue)
this->mapfile_,
this->input_argument_,
obj,
NULL,
sd,
this->this_blocker_,
this->next_blocker_));
@ -563,7 +567,9 @@ void
Add_symbols::locks(Task_locker* tl)
{
tl->add(this, this->next_blocker_);
tl->add(this, this->object_->token());
Task_token* token = this->object_->token();
if (token != NULL)
tl->add(this, token);
}
// Add the symbols in the object to the symbol table.
@ -580,6 +586,7 @@ Add_symbols::run(Workqueue*)
if (!this->input_objects_->add_object(this->object_))
{
gold_assert(this->sd_ != NULL);
delete this->sd_;
this->sd_ = NULL;
this->object_->release();
@ -590,8 +597,23 @@ Add_symbols::run(Workqueue*)
Incremental_inputs* incremental_inputs =
this->layout_->incremental_inputs();
if (incremental_inputs != NULL)
incremental_inputs->report_object(this->object_, NULL,
this->input_argument_->script_info());
{
if (this->library_ != NULL && !this->library_->is_reported())
{
Incremental_binary* ibase = this->layout_->incremental_base();
gold_assert(ibase != NULL);
unsigned int lib_serial = this->library_->arg_serial();
unsigned int lib_index = this->library_->input_file_index();
Script_info* lib_script_info = ibase->get_script_info(lib_index);
incremental_inputs->report_archive_begin(this->library_,
lib_serial,
lib_script_info);
}
unsigned int arg_serial = this->input_argument_->file().arg_serial();
Script_info* script_info = this->input_argument_->script_info();
incremental_inputs->report_object(this->object_, arg_serial,
this->library_, script_info);
}
this->object_->layout(this->symtab_, this->layout_, this->sd_);
this->object_->add_symbols(this->symtab_, this->sd_, this->layout_);
delete this->sd_;
@ -600,6 +622,127 @@ Add_symbols::run(Workqueue*)
}
}
// Class Read_member.
Read_member::~Read_member()
{
if (this->this_blocker_ != NULL)
delete this->this_blocker_;
// next_blocker_ is deleted by the task associated with the next
// input file.
}
// Return whether a Read_member task is runnable.
Task_token*
Read_member::is_runnable()
{
return NULL;
}
void
Read_member::locks(Task_locker* tl)
{
tl->add(this, this->next_blocker_);
}
// Run a Read_member task.
void
Read_member::run(Workqueue*)
{
// This task doesn't need to do anything for now. The Read_symbols task
// that is queued for the archive library will cause the archive to be
// processed from scratch.
}
// Class Check_script.
Check_script::~Check_script()
{
if (this->this_blocker_ != NULL)
delete this->this_blocker_;
// next_blocker_ is deleted by the task associated with the next
// input file.
}
// Return whether a Check_script task is runnable.
Task_token*
Check_script::is_runnable()
{
if (this->this_blocker_ != NULL && this->this_blocker_->is_blocked())
return this->this_blocker_;
return NULL;
}
void
Check_script::locks(Task_locker* tl)
{
tl->add(this, this->next_blocker_);
}
// Run a Check_script task.
void
Check_script::run(Workqueue*)
{
Incremental_inputs* incremental_inputs = this->layout_->incremental_inputs();
gold_assert(incremental_inputs != NULL);
unsigned int arg_serial = this->input_reader_->arg_serial();
Script_info* script_info =
this->ibase_->get_script_info(this->input_file_index_);
Timespec mtime = this->input_reader_->get_mtime();
incremental_inputs->report_script(script_info, arg_serial, mtime);
}
// Class Check_library.
Check_library::~Check_library()
{
if (this->this_blocker_ != NULL)
delete this->this_blocker_;
// next_blocker_ is deleted by the task associated with the next
// input file.
}
// Return whether a Check_library task is runnable.
Task_token*
Check_library::is_runnable()
{
if (this->this_blocker_ != NULL && this->this_blocker_->is_blocked())
return this->this_blocker_;
return NULL;
}
void
Check_library::locks(Task_locker* tl)
{
tl->add(this, this->next_blocker_);
}
// Run a Check_library task.
void
Check_library::run(Workqueue*)
{
Incremental_inputs* incremental_inputs = this->layout_->incremental_inputs();
gold_assert(incremental_inputs != NULL);
Incremental_library* lib = this->ibase_->get_library(this->input_file_index_);
gold_assert(lib != NULL);
lib->copy_unused_symbols();
// FIXME: Check that unused symbols remain unused.
if (!lib->is_reported())
{
unsigned int lib_serial = lib->arg_serial();
unsigned int lib_index = lib->input_file_index();
Script_info* script_info = this->ibase_->get_script_info(lib_index);
incremental_inputs->report_archive_begin(lib, lib_serial, script_info);
}
incremental_inputs->report_archive_end(lib);
}
// Class Input_group.
// When we delete an Input_group we can delete the archive

View File

@ -27,6 +27,7 @@
#include "workqueue.h"
#include "object.h"
#include "incremental.h"
namespace gold
{
@ -138,14 +139,13 @@ class Add_symbols : public Task
Add_symbols(Input_objects* input_objects, Symbol_table* symtab,
Layout* layout, Dirsearch* dirpath, int dirindex,
Mapfile* mapfile, const Input_argument* input_argument,
Object* object,
Object* object, Incremental_library* library,
Read_symbols_data* sd, Task_token* this_blocker,
Task_token* next_blocker)
: input_objects_(input_objects), symtab_(symtab), layout_(layout),
dirpath_(dirpath), dirindex_(dirindex), mapfile_(mapfile),
input_argument_(input_argument),
object_(object), sd_(sd), this_blocker_(this_blocker),
next_blocker_(next_blocker)
input_argument_(input_argument), object_(object), library_(library),
sd_(sd), this_blocker_(this_blocker), next_blocker_(next_blocker)
{ }
~Add_symbols();
@ -174,11 +174,153 @@ private:
Mapfile* mapfile_;
const Input_argument* input_argument_;
Object* object_;
Incremental_library* library_;
Read_symbols_data* sd_;
Task_token* this_blocker_;
Task_token* next_blocker_;
};
// This Task is responsible for reading the symbols from an archive
// member that has changed since the last incremental link.
class Read_member : public Task
{
public:
// INPUT is the file to read. INPUT_GROUP is not NULL if we are in
// the middle of an input group. THIS_BLOCKER is used to prevent
// the associated Add_symbols task from running before the previous
// one has completed; it will be NULL for the first task.
// NEXT_BLOCKER is used to block the next input file from adding
// symbols.
Read_member(Input_objects* input_objects, Symbol_table* symtab,
Layout* layout, Mapfile* mapfile,
const Incremental_binary::Input_reader* input_reader,
Task_token* this_blocker, Task_token* next_blocker)
: input_objects_(input_objects), symtab_(symtab), layout_(layout),
mapfile_(mapfile), input_reader_(input_reader),
this_blocker_(this_blocker), next_blocker_(next_blocker)
{ }
~Read_member();
// The standard Task methods.
Task_token*
is_runnable();
void
locks(Task_locker*);
void
run(Workqueue*);
std::string
get_name() const
{
return (std::string("Read_member ") + this->input_reader_->filename());
}
private:
Input_objects* input_objects_;
Symbol_table* symtab_;
Layout* layout_;
Mapfile* mapfile_;
const Incremental_binary::Input_reader* input_reader_;
Task_token* this_blocker_;
Task_token* next_blocker_;
};
// This Task is responsible for processing an input script file that has
// not changed since the last incremental link.
class Check_script : public Task
{
public:
Check_script(Layout* layout, Incremental_binary* ibase,
unsigned int input_file_index,
const Incremental_binary::Input_reader* input_reader,
Task_token* this_blocker, Task_token* next_blocker)
: layout_(layout), ibase_(ibase), input_file_index_(input_file_index),
input_reader_(input_reader), this_blocker_(this_blocker),
next_blocker_(next_blocker)
{
this->filename_ = std::string(this->input_reader_->filename());
}
~Check_script();
// The standard Task methods.
Task_token*
is_runnable();
void
locks(Task_locker*);
void
run(Workqueue*);
std::string
get_name() const
{
return (std::string("Check_script ") + this->input_reader_->filename());
}
private:
std::string filename_;
Layout* layout_;
Incremental_binary* ibase_;
unsigned int input_file_index_;
const Incremental_binary::Input_reader* input_reader_;
Task_token* this_blocker_;
Task_token* next_blocker_;
};
// This Task is responsible for processing an archive library that has
// not changed since the last incremental link.
class Check_library : public Task
{
public:
Check_library(Symbol_table* symtab, Layout* layout,
Incremental_binary* ibase,
unsigned int input_file_index,
const Incremental_binary::Input_reader* input_reader,
Task_token* this_blocker, Task_token* next_blocker)
: layout_(layout), symtab_(symtab), ibase_(ibase),
input_file_index_(input_file_index), input_reader_(input_reader),
this_blocker_(this_blocker), next_blocker_(next_blocker)
{ }
~Check_library();
// The standard Task methods.
Task_token*
is_runnable();
void
locks(Task_locker*);
void
run(Workqueue*);
std::string
get_name() const
{
return (std::string("Check_library ") + this->input_reader_->filename());
}
private:
Layout* layout_;
Symbol_table* symtab_;
Incremental_binary* ibase_;
unsigned int input_file_index_;
const Incremental_binary::Input_reader* input_reader_;
Task_token* this_blocker_;
Task_token* next_blocker_;
};
// This class is used to track the archives in a group.
class Input_group

View File

@ -56,7 +56,9 @@ Read_relocs::is_runnable()
void
Read_relocs::locks(Task_locker* tl)
{
tl->add(this, this->object_->token());
Task_token* token = this->object_->token();
if (token != NULL)
tl->add(this, token);
}
// Read the relocations and then start a Scan_relocs_task.
@ -172,7 +174,9 @@ Scan_relocs::is_runnable()
void
Scan_relocs::locks(Task_locker* tl)
{
tl->add(this, this->object_->token());
Task_token* token = this->object_->token();
if (token != NULL)
tl->add(this, token);
tl->add(this, this->next_blocker_);
}
@ -222,7 +226,9 @@ Relocate_task::locks(Task_locker* tl)
if (this->input_sections_blocker_ != NULL)
tl->add(this, this->input_sections_blocker_);
tl->add(this, this->final_blocker_);
tl->add(this, this->object_->token());
Task_token* token = this->object_->token();
if (token != NULL)
tl->add(this, token);
}
// Run the task.
@ -483,7 +489,7 @@ Sized_relobj<size, big_endian>::do_scan_relocs(Symbol_table* symtab,
// For incremental links, finalize the allocation of relocations.
if (layout->incremental_inputs() != NULL)
this->finalize_incremental_relocs(layout);
this->finalize_incremental_relocs(layout, true);
if (rd->local_symbols != NULL)
{
@ -596,7 +602,7 @@ Sized_relobj<size, big_endian>::incremental_relocs_scan(
}
}
// Scan the input relocation for --emit-relocs, templatized on the
// Scan the input relocation for --incremental, templatized on the
// type of the relocation section.
template<int size, bool big_endian>
@ -684,7 +690,8 @@ Sized_relobj<size, big_endian>::do_relocate(const Symbol_table* symtab,
// Write out the local symbols.
this->write_local_symbols(of, layout->sympool(), layout->dynpool(),
layout->symtab_xindex(), layout->dynsym_xindex());
layout->symtab_xindex(), layout->dynsym_xindex(),
layout->symtab_section()->offset());
}
// Sort a Read_multiple vector by file offset.
@ -1134,7 +1141,8 @@ Sized_relobj<size, big_endian>::incremental_relocs_write_reltype(
const unsigned int reloc_size =
Reloc_types<sh_type, size, big_endian>::reloc_size;
const unsigned int sizeof_addr = size / 8;
const unsigned int incr_reloc_size = 8 + 2 * sizeof_addr;
const unsigned int incr_reloc_size =
Incremental_relocs_reader<size, big_endian>::reloc_size;
unsigned int out_shndx = output_section->out_shndx();

View File

@ -1436,8 +1436,10 @@ read_input_script(Workqueue* workqueue, Symbol_table* symtab, Layout* layout,
{
const std::string& filename = input_file->filename();
Timespec mtime = input_file->file().get_mtime();
script_info = new Script_info();
layout->incremental_inputs()->report_script(filename, script_info, mtime);
unsigned int arg_serial = input_argument->file().arg_serial();
script_info = new Script_info(filename);
layout->incremental_inputs()->report_script(script_info, arg_serial,
mtime);
}
Parser_closure closure(input_file->filename().c_str(),

View File

@ -548,31 +548,6 @@ class Script_options
Script_sections script_sections_;
};
// Information about a script input that will persist during the whole linker
// run. Needed only during an incremental build to retrieve the input files
// added by this script.
class Script_info
{
public:
Script_info()
: incremental_script_entry_(NULL)
{ }
// Store a pointer to the incremental information for this script.
void
set_incremental_info(Incremental_script_entry* entry)
{ this->incremental_script_entry_ = entry; }
// Return the pointer to the incremental information for this script.
Incremental_script_entry*
incremental_info() const
{ return this->incremental_script_entry_; }
private:
Incremental_script_entry* incremental_script_entry_;
};
// FILE was found as an argument on the command line, but was not
// recognized as an ELF file. Try to read it as a script. Return
// true if the file was handled. This has to handle /usr/lib/libc.so

View File

@ -40,6 +40,7 @@
#include "symtab.h"
#include "script.h"
#include "plugin.h"
#include "incremental.h"
namespace gold
{
@ -1485,6 +1486,37 @@ Symbol_table::add_from_dynobj(
this->record_weak_aliases(&object_symbols);
}
// Add a symbol from a incremental object file.
template<int size, bool big_endian>
Symbol*
Symbol_table::add_from_incrobj(
Object* obj,
const char* name,
const char* ver,
elfcpp::Sym<size, big_endian>* sym)
{
unsigned int st_shndx = sym->get_st_shndx();
bool is_ordinary = st_shndx < elfcpp::SHN_LORESERVE;
Stringpool::Key ver_key = 0;
bool is_default_version = false;
bool is_forced_local = false;
Stringpool::Key name_key;
name = this->namepool_.add(name, true, &name_key);
Sized_symbol<size>* res;
res = this->add_from_object(obj, name, name_key, ver, ver_key,
is_default_version, *sym, st_shndx,
is_ordinary, st_shndx);
if (is_forced_local)
this->force_local(res);
return res;
}
// This is used to sort weak aliases. We sort them first by section
// index, then by offset, then by weak ahead of strong.
@ -3419,6 +3451,46 @@ Symbol_table::add_from_dynobj<64, true>(
size_t* defined);
#endif
#ifdef HAVE_TARGET_32_LITTLE
template
Symbol*
Symbol_table::add_from_incrobj(
Object* obj,
const char* name,
const char* ver,
elfcpp::Sym<32, false>* sym);
#endif
#ifdef HAVE_TARGET_32_BIG
template
Symbol*
Symbol_table::add_from_incrobj(
Object* obj,
const char* name,
const char* ver,
elfcpp::Sym<32, true>* sym);
#endif
#ifdef HAVE_TARGET_64_LITTLE
template
Symbol*
Symbol_table::add_from_incrobj(
Object* obj,
const char* name,
const char* ver,
elfcpp::Sym<64, false>* sym);
#endif
#ifdef HAVE_TARGET_64_BIG
template
Symbol*
Symbol_table::add_from_incrobj(
Object* obj,
const char* name,
const char* ver,
elfcpp::Sym<64, true>* sym);
#endif
#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
template
void

View File

@ -48,6 +48,8 @@ class Sized_pluginobj;
class Dynobj;
template<int size, bool big_endian>
class Sized_dynobj;
template<int size, bool big_endian>
class Sized_incrobj;
class Versions;
class Version_script_info;
class Input_objects;
@ -1336,6 +1338,13 @@ class Symbol_table
typename Sized_relobj<size, big_endian>::Symbols*,
size_t* defined);
// Add one external symbol from the incremental object OBJ to the symbol
// table. Returns a pointer to the resolved symbol in the symbol table.
template<int size, bool big_endian>
Symbol*
add_from_incrobj(Object* obj, const char* name,
const char* ver, elfcpp::Sym<size, big_endian>* sym);
// Define a special symbol based on an Output_data. It is a
// multiple definition error if this symbol is already defined.
Symbol*
@ -1466,6 +1475,11 @@ class Symbol_table
finalize(off_t off, off_t dynoff, size_t dyn_global_index, size_t dyncount,
Stringpool* pool, unsigned int* plocal_symcount);
// Set the final file offset of the symbol table.
void
set_file_offset(off_t off)
{ this->offset_ = off; }
// Status code of Symbol_table::compute_final_value.
enum Compute_final_value_status
{