+// This is called when we see a symbol NAME/VERSION, and the symbol
+// already exists in the symbol table, and VERSION is marked as being
+// the default version. SYM is the NAME/VERSION symbol we just added.
+// DEFAULT_IS_NEW is true if this is the first time we have seen the
+// symbol NAME/NULL. PDEF points to the entry for NAME/NULL.
+
+template<int size, bool big_endian>
+void
+Symbol_table::define_default_version(Sized_symbol<size>* sym,
+ bool default_is_new,
+ Symbol_table_type::iterator pdef)
+{
+ if (default_is_new)
+ {
+ // This is the first time we have seen NAME/NULL. Make
+ // NAME/NULL point to NAME/VERSION, and mark SYM as the default
+ // version.
+ pdef->second = sym;
+ sym->set_is_default();
+ }
+ else if (pdef->second == sym)
+ {
+ // NAME/NULL already points to NAME/VERSION. Don't mark the
+ // symbol as the default if it is not already the default.
+ }
+ else
+ {
+ // This is the unfortunate case where we already have entries
+ // for both NAME/VERSION and NAME/NULL. We now see a symbol
+ // NAME/VERSION where VERSION is the default version. We have
+ // already resolved this new symbol with the existing
+ // NAME/VERSION symbol.
+
+ // It's possible that NAME/NULL and NAME/VERSION are both
+ // defined in regular objects. This can only happen if one
+ // object file defines foo and another defines foo@@ver. This
+ // is somewhat obscure, but we call it a multiple definition
+ // error.
+
+ // It's possible that NAME/NULL actually has a version, in which
+ // case it won't be the same as VERSION. This happens with
+ // ver_test_7.so in the testsuite for the symbol t2_2. We see
+ // t2_2@@VER2, so we define both t2_2/VER2 and t2_2/NULL. We
+ // then see an unadorned t2_2 in an object file and give it
+ // version VER1 from the version script. This looks like a
+ // default definition for VER1, so it looks like we should merge
+ // t2_2/NULL with t2_2/VER1. That doesn't make sense, but it's
+ // not obvious that this is an error, either. So we just punt.
+
+ // If one of the symbols has non-default visibility, and the
+ // other is defined in a shared object, then they are different
+ // symbols.
+
+ // If the two symbols are from different shared objects,
+ // they are different symbols.
+
+ // Otherwise, we just resolve the symbols as though they were
+ // the same.
+
+ if (pdef->second->version() != NULL)
+ gold_assert(pdef->second->version() != sym->version());
+ else if (sym->visibility() != elfcpp::STV_DEFAULT
+ && pdef->second->is_from_dynobj())
+ ;
+ else if (pdef->second->visibility() != elfcpp::STV_DEFAULT
+ && sym->is_from_dynobj())
+ ;
+ else if (pdef->second->is_from_dynobj()
+ && sym->is_from_dynobj()
+ && pdef->second->object() != sym->object())
+ ;
+ else
+ {
+ const Sized_symbol<size>* symdef;
+ symdef = this->get_sized_symbol<size>(pdef->second);
+ Symbol_table::resolve<size, big_endian>(sym, symdef);
+ this->make_forwarder(pdef->second, sym);
+ pdef->second = sym;
+ sym->set_is_default();
+ }
+ }
+}
+