From 8c1acaeb08b1951291b2977f679709a15fd73778 Mon Sep 17 00:00:00 2001 From: Dodji Seketeli Date: Mon, 25 Jan 2016 15:19:59 +0100 Subject: [PATCH] Comparing aliases of the same symbol must be done by pointer Different aliases of the same symbol are considered equal. This is at least how the elf_symbol::operator== is intended to work. What makes the different aliases be different is their pointer value. This patch fixes several spots where these assumptions are not respected. * src/abg-ir.cc (elf_symbol::operator==): Fix thinko and indentation. What was I thinking ... (elf_symbol::add_alias) (compute_aliases_for_elf_symbol): Do not compare aliases using the equality operator, because it considers all aliases of a given symbol as equal. Rather, use elf_symbol::is_main_symbol() to test if an alias is the main symbol alias. * src/abg-comp-filter.cc (function_name_changed_but_not_symbol): Likewise. * src/abg-corpus.cc (corpus::priv::build_unreferenced_symbols_tables): Likewise. * src/abg-writer.cc (write_elf_symbol_aliases): Likewise. Signed-off-by: Dodji Seketeli --- src/abg-comp-filter.cc | 2 +- src/abg-corpus.cc | 4 ++-- src/abg-ir.cc | 15 +++++++-------- src/abg-writer.cc | 6 +++--- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/abg-comp-filter.cc b/src/abg-comp-filter.cc index 16086491..89275e66 100644 --- a/src/abg-comp-filter.cc +++ b/src/abg-comp-filter.cc @@ -226,7 +226,7 @@ function_name_changed_but_not_symbol(const function_decl_sptr f, if (fs == ss) return true; for (elf_symbol_sptr s = fs->get_next_alias(); - s && s != fs->get_main_symbol(); + s && !s->is_main_symbol(); s = s->get_next_alias()) if (*s == *ss) return true; diff --git a/src/abg-corpus.cc b/src/abg-corpus.cc index fa27b0ae..a2ecbb53 100644 --- a/src/abg-corpus.cc +++ b/src/abg-corpus.cc @@ -1015,7 +1015,7 @@ corpus::priv::build_unreferenced_symbols_tables() { refed_funs[sym->get_id_string()] = true; for (elf_symbol_sptr a = sym->get_next_alias(); - a && (a != sym->get_main_symbol()); + a && !a->is_main_symbol(); a = a->get_next_alias()) refed_funs[a->get_id_string()] = true; } @@ -1027,7 +1027,7 @@ corpus::priv::build_unreferenced_symbols_tables() { refed_vars[sym->get_id_string()] = true; for (elf_symbol_sptr a = sym->get_next_alias(); - a && a != sym->get_main_symbol(); + a && !a->is_main_symbol(); a = a->get_next_alias()) refed_vars[a->get_id_string()] = true; } diff --git a/src/abg-ir.cc b/src/abg-ir.cc index 95a177f2..8a959f78 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -1158,10 +1158,10 @@ elf_symbol::add_alias(const elf_symbol_sptr& alias) { elf_symbol_sptr last_alias; for (elf_symbol_sptr a = get_next_alias(); - a && (a.get() != get_main_symbol().get()); + a && !a->is_main_symbol(); a = a->get_next_alias()) { - if (a->get_next_alias().get() == get_main_symbol().get()) + if (a->get_next_alias()->is_main_symbol()) { assert(last_alias == 0); last_alias = a; @@ -1457,10 +1457,9 @@ bool elf_symbol::operator==(const elf_symbol& other) const { bool are_equal = textually_equals(*this, other); - return are_equal; if (!are_equal) are_equal = get_alias_which_equals(other); - return are_equal; + return are_equal; } /// Test if the current symbol aliases another one. @@ -1478,7 +1477,7 @@ elf_symbol::does_alias(const elf_symbol& o) const return true; for (elf_symbol_sptr a = get_next_alias(); - a && a!= get_main_symbol(); + a && !a->is_main_symbol(); a = a->get_next_alias()) { if (o == *a) @@ -1517,7 +1516,7 @@ compute_aliases_for_elf_symbol(const elf_symbol& sym, { if (elf_symbol_sptr a = sym.get_next_alias()) - for (; a != sym.get_main_symbol(); a = a->get_next_alias()) + for (; a && !a->is_main_symbol(); a = a->get_next_alias()) aliases.push_back(a); else for (string_elf_symbols_map_type::const_iterator i = symtab.begin(); @@ -1529,12 +1528,12 @@ compute_aliases_for_elf_symbol(const elf_symbol& sym, { if (**j == sym) for (elf_symbol_sptr s = (*j)->get_next_alias(); - s && s != (*j)->get_main_symbol(); + s && !s->is_main_symbol(); s = s->get_next_alias()) aliases.push_back(s); else for (elf_symbol_sptr s = (*j)->get_next_alias(); - s && s != (*j)->get_main_symbol(); + s && !s->is_main_symbol(); s = s->get_next_alias()) if (*s == sym) aliases.push_back(*j); diff --git a/src/abg-writer.cc b/src/abg-writer.cc index 108e8723..d37dc16f 100644 --- a/src/abg-writer.cc +++ b/src/abg-writer.cc @@ -930,10 +930,10 @@ write_elf_symbol_aliases(const elf_symbol& sym, ostream& o) !s->is_main_symbol(); s = s->get_next_alias()) { - if (s->get_next_alias() == s->get_main_symbol()) - o << s->get_id_string() << "'"; + if (s->get_next_alias()->is_main_symbol()) + o << s->get_id_string() << "'"; else - o << s->get_id_string() << ","; + o << s->get_id_string() << ","; emitted = true; }