* i386.cc (Target_i386::got_section): If -z now, make .got.plt a
[deliverable/binutils-gdb.git] / gold / symtab.cc
index 92f83af852b56bdc3da38386b2ab2e3429abfd1a..26d803262d57ba9c51ce7fcd51e967b7e03aa5ae 100644 (file)
@@ -293,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
@@ -399,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;
 
@@ -1867,7 +1883,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)
@@ -1981,7 +1997,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)
@@ -2100,7 +2116,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)
@@ -2416,7 +2432,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;
 }
@@ -2925,7 +2944,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())
@@ -3282,6 +3304,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.025258 seconds and 4 git commands to generate.