* configure.ac: Add --with-lib-path option. Define LIB_PATH and
[deliverable/binutils-gdb.git] / gold / incremental.cc
index f0be7f04daac23fdd199dd460927b11bd4b1f474..75e44c5707f996cd44719459165fd6bfe5a4c3e3 100644 (file)
@@ -1,6 +1,6 @@
 // inremental.cc -- incremental linking support for gold
 
-// Copyright 2009, 2010 Free Software Foundation, Inc.
+// Copyright 2009, 2010, 2011 Free Software Foundation, Inc.
 // Written by Mikolaj Zalewski <mikolajz@google.com>.
 
 // This file is part of gold.
@@ -161,6 +161,22 @@ Incremental_binary::error(const char* format, ...) const
   va_end(args);
 }
 
+// Return TRUE if a section of type SH_TYPE can be updated in place
+// during an incremental update.  We can update sections of type PROGBITS,
+// NOBITS, INIT_ARRAY, FINI_ARRAY, PREINIT_ARRAY, and NOTE.  All others
+// will be regenerated.
+
+bool
+can_incremental_update(unsigned int sh_type)
+{
+  return (sh_type == elfcpp::SHT_PROGBITS
+         || sh_type == elfcpp::SHT_NOBITS
+         || sh_type == elfcpp::SHT_INIT_ARRAY
+         || sh_type == elfcpp::SHT_FINI_ARRAY
+         || sh_type == elfcpp::SHT_PREINIT_ARRAY
+         || sh_type == elfcpp::SHT_NOTE);
+}
+
 // Find the .gnu_incremental_inputs section and related sections.
 
 template<int size, bool big_endian>
@@ -309,7 +325,7 @@ Sized_incremental_binary<size, big_endian>::setup_readers()
          break;
        case INCREMENTAL_INPUT_SCRIPT:
          {
-           Script_info* script = new Script_info(input_file.filename());
+           Script_info* script = new Script_info(input_file.filename(), i);
            this->script_map_[i] = script;
            unsigned int object_count = input_file.get_object_count();
            for (unsigned int j = 0; j < object_count; j++)
@@ -393,6 +409,12 @@ Sized_incremental_binary<size, big_endian>::do_check_inputs(
 
   if (incremental_inputs->command_line() != inputs.command_line())
     {
+      gold_debug(DEBUG_INCREMENTAL,
+                "old command line: %s",
+                inputs.command_line());
+      gold_debug(DEBUG_INCREMENTAL,
+                "new command line: %s",
+                incremental_inputs->command_line().c_str());
       explain_no_incremental(_("command line changed"));
       return false;
     }
@@ -442,10 +464,24 @@ Sized_incremental_binary<size, big_endian>::do_file_has_changed(
 {
   Input_entry_reader input_file = this->inputs_reader_.input_file(n);
   Incremental_disposition disp = INCREMENTAL_CHECK;
+
+  // For files named in scripts, find the file that was actually named
+  // on the command line, so that we can get the incremental disposition
+  // flag.
+  Script_info* script = this->get_script_info(n);
+  if (script != NULL)
+    n = script->input_file_index();
+
   const Input_argument* input_argument = this->get_input_argument(n);
   if (input_argument != NULL)
     disp = input_argument->file().options().incremental_disposition();
 
+  // For files at the beginning of the command line (i.e., those added
+  // implicitly by gcc), check whether the --incremental-startup-unchanged
+  // option was used.
+  if (disp == INCREMENTAL_STARTUP)
+    disp = parameters->options().incremental_startup_disposition();
+
   if (disp != INCREMENTAL_CHECK)
     return disp == INCREMENTAL_CHANGED;
 
@@ -649,12 +685,12 @@ Sized_incremental_binary<size, big_endian>::do_process_got_plt(
       gold_assert(plt_desc >= first_global && plt_desc < symtab_count);
       Symbol* sym = this->global_symbol(plt_desc - first_global);
       // Add the PLT entry only if the symbol is still referenced.
-      if (sym->in_reg())
+      if (sym != NULL && sym->in_reg())
        {
          gold_debug(DEBUG_INCREMENTAL,
                     "PLT entry %d: %s",
                     i, sym->name());
-         target->register_global_plt_entry(i, sym);
+         target->register_global_plt_entry(symtab, layout, i, sym);
        }
     }
 }
@@ -924,6 +960,7 @@ Incremental_inputs::report_command_line(int argc, const char* const* argv)
          || strcmp(argv[i], "--incremental-changed") == 0
          || strcmp(argv[i], "--incremental-unchanged") == 0
          || strcmp(argv[i], "--incremental-unknown") == 0
+         || strcmp(argv[i], "--incremental-startup-unchanged") == 0
          || is_prefix_of("--incremental-base=", argv[i])
          || is_prefix_of("--incremental-patch=", argv[i])
          || is_prefix_of("--debug=", argv[i]))
@@ -1648,9 +1685,15 @@ Output_section_incremental_inputs<size, big_endian>::write_info_blocks(
                if (sym->symtab_index() == -1U)
                  continue;
                unsigned int flags = 0;
-               if (sym->source() == Symbol::FROM_OBJECT
-                   && sym->object() == obj
-                   && sym->is_defined())
+               // If the symbol has hidden or internal visibility, we
+               // mark it as defined in the shared object so we don't
+               // try to resolve it during an incremental update.
+               if (sym->visibility() == elfcpp::STV_HIDDEN
+                   || sym->visibility() == elfcpp::STV_INTERNAL)
+                 flags = INCREMENTAL_SHLIB_SYM_DEF;
+               else if (sym->source() == Symbol::FROM_OBJECT
+                        && sym->object() == obj
+                        && sym->is_defined())
                  flags = INCREMENTAL_SHLIB_SYM_DEF;
                else if (sym->is_copied_from_dynobj()
                         && this->symtab_->get_copy_source(sym) == dynobj)
@@ -1923,8 +1966,9 @@ Sized_relobj_incr<size, big_endian>::Sized_relobj_incr(
     input_reader_(ibase->inputs_reader().input_file(input_file_index)),
     local_symbol_count_(0), output_local_dynsym_count_(0),
     local_symbol_index_(0), local_symbol_offset_(0), local_dynsym_offset_(0),
-    symbols_(), incr_reloc_offset_(-1U), incr_reloc_count_(0),
-    incr_reloc_output_index_(0), incr_relocs_(NULL), local_symbols_()
+    symbols_(), defined_count_(0), incr_reloc_offset_(-1U),
+    incr_reloc_count_(0), incr_reloc_output_index_(0), incr_relocs_(NULL),
+    local_symbols_()
 {
   if (this->input_reader_.is_in_system_directory())
     this->set_is_in_system_directory();
@@ -1981,7 +2025,9 @@ Sized_relobj_incr<size, big_endian>::do_layout(
         this->error(_("COMDAT group has no signature"));
       bool keep = layout->find_or_add_kept_section(signature, this, i, true,
                                                   true, NULL);
-      if (!keep)
+      if (keep)
+       incremental_inputs->report_comdat_group(this, signature);
+      else
         this->error(_("COMDAT group %s included twice in incremental link"),
                    signature);
     }
@@ -2075,6 +2121,9 @@ Sized_relobj_incr<size, big_endian>::do_add_symbols(
 
       Symbol* res = symtab->add_from_incrobj(this, name, NULL, &sym);
 
+      if (shndx != elfcpp::SHN_UNDEF)
+        ++this->defined_count_;
+
       // If this is a linker-defined symbol that hasn't yet been defined,
       // define it now.
       if (input_shndx == -1U && !res->is_defined())
@@ -2238,9 +2287,21 @@ Sized_relobj_incr<size, big_endian>::do_initialize_xindex()
 template<int size, bool big_endian>
 void
 Sized_relobj_incr<size, big_endian>::do_get_global_symbol_counts(
-    const Symbol_table*, size_t*, size_t*) const
-{
-  gold_unreachable();
+    const Symbol_table*,
+    size_t* defined,
+    size_t* used) const
+{
+  *defined = this->defined_count_;
+  size_t count = 0;
+  for (typename Symbols::const_iterator p = this->symbols_.begin();
+       p != this->symbols_.end();
+       ++p)
+    if (*p != NULL
+       && (*p)->source() == Symbol::FROM_OBJECT
+       && (*p)->object() == this
+       && (*p)->is_defined())
+      ++count;
+  *used = count;
 }
 
 // Read the relocs.
@@ -2534,7 +2595,7 @@ Sized_incr_dynobj<size, big_endian>::Sized_incr_dynobj(
   : Dynobj(name, NULL), ibase_(ibase),
     input_file_index_(input_file_index),
     input_reader_(ibase->inputs_reader().input_file(input_file_index)),
-    symbols_()
+    symbols_(), defined_count_(0)
 {
   if (this->input_reader_.is_in_system_directory())
     this->set_is_in_system_directory();
@@ -2632,6 +2693,7 @@ Sized_incr_dynobj<size, big_endian>::do_add_symbols(
          // is meaningless, as long as it's not SHN_UNDEF.
          shndx = 1;
          v = gsym.get_st_value();
+         ++this->defined_count_;
        }
 
       osym.put_st_name(0);
@@ -2800,9 +2862,22 @@ Sized_incr_dynobj<size, big_endian>::do_initialize_xindex()
 template<int size, bool big_endian>
 void
 Sized_incr_dynobj<size, big_endian>::do_get_global_symbol_counts(
-    const Symbol_table*, size_t*, size_t*) const
-{
-  gold_unreachable();
+    const Symbol_table*,
+    size_t* defined,
+    size_t* used) const
+{
+  *defined = this->defined_count_;
+  size_t count = 0;
+  for (typename Symbols::const_iterator p = this->symbols_.begin();
+       p != this->symbols_.end();
+       ++p)
+    if (*p != NULL
+       && (*p)->source() == Symbol::FROM_OBJECT
+       && (*p)->object() == this
+       && (*p)->is_defined()
+       && (*p)->dynsym_index() != -1U)
+      ++count;
+  *used = count;
 }
 
 // Allocate an incremental object of the appropriate size and endianness.
This page took 0.026773 seconds and 4 git commands to generate.