From 8c21d9d382512278b484e29aa85053d9378c8b63 Mon Sep 17 00:00:00 2001 From: Cary Coutant Date: Thu, 14 Oct 2010 22:10:22 +0000 Subject: * debug.h (DEBUG_INCREMENTAL): New flag. (debug_string_to_enum): Add DEBUG_INCREMENTAL). * gold.cc (queue_initial_tasks): Check parameters for incremental link mode. * incremental.cc (report_command_line): Ignore all forms of --incremental. * layout.cc (Layout::Layout): Check parameters for incremental link mode. * options.cc (General_options::parse_incremental): New function. (General_options::parse_no_incremental): New function. (General_options::parse_incremental_full): New function. (General_options::parse_incremental_update): New function. (General_options::incremental_mode_): New data member. (General_options::finalize): Check incremental_mode_. * options.h (General_options): Update help text for --incremental. Add --no-incremental, --incremental-full, --incremental-update. (General_options::Incremental_mode): New enum type. (General_options::incremental_mode): New function. (General_options::incremental_mode_): New data member. * parameters.cc (Parameters::incremental_mode_): New data member. (Parameters::set_options): Set incremental_mode_. (Parameters::set_incremental_full): New function. (Parameters::incremental): New function. (Parameters::incremental_update): New function. (set_parameters_incremental_full): New function. * parameters.h (Parameters::set_incremental_full): New function. (Parameters::incremental): New function. (Parameters::incremental_update): New function. (Parameters::incremental_mode_): New data member. (set_parameters_incremental_full): New function. * plugin.cc (Plugin_manager::add_input_file): Check parameters for incremental link mode. * reloc.cc (Sized_relobj::do_read_relocs): Likewise. (Sized_relobj::do_relocate_sections): Likewise. * testsuite/Makefile.am (incremental_test): Use --incremental-full option. * testsuite/Makefile.in: Regenerate. * testsuite/incremental_test.sh: Filter all forms of --incremental. --- gold/ChangeLog | 41 ++++++++++++++++++++++++++++++++++ gold/debug.h | 4 +++- gold/gold.cc | 2 +- gold/incremental.cc | 5 ++++- gold/layout.cc | 2 +- gold/options.cc | 31 +++++++++++++++++++++++++- gold/options.h | 38 +++++++++++++++++++++++++++++--- gold/parameters.cc | 45 +++++++++++++++++++++++++++++++++++++- gold/parameters.h | 18 +++++++++++++++ gold/plugin.cc | 2 +- gold/reloc.cc | 4 ++-- gold/testsuite/Makefile.am | 2 +- gold/testsuite/Makefile.in | 2 +- gold/testsuite/incremental_test.sh | 1 + 14 files changed, 183 insertions(+), 14 deletions(-) (limited to 'gold') diff --git a/gold/ChangeLog b/gold/ChangeLog index c68e4b2..0977b37 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,44 @@ +2010-10-14 Cary Coutant + + * debug.h (DEBUG_INCREMENTAL): New flag. + (debug_string_to_enum): Add DEBUG_INCREMENTAL). + * gold.cc (queue_initial_tasks): Check parameters for incremental link + mode. + * incremental.cc (report_command_line): Ignore all forms of + --incremental. + * layout.cc (Layout::Layout): Check parameters for incremental link + mode. + * options.cc (General_options::parse_incremental): New function. + (General_options::parse_no_incremental): New function. + (General_options::parse_incremental_full): New function. + (General_options::parse_incremental_update): New function. + (General_options::incremental_mode_): New data member. + (General_options::finalize): Check incremental_mode_. + * options.h (General_options): Update help text for --incremental. + Add --no-incremental, --incremental-full, --incremental-update. + (General_options::Incremental_mode): New enum type. + (General_options::incremental_mode): New function. + (General_options::incremental_mode_): New data member. + * parameters.cc (Parameters::incremental_mode_): New data member. + (Parameters::set_options): Set incremental_mode_. + (Parameters::set_incremental_full): New function. + (Parameters::incremental): New function. + (Parameters::incremental_update): New function. + (set_parameters_incremental_full): New function. + * parameters.h (Parameters::set_incremental_full): New function. + (Parameters::incremental): New function. + (Parameters::incremental_update): New function. + (Parameters::incremental_mode_): New data member. + (set_parameters_incremental_full): New function. + * plugin.cc (Plugin_manager::add_input_file): Check parameters for + incremental link mode. + * reloc.cc (Sized_relobj::do_read_relocs): Likewise. + (Sized_relobj::do_relocate_sections): Likewise. + * testsuite/Makefile.am (incremental_test): Use --incremental-full + option. + * testsuite/Makefile.in: Regenerate. + * testsuite/incremental_test.sh: Filter all forms of --incremental. + 2010-10-12 Viktor Kutuzov * script-sections.h (class Script_sections): Make diff --git a/gold/debug.h b/gold/debug.h index 4b9ef19..7fdbee7 100644 --- a/gold/debug.h +++ b/gold/debug.h @@ -37,9 +37,10 @@ const int DEBUG_TASK = 0x1; const int DEBUG_SCRIPT = 0x2; const int DEBUG_FILES = 0x4; const int DEBUG_RELAXATION = 0x8; +const int DEBUG_INCREMENTAL = 0x10; const int DEBUG_ALL = (DEBUG_TASK | DEBUG_SCRIPT | DEBUG_FILES - | DEBUG_RELAXATION); + | DEBUG_RELAXATION | DEBUG_INCREMENTAL); // Convert a debug string to the appropriate enum. inline int @@ -52,6 +53,7 @@ debug_string_to_enum(const char* arg) { "script", DEBUG_SCRIPT }, { "files", DEBUG_FILES }, { "relaxation", DEBUG_RELAXATION }, + { "incremental", DEBUG_INCREMENTAL }, { "all", DEBUG_ALL } }; diff --git a/gold/gold.cc b/gold/gold.cc index 74294d7..6bbf02e 100644 --- a/gold/gold.cc +++ b/gold/gold.cc @@ -178,7 +178,7 @@ queue_initial_tasks(const General_options& options, thread_count = cmdline.number_of_input_files(); workqueue->set_thread_count(thread_count); - if (cmdline.options().incremental()) + if (parameters->incremental()) { Incremental_checker incremental_checker( parameters->options().output_file_name(), diff --git a/gold/incremental.cc b/gold/incremental.cc index 0bd869e..aa9d7d3 100644 --- a/gold/incremental.cc +++ b/gold/incremental.cc @@ -401,7 +401,10 @@ Incremental_inputs::report_command_line(int argc, const char* const* argv) for (int i = 1; i < argc; ++i) { // Adding/removing these options should not result in a full relink. - if (strcmp(argv[i], "--incremental-changed") == 0 + if (strcmp(argv[i], "--incremental") == 0 + || strcmp(argv[i], "--incremental-full") == 0 + || strcmp(argv[i], "--incremental-update") == 0 + || strcmp(argv[i], "--incremental-changed") == 0 || strcmp(argv[i], "--incremental-unchanged") == 0 || strcmp(argv[i], "--incremental-unknown") == 0) continue; diff --git a/gold/layout.cc b/gold/layout.cc index b5490d6..2f56d27 100644 --- a/gold/layout.cc +++ b/gold/layout.cc @@ -218,7 +218,7 @@ Layout::Layout(int number_of_input_files, Script_options* script_options) this->special_output_list_.reserve(2); // Initialize structure needed for an incremental build. - if (parameters->options().incremental()) + if (parameters->incremental()) this->incremental_inputs_ = new Incremental_inputs; // The section name pool is worth optimizing in all cases, because diff --git a/gold/options.cc b/gold/options.cc index 21e3f28..6839ba4 100644 --- a/gold/options.cc +++ b/gold/options.cc @@ -317,6 +317,34 @@ General_options::parse_defsym(const char*, const char* arg, } void +General_options::parse_incremental(const char*, const char*, + Command_line*) +{ + this->incremental_mode_ = INCREMENTAL_AUTO; +} + +void +General_options::parse_no_incremental(const char*, const char*, + Command_line*) +{ + this->incremental_mode_ = INCREMENTAL_OFF; +} + +void +General_options::parse_incremental_full(const char*, const char*, + Command_line*) +{ + this->incremental_mode_ = INCREMENTAL_FULL; +} + +void +General_options::parse_incremental_update(const char*, const char*, + Command_line*) +{ + this->incremental_mode_ = INCREMENTAL_UPDATE; +} + +void General_options::parse_incremental_changed(const char*, const char*, Command_line*) { @@ -852,6 +880,7 @@ General_options::General_options() do_demangle_(false), plugins_(NULL), dynamic_list_(), + incremental_mode_(INCREMENTAL_OFF), incremental_disposition_(INCREMENTAL_CHECK), implicit_incremental_(false), excluded_libs_(), @@ -1137,7 +1166,7 @@ General_options::finalize() "[0.0, 1.0)"), this->hash_bucket_empty_fraction()); - if (this->implicit_incremental_ && !this->incremental()) + if (this->implicit_incremental_ && this->incremental_mode_ == INCREMENTAL_OFF) gold_fatal(_("Options --incremental-changed, --incremental-unchanged, " "--incremental-unknown require the use of --incremental")); diff --git a/gold/options.h b/gold/options.h index 59e2267..7a694a9 100644 --- a/gold/options.h +++ b/gold/options.h @@ -770,9 +770,20 @@ class General_options DEFINE_string(dynamic_linker, options::TWO_DASHES, 'I', NULL, N_("Set dynamic linker path"), N_("PROGRAM")); - DEFINE_bool(incremental, options::TWO_DASHES, '\0', false, - N_("Work in progress; do not use"), - N_("Do a full build")); + DEFINE_special(incremental, options::TWO_DASHES, '\0', + N_("Do an incremental link if possible; " + "otherwise, do a full link and prepare output " + "for incremental linking"), NULL); + + DEFINE_special(no_incremental, options::TWO_DASHES, '\0', + N_("Do a full link (default)"), NULL); + + DEFINE_special(incremental_full, options::TWO_DASHES, '\0', + N_("Do a full link and " + "prepare output for incremental linking"), NULL); + + DEFINE_special(incremental_update, options::TWO_DASHES, '\0', + N_("Do an incremental link; exit if not possible"), NULL); DEFINE_special(incremental_changed, options::TWO_DASHES, '\0', N_("Assume files changed"), NULL); @@ -1263,6 +1274,25 @@ class General_options finalize_dynamic_list() { this->dynamic_list_.version_script_info()->finalize(); } + // The mode selected by the --incremental options. + enum Incremental_mode + { + // No incremental linking (--no-incremental). + INCREMENTAL_OFF, + // Incremental update only (--incremental-update). + INCREMENTAL_UPDATE, + // Force a full link, but prepare for subsequent incremental link + // (--incremental-full). + INCREMENTAL_FULL, + // Incremental update if possible, fallback to full link (--incremental). + INCREMENTAL_AUTO + }; + + // The incremental linking mode. + Incremental_mode + incremental_mode() const + { return this->incremental_mode_; } + // The disposition given by the --incremental-changed, // --incremental-unchanged or --incremental-unknown option. The // value may change as we proceed parsing the command line flags. @@ -1381,6 +1411,8 @@ class General_options // script.cc, we store this as a Script_options object, even though // we only use a single Version_tree from it. Script_options dynamic_list_; + // The incremental linking mode. + Incremental_mode incremental_mode_; // The disposition given by the --incremental-changed, // --incremental-unchanged or --incremental-unknown option. The // value may change as we proceed parsing the command line flags. diff --git a/gold/parameters.cc b/gold/parameters.cc index 4430388..e04168f 100644 --- a/gold/parameters.cc +++ b/gold/parameters.cc @@ -66,7 +66,7 @@ Set_parameters_target_once set_parameters_target_once(&static_parameters); Parameters::Parameters() : errors_(NULL), options_(NULL), target_(NULL), doing_static_link_valid_(false), doing_static_link_(false), - debug_(0), + debug_(0), incremental_mode_(General_options::INCREMENTAL_OFF), set_parameters_target_once_(&set_parameters_target_once) { } @@ -86,6 +86,9 @@ Parameters::set_options(const General_options* options) // For speed, we convert the options() debug var from a string to an // enum (from debug.h). this->debug_ = debug_string_to_enum(this->options().debug()); + // Set incremental_mode_ based on the value of the --incremental option. + // We copy the mode into parameters because it can change based on inputs. + this->incremental_mode_ = this->options().incremental_mode(); // If --verbose is set, it acts as "--debug=files". if (options->verbose()) this->debug_ |= DEBUG_FILES; @@ -208,6 +211,38 @@ Parameters::check_target_endianness() } } +// Set the incremental linking mode to INCREMENTAL_FULL. Used when +// the linker determines that an incremental update is not possible. +// Returns false if the incremental mode was INCREMENTAL_UPDATE, +// indicating that the linker should exit if an update is not possible. + +bool +Parameters::set_incremental_full() +{ + gold_assert(this->incremental_mode_ != General_options::INCREMENTAL_OFF); + if (this->incremental_mode_ == General_options::INCREMENTAL_UPDATE) + return false; + this->incremental_mode_ = General_options::INCREMENTAL_FULL; + return true; +} + +// Return true if we need to prepare incremental linking information. + +bool +Parameters::incremental() const +{ + return this->incremental_mode_ != General_options::INCREMENTAL_OFF; +} + +// Return true if we are doing an incremental update. + +bool +Parameters::incremental_update() const +{ + return (this->incremental_mode_ == General_options::INCREMENTAL_UPDATE + || this->incremental_mode_ == General_options::INCREMENTAL_AUTO); +} + void set_parameters_errors(Errors* errors) { static_parameters.set_errors(errors); } @@ -227,6 +262,14 @@ void set_parameters_doing_static_link(bool doing_static_link) { static_parameters.set_doing_static_link(doing_static_link); } +// Set the incremental linking mode to INCREMENTAL_FULL. Used when +// the linker determines that an incremental update is not possible. +// Returns false if the incremental mode was INCREMENTAL_UPDATE, +// indicating that the linker should exit if an update is not possible. +bool +set_parameters_incremental_full() +{ return static_parameters.set_incremental_full(); } + // Force the target to be valid by using the default. Use the // --oformat option is set; this supports the x86_64 kernel build, // which converts a binary file to an object file using -r --format diff --git a/gold/parameters.h b/gold/parameters.h index 0ca2941..f9022ae 100644 --- a/gold/parameters.h +++ b/gold/parameters.h @@ -144,6 +144,20 @@ class Parameters Target_size_endianness size_and_endianness() const; + // Set the incremental linking mode to INCREMENTAL_FULL. Used when + // the linker determines that an incremental update is not possible. + // Returns false if the incremental mode was INCREMENTAL_UPDATE, + // indicating that the linker should exit if an update is not possible. + bool + set_incremental_full(); + + // Return true if we need to prepare incremental linking information. + bool + incremental() const; + + // Return true if we are doing an incremental update. + bool + incremental_update() const; private: void @@ -160,6 +174,7 @@ class Parameters bool doing_static_link_valid_; bool doing_static_link_; int debug_; + int incremental_mode_; Set_parameters_target_once* set_parameters_target_once_; }; @@ -181,6 +196,9 @@ set_parameters_target(Target* target); extern void set_parameters_doing_static_link(bool doing_static_link); +extern bool +set_parameters_incremental_full(); + // Ensure that the target to be valid by using the default target if // necessary. diff --git a/gold/plugin.cc b/gold/plugin.cc index 2b11cd3..7dd1fa3 100644 --- a/gold/plugin.cc +++ b/gold/plugin.cc @@ -451,7 +451,7 @@ Plugin_manager::add_input_file(const char* pathname, bool is_lib) Input_argument* input_argument = new Input_argument(file); Task_token* next_blocker = new Task_token(true); next_blocker->add_blocker(); - if (parameters->options().incremental()) + if (parameters->incremental()) gold_error(_("input files added by plug-ins in --incremental mode not " "supported yet")); this->workqueue_->queue_soon(new Read_symbols(this->input_objects_, diff --git a/gold/reloc.cc b/gold/reloc.cc index 6f2ede7..9ffb693 100644 --- a/gold/reloc.cc +++ b/gold/reloc.cc @@ -303,7 +303,7 @@ Sized_relobj::do_read_relocs(Read_relocs_data* rd) if (!is_section_allocated && !parameters->options().relocatable() && !parameters->options().emit_relocs() - && !parameters->options().incremental()) + && !parameters->incremental()) continue; if (this->adjust_shndx(shdr.get_sh_link()) != this->symtab_shndx_) @@ -1000,7 +1000,7 @@ Sized_relobj::do_relocate_sections( this->emit_relocs(&relinfo, i, sh_type, prelocs, reloc_count, os, output_offset, view, address, view_size, (*pviews)[i].view, (*pviews)[i].view_size); - if (parameters->options().incremental()) + if (parameters->incremental()) this->incremental_relocs_write(&relinfo, sh_type, prelocs, reloc_count, os, output_offset, of); } diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 24427df..c4e6c03 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -115,7 +115,7 @@ incremental_test_1.o: incremental_test_1.c incremental_test_2.o: incremental_test_2.c $(COMPILE) -O0 -c -ffunction-sections -g -o $@ $< incremental_test: incremental_test_1.o incremental_test_2.o gcctestdir/ld - $(LINK) -Bgcctestdir/ -Wl,-incremental incremental_test_1.o incremental_test_2.o -Wl,-debug 2> incremental_test.cmdline + $(LINK) -Bgcctestdir/ -Wl,--incremental-full incremental_test_1.o incremental_test_2.o -Wl,-debug 2> incremental_test.cmdline incremental_test.stdout: incremental_test ../incremental-dump ../incremental-dump incremental_test > $@ diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index ae419b0..d514893 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -3785,7 +3785,7 @@ uninstall-am: @GCC_TRUE@@NATIVE_LINKER_TRUE@incremental_test_2.o: incremental_test_2.c @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -O0 -c -ffunction-sections -g -o $@ $< @GCC_TRUE@@NATIVE_LINKER_TRUE@incremental_test: incremental_test_1.o incremental_test_2.o gcctestdir/ld -@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -Bgcctestdir/ -Wl,-incremental incremental_test_1.o incremental_test_2.o -Wl,-debug 2> incremental_test.cmdline +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -Bgcctestdir/ -Wl,--incremental-full incremental_test_1.o incremental_test_2.o -Wl,-debug 2> incremental_test.cmdline @GCC_TRUE@@NATIVE_LINKER_TRUE@incremental_test.stdout: incremental_test ../incremental-dump @GCC_TRUE@@NATIVE_LINKER_TRUE@ ../incremental-dump incremental_test > $@ @GCC_TRUE@@NATIVE_LINKER_TRUE@gc_comdat_test_1.o: gc_comdat_test_1.cc diff --git a/gold/testsuite/incremental_test.sh b/gold/testsuite/incremental_test.sh index 94369d4..930d7d1 100755 --- a/gold/testsuite/incremental_test.sh +++ b/gold/testsuite/incremental_test.sh @@ -50,6 +50,7 @@ check() # Extract actual command line from linker's -v output. cat incremental_test.cmdline | grep "gcctestdir/ld " | + sed "s/--incremental[-a-z]* //g" | cut -d ' ' -f 2- > actual # Extract recorded command line from dump of the output file. -- cgit v1.1