2011-03-04 Michael Snyder <msnyder@msnyder-server.eng.vmware.com>
[deliverable/binutils-gdb.git] / gold / resolve.cc
index 3c7c7a838246b39edc57523928f865d0c161b66f..a9a89fa65d68dfee86dffafebd212abdbd30f9a3 100644 (file)
@@ -195,7 +195,7 @@ symbol_to_bits(elfcpp::STB binding, bool is_dynamic,
     default:
       // Any target which wants to handle STB_LOOS, etc., needs to
       // define a resolve method.
-      gold_error(_("unsupported symbol binding"));
+      gold_error(_("unsupported symbol binding %d"), static_cast<int>(binding));
       bits = global_flag;
     }
 
@@ -335,18 +335,33 @@ Symbol_table::resolve(Sized_symbol<size>* to,
                                          sym.get_st_type());
 
   bool adjust_common_sizes;
+  bool adjust_dyndef;
   typename Sized_symbol<size>::Size_type tosize = to->symsize();
   if (Symbol_table::should_override(to, frombits, OBJECT, object,
-                                   &adjust_common_sizes))
+                                   &adjust_common_sizes,
+                                   &adjust_dyndef))
     {
+      elfcpp::STB tobinding = to->binding();
       this->override(to, sym, st_shndx, is_ordinary, object, version);
       if (adjust_common_sizes && tosize > to->symsize())
         to->set_symsize(tosize);
+      if (adjust_dyndef)
+       {
+         // We are overriding an UNDEF or WEAK UNDEF with a DYN DEF.
+         // Remember which kind of UNDEF it was for future reference.
+         to->set_undef_binding(tobinding);
+       }
     }
   else
     {
       if (adjust_common_sizes && sym.get_st_size() > tosize)
         to->set_symsize(sym.get_st_size());
+      if (adjust_dyndef)
+       {
+         // We are keeping a DYN DEF after seeing an UNDEF or WEAK UNDEF.
+         // Remember which kind of UNDEF it was.
+         to->set_undef_binding(sym.get_st_bind());
+       }
       // The ELF ABI says that even for a reference to a symbol we
       // merge the visibility.
       to->override_visibility(sym.get_st_visibility());
@@ -381,9 +396,11 @@ Symbol_table::resolve(Sized_symbol<size>* to,
 bool
 Symbol_table::should_override(const Symbol* to, unsigned int frombits,
                               Defined defined, Object* object,
-                             bool* adjust_common_sizes)
+                             bool* adjust_common_sizes,
+                             bool* adjust_dyndef)
 {
   *adjust_common_sizes = false;
+  *adjust_dyndef = false;
 
   unsigned int tobits;
   if (to->source() == Symbol::IS_UNDEFINED)
@@ -531,12 +548,17 @@ Symbol_table::should_override(const Symbol* to, unsigned int frombits,
       return false;
 
     case UNDEF * 16 + DYN_DEF:
-    case WEAK_UNDEF * 16 + DYN_DEF:
     case DYN_UNDEF * 16 + DYN_DEF:
     case DYN_WEAK_UNDEF * 16 + DYN_DEF:
       // Use a dynamic definition if we have a reference.
       return true;
 
+    case WEAK_UNDEF * 16 + DYN_DEF:
+      // When overriding a weak undef by a dynamic definition,
+      // we need to remember that the original undef was weak.
+      *adjust_dyndef = true;
+      return true;
+
     case COMMON * 16 + DYN_DEF:
     case WEAK_COMMON * 16 + DYN_DEF:
     case DYN_COMMON * 16 + DYN_DEF:
@@ -554,12 +576,22 @@ Symbol_table::should_override(const Symbol* to, unsigned int frombits,
       return false;
 
     case UNDEF * 16 + DYN_WEAK_DEF:
-    case WEAK_UNDEF * 16 + DYN_WEAK_DEF:
+      // When overriding an undef by a dynamic weak definition,
+      // we need to remember that the original undef was not weak.
+      *adjust_dyndef = true;
+      return true;
+
     case DYN_UNDEF * 16 + DYN_WEAK_DEF:
     case DYN_WEAK_UNDEF * 16 + DYN_WEAK_DEF:
       // Use a weak dynamic definition if we have a reference.
       return true;
 
+    case WEAK_UNDEF * 16 + DYN_WEAK_DEF:
+      // When overriding a weak undef by a dynamic definition,
+      // we need to remember that the original undef was weak.
+      *adjust_dyndef = true;
+      return true;
+
     case COMMON * 16 + DYN_WEAK_DEF:
     case WEAK_COMMON * 16 + DYN_WEAK_DEF:
     case DYN_COMMON * 16 + DYN_WEAK_DEF:
@@ -570,12 +602,16 @@ Symbol_table::should_override(const Symbol* to, unsigned int frombits,
 
     case DEF * 16 + UNDEF:
     case WEAK_DEF * 16 + UNDEF:
-    case DYN_DEF * 16 + UNDEF:
-    case DYN_WEAK_DEF * 16 + UNDEF:
     case UNDEF * 16 + UNDEF:
       // A new undefined reference tells us nothing.
       return false;
 
+    case DYN_DEF * 16 + UNDEF:
+    case DYN_WEAK_DEF * 16 + UNDEF:
+      // For a dynamic def, we need to remember which kind of undef we see.
+      *adjust_dyndef = true;
+      return false;
+
     case WEAK_UNDEF * 16 + UNDEF:
     case DYN_UNDEF * 16 + UNDEF:
     case DYN_WEAK_UNDEF * 16 + UNDEF:
@@ -591,17 +627,28 @@ Symbol_table::should_override(const Symbol* to, unsigned int frombits,
 
     case DEF * 16 + WEAK_UNDEF:
     case WEAK_DEF * 16 + WEAK_UNDEF:
-    case DYN_DEF * 16 + WEAK_UNDEF:
-    case DYN_WEAK_DEF * 16 + WEAK_UNDEF:
     case UNDEF * 16 + WEAK_UNDEF:
     case WEAK_UNDEF * 16 + WEAK_UNDEF:
     case DYN_UNDEF * 16 + WEAK_UNDEF:
-    case DYN_WEAK_UNDEF * 16 + WEAK_UNDEF:
     case COMMON * 16 + WEAK_UNDEF:
     case WEAK_COMMON * 16 + WEAK_UNDEF:
     case DYN_COMMON * 16 + WEAK_UNDEF:
     case DYN_WEAK_COMMON * 16 + WEAK_UNDEF:
-      // A new weak undefined reference tells us nothing.
+      // A new weak undefined reference tells us nothing unless the
+      // exisiting symbol is a dynamic weak reference.
+      return false;
+
+    case DYN_WEAK_UNDEF * 16 + WEAK_UNDEF:
+      // A new weak reference overrides an existing dynamic weak reference.
+      // This is necessary because a dynamic weak reference remembers
+      // the old binding, which may not be weak.  If we keeps the existing
+      // dynamic weak reference, the weakness may be dropped in the output.
+      return true;
+
+    case DYN_DEF * 16 + WEAK_UNDEF:
+    case DYN_WEAK_DEF * 16 + WEAK_UNDEF:
+      // For a dynamic def, we need to remember which kind of undef we see.
+      *adjust_dyndef = true;
       return false;
 
     case DEF * 16 + DYN_UNDEF:
@@ -811,10 +858,12 @@ bool
 Symbol_table::should_override_with_special(const Symbol* to, Defined defined)
 {
   bool adjust_common_sizes;
+  bool adjust_dyn_def;
   unsigned int frombits = global_flag | regular_flag | def_flag;
   bool ret = Symbol_table::should_override(to, frombits, defined, NULL,
-                                          &adjust_common_sizes);
-  gold_assert(!adjust_common_sizes);
+                                          &adjust_common_sizes,
+                                          &adjust_dyn_def);
+  gold_assert(!adjust_common_sizes && !adjust_dyn_def);
   return ret;
 }
 
@@ -916,7 +965,10 @@ Symbol_table::override_with_special(Sized_symbol<size>* tosym,
 // script to restrict this to only the ones needed for implemented
 // targets.
 
-#ifdef HAVE_TARGET_32_LITTLE
+// We have to instantiate both big and little endian versions because
+// these are used by other templates that depends on size only.
+
+#if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
 template
 void
 Symbol_table::resolve<32, false>(
@@ -927,9 +979,7 @@ Symbol_table::resolve<32, false>(
     unsigned int orig_st_shndx,
     Object* object,
     const char* version);
-#endif
 
-#ifdef HAVE_TARGET_32_BIG
 template
 void
 Symbol_table::resolve<32, true>(
@@ -942,7 +992,7 @@ Symbol_table::resolve<32, true>(
     const char* version);
 #endif
 
-#ifdef HAVE_TARGET_64_LITTLE
+#if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
 template
 void
 Symbol_table::resolve<64, false>(
@@ -953,9 +1003,7 @@ Symbol_table::resolve<64, false>(
     unsigned int orig_st_shndx,
     Object* object,
     const char* version);
-#endif
 
-#ifdef HAVE_TARGET_64_BIG
 template
 void
 Symbol_table::resolve<64, true>(
This page took 0.024614 seconds and 4 git commands to generate.