2010-02-01 Doug Kwan <dougkwan@google.com>
[deliverable/binutils-gdb.git] / gold / resolve.cc
index 89b10b9f9a8a8c3edbdc0360d12b07106527ca6a..3c7c7a838246b39edc57523928f865d0c161b66f 100644 (file)
@@ -1,6 +1,6 @@
 // resolve.cc -- symbol resolution for gold
 
-// Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
@@ -297,6 +297,38 @@ Symbol_table::resolve(Sized_symbol<size>* to,
         }
     }
 
+  // A new weak undefined reference, merging with an old weak
+  // reference, could be a One Definition Rule (ODR) violation --
+  // especially if the types or sizes of the references differ.  We'll
+  // store such pairs and look them up later to make sure they
+  // actually refer to the same lines of code.  We also check
+  // combinations of weak and strong, which might occur if one case is
+  // inline and the other is not.  (Note: not all ODR violations can
+  // be found this way, and not everything this finds is an ODR
+  // violation.  But it's helpful to warn about.)
+  bool to_is_ordinary;
+  if (parameters->options().detect_odr_violations()
+      && (sym.get_st_bind() == elfcpp::STB_WEAK
+         || to->binding() == elfcpp::STB_WEAK)
+      && orig_st_shndx != elfcpp::SHN_UNDEF
+      && to->shndx(&to_is_ordinary) != elfcpp::SHN_UNDEF
+      && to_is_ordinary
+      && sym.get_st_size() != 0    // Ignore weird 0-sized symbols.
+      && to->symsize() != 0
+      && (sym.get_st_type() != to->type()
+          || sym.get_st_size() != to->symsize())
+      // C does not have a concept of ODR, so we only need to do this
+      // on C++ symbols.  These have (mangled) names starting with _Z.
+      && to->name()[0] == '_' && to->name()[1] == 'Z')
+    {
+      Symbol_location fromloc
+          = { object, orig_st_shndx, sym.get_st_value() };
+      Symbol_location toloc = { to->object(), to->shndx(&to_is_ordinary),
+                               to->value() };
+      this->candidate_odr_violations_[to->name()].insert(fromloc);
+      this->candidate_odr_violations_[to->name()].insert(toloc);
+    }
+
   unsigned int frombits = symbol_to_bits(sym.get_st_bind(),
                                          object->is_dynamic(),
                                         st_shndx, is_ordinary,
@@ -304,7 +336,7 @@ Symbol_table::resolve(Sized_symbol<size>* to,
 
   bool adjust_common_sizes;
   typename Sized_symbol<size>::Size_type tosize = to->symsize();
-  if (Symbol_table::should_override(to, frombits, object,
+  if (Symbol_table::should_override(to, frombits, OBJECT, object,
                                    &adjust_common_sizes))
     {
       this->override(to, sym, st_shndx, is_ordinary, object, version);
@@ -326,46 +358,16 @@ Symbol_table::resolve(Sized_symbol<size>* to,
        Symbol_table::report_resolve_problem(false,
                                             _("common of '%s' overriding "
                                               "smaller common"),
-                                            to, object);
+                                            to, OBJECT, object);
       else if (tosize < sym.get_st_size())
        Symbol_table::report_resolve_problem(false,
                                             _("common of '%s' overidden by "
                                               "larger common"),
-                                            to, object);
+                                            to, OBJECT, object);
       else
        Symbol_table::report_resolve_problem(false,
                                             _("multiple common of '%s'"),
-                                            to, object);
-    }
-
-  // A new weak undefined reference, merging with an old weak
-  // reference, could be a One Definition Rule (ODR) violation --
-  // especially if the types or sizes of the references differ.  We'll
-  // store such pairs and look them up later to make sure they
-  // actually refer to the same lines of code.  (Note: not all ODR
-  // violations can be found this way, and not everything this finds
-  // is an ODR violation.  But it's helpful to warn about.)
-  bool to_is_ordinary;
-  if (parameters->options().detect_odr_violations()
-      && sym.get_st_bind() == elfcpp::STB_WEAK
-      && to->binding() == elfcpp::STB_WEAK
-      && orig_st_shndx != elfcpp::SHN_UNDEF
-      && to->shndx(&to_is_ordinary) != elfcpp::SHN_UNDEF
-      && to_is_ordinary
-      && sym.get_st_size() != 0    // Ignore weird 0-sized symbols.
-      && to->symsize() != 0
-      && (sym.get_st_type() != to->type()
-          || sym.get_st_size() != to->symsize())
-      // C does not have a concept of ODR, so we only need to do this
-      // on C++ symbols.  These have (mangled) names starting with _Z.
-      && to->name()[0] == '_' && to->name()[1] == 'Z')
-    {
-      Symbol_location fromloc
-          = { object, orig_st_shndx, sym.get_st_value() };
-      Symbol_location toloc = { to->object(), to->shndx(&to_is_ordinary),
-                               to->value() };
-      this->candidate_odr_violations_[to->name()].insert(fromloc);
-      this->candidate_odr_violations_[to->name()].insert(toloc);
+                                            to, OBJECT, object);
     }
 }
 
@@ -378,7 +380,8 @@ Symbol_table::resolve(Sized_symbol<size>* to,
 
 bool
 Symbol_table::should_override(const Symbol* to, unsigned int frombits,
-                              Object* object, bool* adjust_common_sizes)
+                              Defined defined, Object* object,
+                             bool* adjust_common_sizes)
 {
   *adjust_common_sizes = false;
 
@@ -436,12 +439,13 @@ Symbol_table::should_override(const Symbol* to, unsigned int frombits,
       // --just-symbols, then don't warn.  This is for compatibility
       // with the GNU linker.  FIXME: This is a hack.
       if ((to->source() == Symbol::FROM_OBJECT && to->object()->just_symbols())
-          || object->just_symbols())
+          || (object != NULL && object->just_symbols()))
         return false;
 
-      Symbol_table::report_resolve_problem(true,
-                                          _("multiple definition of '%s'"),
-                                          to, object);
+      if (!parameters->options().muldefs())
+       Symbol_table::report_resolve_problem(true,
+                                            _("multiple definition of '%s'"),
+                                            to, defined, object);
       return false;
 
     case WEAK_DEF * 16 + DEF:
@@ -481,7 +485,7 @@ Symbol_table::should_override(const Symbol* to, unsigned int frombits,
        Symbol_table::report_resolve_problem(false,
                                             _("definition of '%s' overriding "
                                               "common"),
-                                            to, object);
+                                            to, defined, object);
       return true;
 
     case DEF * 16 + WEAK_DEF:
@@ -516,7 +520,7 @@ Symbol_table::should_override(const Symbol* to, unsigned int frombits,
        Symbol_table::report_resolve_problem(false,
                                             _("definition of '%s' overriding "
                                               "dynamic common definition"),
-                                            to, object);
+                                            to, defined, object);
       return true;
 
     case DEF * 16 + DYN_DEF:
@@ -636,7 +640,7 @@ Symbol_table::should_override(const Symbol* to, unsigned int frombits,
        Symbol_table::report_resolve_problem(false,
                                             _("common '%s' overridden by "
                                               "previous definition"),
-                                            to, object);
+                                            to, defined, object);
       return false;
 
     case WEAK_DEF * 16 + COMMON:
@@ -745,7 +749,8 @@ Symbol_table::should_override(const Symbol* to, unsigned int frombits,
 // Issue an error or warning due to symbol resolution.  IS_ERROR
 // indicates an error rather than a warning.  MSG is the error
 // message; it is expected to have a %s for the symbol name.  TO is
-// the existing symbol.  OBJECT is where the new symbol was found.
+// the existing symbol.  DEFINED/OBJECT is where the new symbol was
+// found.
 
 // FIXME: We should have better location information here.  When the
 // symbol is defined, we should be able to pull the location from the
@@ -753,7 +758,8 @@ Symbol_table::should_override(const Symbol* to, unsigned int frombits,
 
 void
 Symbol_table::report_resolve_problem(bool is_error, const char* msg,
-                                    const Symbol* to, Object* object)
+                                    const Symbol* to, Defined defined,
+                                    Object* object)
 {
   std::string demangled(to->demangled_name());
   size_t len = strlen(msg) + demangled.length() + 10;
@@ -761,10 +767,27 @@ Symbol_table::report_resolve_problem(bool is_error, const char* msg,
   snprintf(buf, len, msg, demangled.c_str());
 
   const char* objname;
-  if (object != NULL)
-    objname = object->name().c_str();
-  else
-    objname = _("command line");
+  switch (defined)
+    {
+    case OBJECT:
+      objname = object->name().c_str();
+      break;
+    case COPY:
+      objname = _("COPY reloc");
+      break;
+    case DEFSYM:
+    case UNDEFINED:
+      objname = _("command line");
+      break;
+    case SCRIPT:
+      objname = _("linker script");
+      break;
+    case PREDEFINED:
+      objname = _("linker defined");
+      break;
+    default:
+      gold_unreachable();
+    }
 
   if (is_error)
     gold_error("%s: %s", objname, buf);
@@ -785,11 +808,11 @@ Symbol_table::report_resolve_problem(bool is_error, const char* msg,
 // defining special symbols.
 
 bool
-Symbol_table::should_override_with_special(const Symbol* to)
+Symbol_table::should_override_with_special(const Symbol* to, Defined defined)
 {
   bool adjust_common_sizes;
   unsigned int frombits = global_flag | regular_flag | def_flag;
-  bool ret = Symbol_table::should_override(to, frombits, NULL,
+  bool ret = Symbol_table::should_override(to, frombits, defined, NULL,
                                           &adjust_common_sizes);
   gold_assert(!adjust_common_sizes);
   return ret;
@@ -838,9 +861,8 @@ Symbol::override_base_with_special(const Symbol* from)
 
   // We shouldn't see these flags.  If we do, we need to handle them
   // somehow.
-  gold_assert(!from->is_target_special_ || this->is_target_special_);
   gold_assert(!from->is_forwarder_);
-  gold_assert(!from->has_plt_offset_);
+  gold_assert(!from->has_plt_offset());
   gold_assert(!from->has_warning_);
   gold_assert(!from->is_copied_from_dynobj_);
   gold_assert(!from->is_forced_local_);
This page took 0.025966 seconds and 4 git commands to generate.