PR 6048
[binutils-gdb.git] / gold / resolve.cc
index 21a7fc634f29927161694fccd9fe37fbe3890289..0ad990cd055db328df05adf6a657a00d04931a52 100644 (file)
@@ -32,6 +32,36 @@ namespace gold
 
 // Symbol methods used in this file.
 
+// This symbol is being overridden by another symbol whose version is
+// VERSION.  Update the VERSION_ field accordingly.
+
+inline void
+Symbol::override_version(const char* version)
+{
+  if (version == NULL)
+    {
+      // This is the case where this symbol is NAME/VERSION, and the
+      // version was not marked as hidden.  That makes it the default
+      // version, so we create NAME/NULL.  Later we see another symbol
+      // NAME/NULL, and that symbol is overriding this one.  In this
+      // case, since NAME/VERSION is the default, we make NAME/NULL
+      // override NAME/VERSION as well.  They are already the same
+      // Symbol structure.  Setting the VERSION_ field to NULL ensures
+      // that it will be output with the correct, empty, version.
+      this->version_ = version;
+    }
+  else
+    {
+      // This is the case where this symbol is NAME/VERSION_ONE, and
+      // now we see NAME/VERSION_TWO, and NAME/VERSION_TWO is
+      // overriding NAME.  If VERSION_ONE and VERSION_TWO are
+      // different, then this can only happen when VERSION_ONE is NULL
+      // and VERSION_TWO is not hidden.
+      gold_assert(this->version_ == version || this->version_ == NULL);
+      this->version_ = version;
+    }
+}
+
 // Override the fields in Symbol.
 
 template<int size, bool big_endian>
@@ -42,11 +72,7 @@ Symbol::override_base(const elfcpp::Sym<size, big_endian>& sym,
 {
   gold_assert(this->source_ == FROM_OBJECT);
   this->u_.from_object.object = object;
-  if (version != NULL && this->version() != version)
-    {
-      gold_assert(this->version() == NULL);
-      this->version_ = version;
-    }
+  this->override_version(version);
   this->u_.from_object.shndx = st_shndx;
   this->is_ordinary_shndx_ = is_ordinary;
   this->type_ = sym.get_st_type();
@@ -184,7 +210,7 @@ symbol_to_bits(elfcpp::STB binding, bool is_dynamic,
 // IS_ORDINARY is whether ST_SHNDX is a normal section index rather
 // than a special code.  ORIG_ST_SHNDX is the original section index,
 // before any munging because of discarded sections, except that all
-// non-ordinary section indexes are mapped to SHN_UNDEF.  VERSION of
+// non-ordinary section indexes are mapped to SHN_UNDEF.  VERSION is
 // the version of SYM.
 
 template<int size, bool big_endian>
@@ -281,7 +307,10 @@ Symbol_table::should_override(const Symbol* to, unsigned int frombits,
   *adjust_common_sizes = false;
 
   unsigned int tobits;
-  if (to->source() != Symbol::FROM_OBJECT)
+  if (to->source() == Symbol::IS_UNDEFINED)
+    tobits = symbol_to_bits(to->binding(), false, elfcpp::SHN_UNDEF, true,
+                           to->type());
+  else if (to->source() != Symbol::FROM_OBJECT)
     tobits = symbol_to_bits(to->binding(), false, elfcpp::SHN_ABS, false,
                            to->type());
   else
@@ -662,19 +691,15 @@ Symbol::override_base_with_special(const Symbol* from)
     case IN_OUTPUT_SEGMENT:
       this->u_.in_output_segment = from->u_.in_output_segment;
       break;
-    case CONSTANT:
+    case IS_CONSTANT:
+    case IS_UNDEFINED:
       break;
     default:
       gold_unreachable();
       break;
     }
 
-  if (from->version_ != NULL && this->version_ != from->version_)
-    {
-      gold_assert(this->version_ == NULL);
-      this->version_ = from->version_;
-    }
-
+  this->override_version(from->version_);
   this->type_ = from->type_;
   this->binding_ = from->binding_;
   this->visibility_ = from->visibility_;