+ // 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.)
+ // We use orig_sym here because we want the symbol exactly as it
+ // appears in the object file, not munged via our future processing.
+ if (parameters->detect_odr_violations()
+ && orig_sym.get_st_bind() == elfcpp::STB_WEAK
+ && to->binding() == elfcpp::STB_WEAK
+ && orig_sym.get_st_shndx() != elfcpp::SHN_UNDEF
+ && to->shndx() != elfcpp::SHN_UNDEF
+ && orig_sym.get_st_size() != 0 // Ignore weird 0-sized symbols.
+ && to->symsize() != 0
+ && (orig_sym.get_st_type() != to->type()
+ || orig_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_sym.get_st_shndx(), orig_sym.get_st_value() };
+ Symbol_location toloc = { to->object(), to->shndx(), to->value() };
+ this->candidate_odr_violations_[to->name()].insert(fromloc);
+ this->candidate_odr_violations_[to->name()].insert(toloc);
+ }
+}
+
+// Handle the core of symbol resolution. This is called with the
+// existing symbol, TO, and a bitflag describing the new symbol. This
+// returns true if we should override the existing symbol with the new
+// one, and returns false otherwise. It sets *ADJUST_COMMON_SIZES to
+// true if we should set the symbol size to the maximum of the TO and
+// FROM sizes. It handles error conditions.
+
+bool
+Symbol_table::should_override(const Symbol* to, unsigned int frombits,
+ Object* object, bool* adjust_common_sizes)
+{
+ *adjust_common_sizes = false;
+
+ unsigned int tobits = symbol_to_bits(to->binding(),
+ (to->source() == Symbol::FROM_OBJECT
+ && to->object()->is_dynamic()),
+ to->shndx(),
+ to->type());
+