Sync bootstrap-lto.mk and dfp.m4 with gcc.
[deliverable/binutils-gdb.git] / gold / symtab.cc
index 3f85f6c0e02befb041a73be31544892f584da47c..d8cda2d105cb92a604659314776337d832551ab4 100644 (file)
@@ -38,7 +38,7 @@
 #include "target.h"
 #include "workqueue.h"
 #include "symtab.h"
-#include "demangle.h"   // needed for --dynamic-list-cpp-new
+#include "script.h"
 #include "plugin.h"
 
 namespace gold
@@ -76,6 +76,8 @@ Symbol::init_fields(const char* name, const char* version,
   this->is_ordinary_shndx_ = false;
   this->in_real_elf_ = false;
   this->is_defined_in_discarded_section_ = false;
+  this->undef_binding_set_ = false;
+  this->undef_binding_weak_ = false;
 }
 
 // Return the demangled version of the symbol's name, but only
@@ -528,7 +530,7 @@ Symbol_table::is_section_folded(Object* obj, unsigned int shndx) const
 // work list to avoid gc'ing them.
 
 void 
-Symbol_table::gc_mark_undef_symbols()
+Symbol_table::gc_mark_undef_symbols(Layout* layout)
 {
   for (options::String_set::const_iterator p =
         parameters->options().undefined_begin();
@@ -537,7 +539,7 @@ Symbol_table::gc_mark_undef_symbols()
     {
       const char* name = p->c_str();
       Symbol* sym = this->lookup(name);
-      gold_assert (sym != NULL);
+      gold_assert(sym != NULL);
       if (sym->source() == Symbol::FROM_OBJECT 
           && !sym->object()->is_dynamic())
         {
@@ -551,6 +553,27 @@ Symbol_table::gc_mark_undef_symbols()
             }
         }
     }
+
+  for (Script_options::referenced_const_iterator p =
+        layout->script_options()->referenced_begin();
+       p != layout->script_options()->referenced_end();
+       ++p)
+    {
+      Symbol* sym = this->lookup(p->c_str());
+      gold_assert(sym != NULL);
+      if (sym->source() == Symbol::FROM_OBJECT
+         && !sym->object()->is_dynamic())
+       {
+         Relobj* obj = static_cast<Relobj*>(sym->object());
+         bool is_ordinary;
+         unsigned int shndx = sym->shndx(&is_ordinary);
+         if (is_ordinary)
+           {
+             gold_assert(this->gc_ != NULL);
+             this->gc_->worklist().push(Section_id(obj, shndx));
+           }
+       }
+    }
 }
 
 void
@@ -579,7 +602,7 @@ Symbol_table::gc_mark_dyn_syms(Symbol* sym)
   if (sym->in_dyn() && sym->source() == Symbol::FROM_OBJECT
       && !sym->object()->is_dynamic())
     {
-      Relobj *obj = static_cast<Relobj*>(sym->object()); 
+      Relobjobj = static_cast<Relobj*>(sym->object()); 
       bool is_ordinary;
       unsigned int shndx = sym->shndx(&is_ordinary);
       if (is_ordinary && shndx != elfcpp::SHN_UNDEF)
@@ -840,9 +863,9 @@ Symbol_table::define_default_version(Sized_symbol<size>* sym,
 template<int size, bool big_endian>
 Sized_symbol<size>*
 Symbol_table::add_from_object(Object* object,
-                             const char *name,
+                             const charname,
                              Stringpool::Key name_key,
-                             const char *version,
+                             const charversion,
                              Stringpool::Key version_key,
                              bool is_default_version,
                              const elfcpp::Sym<size, big_endian>& sym,
@@ -1030,7 +1053,7 @@ Symbol_table::add_from_relobj(
     const char* sym_names,
     size_t sym_name_size,
     typename Sized_relobj<size, big_endian>::Symbols* sympointers,
-    size_t *defined)
+    size_tdefined)
 {
   *defined = 0;
 
@@ -1558,7 +1581,7 @@ Sized_symbol<size>*
 Symbol_table::define_special_symbol(const char** pname, const char** pversion,
                                    bool only_if_ref,
                                     Sized_symbol<size>** poldsym,
-                                   bool *resolve_oldsym)
+                                   boolresolve_oldsym)
 {
   *resolve_oldsym = false;
 
@@ -2161,14 +2184,15 @@ Symbol_table::get_copy_source(const Symbol* sym) const
 // Add any undefined symbols named on the command line.
 
 void
-Symbol_table::add_undefined_symbols_from_command_line()
+Symbol_table::add_undefined_symbols_from_command_line(Layout* layout)
 {
-  if (parameters->options().any_undefined())
+  if (parameters->options().any_undefined()
+      || layout->script_options()->any_unreferenced())
     {
       if (parameters->target().get_size() == 32)
        {
 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
-         this->do_add_undefined_symbols_from_command_line<32>();
+         this->do_add_undefined_symbols_from_command_line<32>(layout);
 #else
          gold_unreachable();
 #endif
@@ -2176,7 +2200,7 @@ Symbol_table::add_undefined_symbols_from_command_line()
       else if (parameters->target().get_size() == 64)
        {
 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
-         this->do_add_undefined_symbols_from_command_line<64>();
+         this->do_add_undefined_symbols_from_command_line<64>(layout);
 #else
          gold_unreachable();
 #endif
@@ -2188,50 +2212,59 @@ Symbol_table::add_undefined_symbols_from_command_line()
 
 template<int size>
 void
-Symbol_table::do_add_undefined_symbols_from_command_line()
+Symbol_table::do_add_undefined_symbols_from_command_line(Layout* layout)
 {
   for (options::String_set::const_iterator p =
         parameters->options().undefined_begin();
        p != parameters->options().undefined_end();
        ++p)
-    {
-      const char* name = p->c_str();
+    this->add_undefined_symbol_from_command_line<size>(p->c_str());
 
-      if (this->lookup(name) != NULL)
-       continue;
+  for (Script_options::referenced_const_iterator p =
+        layout->script_options()->referenced_begin();
+       p != layout->script_options()->referenced_end();
+       ++p)
+    this->add_undefined_symbol_from_command_line<size>(p->c_str());
+}
 
-      const char* version = NULL;
+template<int size>
+void
+Symbol_table::add_undefined_symbol_from_command_line(const char* name)
+{
+  if (this->lookup(name) != NULL)
+    return;
 
-      Sized_symbol<size>* sym;
-      Sized_symbol<size>* oldsym;
-      bool resolve_oldsym;
-      if (parameters->target().is_big_endian())
-       {
+  const char* version = NULL;
+
+  Sized_symbol<size>* sym;
+  Sized_symbol<size>* oldsym;
+  bool resolve_oldsym;
+  if (parameters->target().is_big_endian())
+    {
 #if defined(HAVE_TARGET_32_BIG) || defined(HAVE_TARGET_64_BIG)
-         sym = this->define_special_symbol<size, true>(&name, &version,
-                                                       false, &oldsym,
-                                                       &resolve_oldsym);
+      sym = this->define_special_symbol<size, true>(&name, &version,
+                                                   false, &oldsym,
+                                                   &resolve_oldsym);
 #else
-         gold_unreachable();
+      gold_unreachable();
 #endif
-       }
-      else
-       {
+    }
+  else
+    {
 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_64_LITTLE)
-         sym = this->define_special_symbol<size, false>(&name, &version,
-                                                        false, &oldsym,
-                                                        &resolve_oldsym);
+      sym = this->define_special_symbol<size, false>(&name, &version,
+                                                    false, &oldsym,
+                                                    &resolve_oldsym);
 #else
-         gold_unreachable();
+      gold_unreachable();
 #endif
-       }
+    }
 
-      gold_assert(oldsym == NULL);
+  gold_assert(oldsym == NULL);
 
-      sym->init_undefined(name, version, elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
-                         elfcpp::STV_DEFAULT, 0);
-      ++this->saw_undefined_;
-    }
+  sym->init_undefined(name, version, elfcpp::STT_NOTYPE, elfcpp::STB_GLOBAL,
+                     elfcpp::STV_DEFAULT, 0);
+  ++this->saw_undefined_;
 }
 
 // Set the dynamic symbol indexes.  INDEX is the index of the first
@@ -2291,7 +2324,7 @@ Symbol_table::set_dynsym_indexes(unsigned int index,
 off_t
 Symbol_table::finalize(off_t off, off_t dynoff, size_t dyn_global_index,
                       size_t dyncount, Stringpool* pool,
-                      unsigned int *plocal_symcount)
+                      unsigned intplocal_symcount)
 {
   off_t ret;
 
@@ -2697,6 +2730,7 @@ Symbol_table::sized_write_globals(const Stringpool* sympool,
       unsigned int shndx;
       typename elfcpp::Elf_types<size>::Elf_Addr sym_value = sym->value();
       typename elfcpp::Elf_types<size>::Elf_Addr dynsym_value = sym_value;
+      elfcpp::STB binding = sym->binding();
       switch (sym->source())
        {
        case Symbol::FROM_OBJECT:
@@ -2720,6 +2754,10 @@ Symbol_table::sized_write_globals(const Stringpool* sympool,
                    if (sym->needs_dynsym_value())
                      dynsym_value = target.dynsym_value(sym);
                    shndx = elfcpp::SHN_UNDEF;
+                   if (sym->is_undef_binding_weak())
+                     binding = elfcpp::STB_WEAK;
+                   else
+                     binding = elfcpp::STB_GLOBAL;
                  }
                else if (symobj->pluginobj() != NULL)
                  shndx = elfcpp::SHN_UNDEF;
@@ -2800,7 +2838,7 @@ Symbol_table::sized_write_globals(const Stringpool* sympool,
          gold_assert(sym_index < output_count);
          unsigned char* ps = psyms + (sym_index * sym_size);
          this->sized_write_symbol<size, big_endian>(sym, sym_value, shndx,
-                                                    sympool, ps);
+                                                    binding, sympool, ps);
        }
 
       if (dynsym_index != -1U)
@@ -2809,7 +2847,7 @@ Symbol_table::sized_write_globals(const Stringpool* sympool,
          gold_assert(dynsym_index < dynamic_count);
          unsigned char* pd = dynamic_view + (dynsym_index * sym_size);
          this->sized_write_symbol<size, big_endian>(sym, dynsym_value, shndx,
-                                                    dynpool, pd);
+                                                    binding, dynpool, pd);
        }
     }
 
@@ -2827,6 +2865,7 @@ Symbol_table::sized_write_symbol(
     Sized_symbol<size>* sym,
     typename elfcpp::Elf_types<size>::Elf_Addr value,
     unsigned int shndx,
+    elfcpp::STB binding,
     const Stringpool* pool,
     unsigned char* p) const
 {
@@ -2847,7 +2886,7 @@ Symbol_table::sized_write_symbol(
   if (sym->is_forced_local())
     osym.put_st_info(elfcpp::elf_st_info(elfcpp::STB_LOCAL, type));
   else
-    osym.put_st_info(elfcpp::elf_st_info(sym->binding(), type));
+    osym.put_st_info(elfcpp::elf_st_info(binding, type));
   osym.put_st_other(elfcpp::elf_st_other(sym->visibility(), sym->nonvis()));
   osym.put_st_shndx(shndx);
 }
@@ -2888,7 +2927,7 @@ Symbol_table::warn_about_undefined_dynobj_symbol(Symbol* sym) const
 // Write out a section symbol.  Return the update offset.
 
 void
-Symbol_table::write_section_symbol(const Output_section *os,
+Symbol_table::write_section_symbol(const Output_sectionos,
                                   Output_symtab_xindex* symtab_xindex,
                                   Output_file* of,
                                   off_t offset) const
@@ -3014,8 +3053,11 @@ Symbol_table::detect_odr_violations(const Task* task,
        ++it)
     {
       const char* symbol_name = it->first;
-      // We use a sorted set so the output is deterministic.
-      std::set<std::string, Odr_violation_compare> line_nums;
+      // Maps from symbol location to a sample object file we found
+      // that location in.  We use a sorted map so the location order
+      // is deterministic, but we only store an arbitrary object file
+      // to avoid copying lots of names.
+      std::map<std::string, std::string, Odr_violation_compare> line_nums;
 
       for (Unordered_set<Symbol_location, Symbol_location_hash>::const_iterator
                locs = it->second.begin();
@@ -3034,7 +3076,11 @@ Symbol_table::detect_odr_violations(const Task* task,
           std::string lineno = Dwarf_line_info::one_addr2line(
               locs->object, locs->shndx, locs->offset, 16);
           if (!lineno.empty())
-            line_nums.insert(lineno);
+            {
+              std::string& sample_object = line_nums[lineno];
+              if (sample_object.empty())
+                sample_object = locs->object->name();
+            }
         }
 
       if (line_nums.size() > 1)
@@ -3042,10 +3088,12 @@ Symbol_table::detect_odr_violations(const Task* task,
           gold_warning(_("while linking %s: symbol '%s' defined in multiple "
                          "places (possible ODR violation):"),
                        output_file_name, demangle(symbol_name).c_str());
-          for (std::set<std::string>::const_iterator it2 = line_nums.begin();
-               it2 != line_nums.end();
-               ++it2)
-            fprintf(stderr, "  %s\n", it2->c_str());
+          for (std::map<std::string, std::string>::const_iterator it2 =
+                line_nums.begin();
+              it2 != line_nums.end();
+              ++it2)
+            fprintf(stderr, _("  %s from %s\n"),
+                    it2->first.c_str(), it2->second.c_str());
         }
     }
   // We only call one_addr2line() in this function, so we can clear its cache.
This page took 0.030293 seconds and 4 git commands to generate.