*** empty log message ***
[deliverable/binutils-gdb.git] / gold / symtab.cc
index 12e2762bdd0048273684ac74139822884b7fec6b..f0ba1d560fb5563d5bfa4d80f358c90ab7307959 100644 (file)
@@ -79,6 +79,7 @@ Symbol::init_fields(const char* name, const char* version,
   this->is_defined_in_discarded_section_ = false;
   this->undef_binding_set_ = false;
   this->undef_binding_weak_ = false;
+  this->is_predefined_ = false;
 }
 
 // Return the demangled version of the symbol's name, but only
@@ -133,7 +134,8 @@ void
 Symbol::init_base_output_data(const char* name, const char* version,
                              Output_data* od, elfcpp::STT type,
                              elfcpp::STB binding, elfcpp::STV visibility,
-                             unsigned char nonvis, bool offset_is_from_end)
+                             unsigned char nonvis, bool offset_is_from_end,
+                             bool is_predefined)
 {
   this->init_fields(name, version, type, binding, visibility, nonvis);
   this->u_.in_output_data.output_data = od;
@@ -141,6 +143,7 @@ Symbol::init_base_output_data(const char* name, const char* version,
   this->source_ = IN_OUTPUT_DATA;
   this->in_reg_ = true;
   this->in_real_elf_ = true;
+  this->is_predefined_ = is_predefined;
 }
 
 // Initialize the fields in the base class Symbol for a symbol defined
@@ -151,7 +154,8 @@ Symbol::init_base_output_segment(const char* name, const char* version,
                                 Output_segment* os, elfcpp::STT type,
                                 elfcpp::STB binding, elfcpp::STV visibility,
                                 unsigned char nonvis,
-                                Segment_offset_base offset_base)
+                                Segment_offset_base offset_base,
+                                bool is_predefined)
 {
   this->init_fields(name, version, type, binding, visibility, nonvis);
   this->u_.in_output_segment.output_segment = os;
@@ -159,6 +163,7 @@ Symbol::init_base_output_segment(const char* name, const char* version,
   this->source_ = IN_OUTPUT_SEGMENT;
   this->in_reg_ = true;
   this->in_real_elf_ = true;
+  this->is_predefined_ = is_predefined;
 }
 
 // Initialize the fields in the base class Symbol for a symbol defined
@@ -167,12 +172,14 @@ Symbol::init_base_output_segment(const char* name, const char* version,
 void
 Symbol::init_base_constant(const char* name, const char* version,
                           elfcpp::STT type, elfcpp::STB binding,
-                          elfcpp::STV visibility, unsigned char nonvis)
+                          elfcpp::STV visibility, unsigned char nonvis,
+                          bool is_predefined)
 {
   this->init_fields(name, version, type, binding, visibility, nonvis);
   this->source_ = IS_CONSTANT;
   this->in_reg_ = true;
   this->in_real_elf_ = true;
+  this->is_predefined_ = is_predefined;
 }
 
 // Initialize the fields in the base class Symbol for an undefined
@@ -227,10 +234,11 @@ Sized_symbol<size>::init_output_data(const char* name, const char* version,
                                     elfcpp::STB binding,
                                     elfcpp::STV visibility,
                                     unsigned char nonvis,
-                                    bool offset_is_from_end)
+                                    bool offset_is_from_end,
+                                    bool is_predefined)
 {
   this->init_base_output_data(name, version, od, type, binding, visibility,
-                             nonvis, offset_is_from_end);
+                             nonvis, offset_is_from_end, is_predefined);
   this->value_ = value;
   this->symsize_ = symsize;
 }
@@ -246,10 +254,11 @@ Sized_symbol<size>::init_output_segment(const char* name, const char* version,
                                        elfcpp::STB binding,
                                        elfcpp::STV visibility,
                                        unsigned char nonvis,
-                                       Segment_offset_base offset_base)
+                                       Segment_offset_base offset_base,
+                                       bool is_predefined)
 {
   this->init_base_output_segment(name, version, os, type, binding, visibility,
-                                nonvis, offset_base);
+                                nonvis, offset_base, is_predefined);
   this->value_ = value;
   this->symsize_ = symsize;
 }
@@ -262,9 +271,11 @@ void
 Sized_symbol<size>::init_constant(const char* name, const char* version,
                                  Value_type value, Size_type symsize,
                                  elfcpp::STT type, elfcpp::STB binding,
-                                 elfcpp::STV visibility, unsigned char nonvis)
+                                 elfcpp::STV visibility, unsigned char nonvis,
+                                 bool is_predefined)
 {
-  this->init_base_constant(name, version, type, binding, visibility, nonvis);
+  this->init_base_constant(name, version, type, binding, visibility, nonvis,
+                          is_predefined);
   this->value_ = value;
   this->symsize_ = symsize;
 }
@@ -282,6 +293,21 @@ Sized_symbol<size>::init_undefined(const char* name, const char* version,
   this->symsize_ = 0;
 }
 
+// Return an allocated string holding the symbol's name as
+// name@version.  This is used for relocatable links.
+
+std::string
+Symbol::versioned_name() const
+{
+  gold_assert(this->version_ != NULL);
+  std::string ret = this->name_;
+  ret.push_back('@');
+  if (this->is_def_)
+    ret.push_back('@');
+  ret += this->version_;
+  return ret;
+}
+
 // Return true if SHNDX represents a common symbol.
 
 bool
@@ -388,6 +414,7 @@ Symbol::should_add_dynsym_entry(Symbol_table* symtab) const
   // externally visible, we need to add it.
   if ((parameters->options().export_dynamic() || parameters->options().shared())
       && !this->is_from_dynobj()
+      && !this->is_undefined()
       && this->is_externally_visible())
     return true;
 
@@ -575,20 +602,16 @@ Symbol_table::gc_mark_undef_symbols(Layout* layout)
 }
 
 void
-Symbol_table::gc_mark_symbol_for_shlib(Symbol* sym)
+Symbol_table::gc_mark_symbol(Symbol* sym)
 {
-  if (!sym->is_from_dynobj() 
-      && sym->is_externally_visible())
+  // Add the object and section to the work list.
+  Relobj* obj = static_cast<Relobj*>(sym->object());
+  bool is_ordinary;
+  unsigned int shndx = sym->shndx(&is_ordinary);
+  if (is_ordinary && shndx != elfcpp::SHN_UNDEF)
     {
-      //Add the object and section to the work list.
-      Relobj* obj = static_cast<Relobj*>(sym->object());
-      bool is_ordinary;
-      unsigned int shndx = sym->shndx(&is_ordinary);
-      if (is_ordinary && shndx != elfcpp::SHN_UNDEF)
-        {
-          gold_assert(this->gc_!= NULL);
-          this->gc_->worklist().push(Section_id(obj, shndx));
-        }
+      gold_assert(this->gc_!= NULL);
+      this->gc_->worklist().push(Section_id(obj, shndx));
     }
 }
 
@@ -599,16 +622,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()); 
-      bool is_ordinary;
-      unsigned int shndx = sym->shndx(&is_ordinary);
-      if (is_ordinary && shndx != elfcpp::SHN_UNDEF)
-        {
-          gold_assert(this->gc_ != NULL);
-          this->gc_->worklist().push(Section_id(obj, shndx));
-        }
-    }
+    this->gc_mark_symbol(sym);
 }
 
 // Make TO a symbol which forwards to FROM.
@@ -1116,6 +1130,14 @@ Symbol_table::add_from_relobj(
       bool is_default_version = false;
       bool is_forced_local = false;
 
+      // FIXME: For incremental links, we don't store version information,
+      // so we need to ignore version symbols for now.
+      if (parameters->incremental_update() && ver != NULL)
+       {
+         namelen = ver - name;
+         ver = NULL;
+       }
+
       if (ver != NULL)
         {
           // The symbol name is of the form foo@VERSION or foo@@VERSION
@@ -1165,12 +1187,14 @@ Symbol_table::add_from_relobj(
        {
          memcpy(symbuf, p, sym_size);
          elfcpp::Sym_write<size, big_endian> sw(symbuf);
-         if (orig_st_shndx != elfcpp::SHN_UNDEF && is_ordinary)
+         if (orig_st_shndx != elfcpp::SHN_UNDEF
+             && is_ordinary
+             && relobj->e_type() == elfcpp::ET_REL)
            {
-             // Symbol values in object files are section relative.
-             // This is normally what we want, but since here we are
-             // converting the symbol to absolute we need to add the
-             // section address.  The section address in an object
+             // Symbol values in relocatable object files are section
+             // relative.  This is normally what we want, but since here
+             // we are converting the symbol to absolute we need to add
+             // the section address.  The section address in an object
              // file is normally zero, but people can use a linker
              // script to change it.
              sw.put_st_value(sym.get_st_value()
@@ -1211,15 +1235,20 @@ Symbol_table::add_from_relobj(
                                  is_default_version, *psym, st_shndx,
                                  is_ordinary, orig_st_shndx);
       
-      // If building a shared library using garbage collection, do not 
-      // treat externally visible symbols as garbage.
-      if (parameters->options().gc_sections() 
-          && parameters->options().shared())
-        this->gc_mark_symbol_for_shlib(res);
-
       if (is_forced_local)
        this->force_local(res);
 
+      // Do not treat this symbol as garbage if this symbol will be
+      // exported to the dynamic symbol table.  This is true when
+      // building a shared library or using --export-dynamic and
+      // the symbol is externally visible.
+      if (parameters->options().gc_sections()
+         && res->is_externally_visible()
+         && !res->is_from_dynobj()
+          && (parameters->options().shared()
+             || parameters->options().export_dynamic()))
+        this->gc_mark_symbol(res);
+
       if (is_defined_in_discarded_section)
        res->set_is_defined_in_discarded_section();
 
@@ -1317,6 +1346,11 @@ Symbol_table::add_from_dynobj(
       return;
     }
 
+  // FIXME: For incremental links, we don't store version information,
+  // so we need to ignore version symbols for now.
+  if (parameters->incremental_update())
+    versym = NULL;
+
   if (versym != NULL && versym_size / 2 < count)
     {
       dynobj->error(_("too few symbol versions"));
@@ -1654,7 +1688,9 @@ Symbol_table::define_special_symbol(const char** pname, const char** pversion,
        return NULL;
 
       *pname = oldsym->name();
-      if (!is_default_version)
+      if (is_default_version)
+       *pversion = this->namepool_.add(*pversion, true, NULL);
+      else
        *pversion = oldsym->version();
     }
   else
@@ -1843,7 +1879,8 @@ Symbol_table::do_define_in_output_data(
     return NULL;
 
   sym->init_output_data(name, version, od, value, symsize, type, binding,
-                       visibility, nonvis, offset_is_from_end);
+                       visibility, nonvis, offset_is_from_end,
+                       defined == PREDEFINED);
 
   if (oldsym == NULL)
     {
@@ -1855,7 +1892,7 @@ Symbol_table::do_define_in_output_data(
       return sym;
     }
 
-  if (Symbol_table::should_override_with_special(oldsym, defined))
+  if (Symbol_table::should_override_with_special(oldsym, type, defined))
     this->override_with_special(oldsym, sym);
 
   if (resolve_oldsym)
@@ -1956,7 +1993,8 @@ Symbol_table::do_define_in_output_segment(
     return NULL;
 
   sym->init_output_segment(name, version, os, value, symsize, type, binding,
-                          visibility, nonvis, offset_base);
+                          visibility, nonvis, offset_base,
+                          defined == PREDEFINED);
 
   if (oldsym == NULL)
     {
@@ -1968,7 +2006,7 @@ Symbol_table::do_define_in_output_segment(
       return sym;
     }
 
-  if (Symbol_table::should_override_with_special(oldsym, defined))
+  if (Symbol_table::should_override_with_special(oldsym, type, defined))
     this->override_with_special(oldsym, sym);
 
   if (resolve_oldsym)
@@ -2068,7 +2106,7 @@ Symbol_table::do_define_as_constant(
     return NULL;
 
   sym->init_constant(name, version, value, symsize, type, binding, visibility,
-                    nonvis);
+                    nonvis, defined == PREDEFINED);
 
   if (oldsym == NULL)
     {
@@ -2087,7 +2125,7 @@ Symbol_table::do_define_as_constant(
     }
 
   if (force_override
-      || Symbol_table::should_override_with_special(oldsym, defined))
+      || Symbol_table::should_override_with_special(oldsym, type, defined))
     this->override_with_special(oldsym, sym);
 
   if (resolve_oldsym)
@@ -2403,7 +2441,10 @@ Symbol_table::add_to_final_symtab(Symbol* sym, Stringpool* pool,
                                  unsigned int* pindex, off_t* poff)
 {
   sym->set_symtab_index(*pindex);
-  pool->add(sym->name(), false, NULL);
+  if (sym->version() == NULL || !parameters->options().relocatable())
+    pool->add(sym->name(), false, NULL);
+  else
+    pool->add(sym->versioned_name(), true, NULL);
   ++*pindex;
   *poff += elfcpp::Elf_sizes<size>::sym_size;
 }
@@ -2773,6 +2814,12 @@ Symbol_table::sized_write_globals(const Stringpool* sympool,
       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();
+
+      // If --no-gnu-unique is set, change STB_GNU_UNIQUE to STB_GLOBAL.
+      if (binding == elfcpp::STB_GNU_UNIQUE
+         && !parameters->options().gnu_unique())
+       binding = elfcpp::STB_GLOBAL;
+
       switch (sym->source())
        {
        case Symbol::FROM_OBJECT:
@@ -2912,7 +2959,10 @@ Symbol_table::sized_write_symbol(
     unsigned char* p) const
 {
   elfcpp::Sym_write<size, big_endian> osym(p);
-  osym.put_st_name(pool->get_offset(sym->name()));
+  if (sym->version() == NULL || !parameters->options().relocatable())
+    osym.put_st_name(pool->get_offset(sym->name()));
+  else
+    osym.put_st_name(pool->get_offset(sym->versioned_name()));
   osym.put_st_value(value);
   // Use a symbol size of zero for undefined symbols from shared libraries.
   if (shndx == elfcpp::SHN_UNDEF && sym->is_from_dynobj())
@@ -3269,6 +3319,12 @@ Warnings::issue_warning(const Symbol* sym,
                        size_t relnum, off_t reloffset) const
 {
   gold_assert(sym->has_warning());
+
+  // We don't want to issue a warning for a relocation against the
+  // symbol in the same object file in which the symbol is defined.
+  if (sym->object() == relinfo->object)
+    return;
+
   Warning_table::const_iterator p = this->warnings_.find(sym->name());
   gold_assert(p != this->warnings_.end());
   gold_warning_at_location(relinfo, relnum, reloffset,
This page took 0.028433 seconds and 4 git commands to generate.