public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
From: Dodji Seketeli <dodji@redhat.com>
To: Giuliano Procida <gprocida@google.com>
Cc: libabigail@sourceware.org
Subject: Re: [PATCH 2/2] writer: Avoid using dynamic hashing in type maps
Date: Thu, 10 Sep 2020 16:27:45 +0200	[thread overview]
Message-ID: <878sdhso4e.fsf@redhat.com> (raw)
In-Reply-To: <87r1rbrlds.fsf@redhat.com> (Dodji Seketeli's message of "Wed, 09 Sep 2020 17:59:59 +0200")

Hello,

Dodji Seketeli <dodji@redhat.com> writes:

> Hey,
>
> Giuliano Procida <gprocida@google.com> writes:
>
>> This probably fixes the hash/equality issue. At least, it makes no
>> difference (for a simple stock kernel) on top of, or without, my change
>> that switched to using plain pointers.
>
> Okay, that is good to know, thanks.
>
>>
>> It does cause the XML writer to emit (more) XML elements with duplicate
>> ids, perhaps where anonymous types are being identified very late in the
>> process. You can see this with the following, before and after the change.
>> Admittedly, there are already about 400 ids that appear to be duplicated!
>>
>> find tests -name '*abi' | while read x; do sed -En "s;.*
>> id='([^']*)'.*;\1;p" $x | sort | uniq -c | grep -vw 1 | sort -nr | sed
>> "s;^;$x: ;"; done
>
>
> This is interesting.  I went through most of the duplicated IDs reported
> by your script.  Thank you for putting this together.
>
> I have just filled an enhancement request for a potential tool à la
> abilint (probably reusing abilint infrastructure) that would
> analyze/sanitize abixml files to detect potential pathological cases for
> these: https://sourceware.org/bugzilla/show_bug.cgi?id=26591.
>
> Most of the current redundant IDs in the tests/data/test-read-dwarf are
> for array sub-ranges.  They are are always sub-types of arrays in C and
> C++.  They have their own ID but we don't de-duplicate these at the
> moment.  So this is not an symptom of a problem per se.
>
> There are other cases that are mostly related to C++.  I have listed
> these in the enhancement request above.
>
> From manual inspection of the cases reported by your script, I haven't
> noticed a case resulting from a type equality problem.  If you do, I'd
> be glad to look into.
>
>
>> I'd still prefer less code to more code and to switch to making the XML
>> writer not care about equality at all.
>
> I still think that the writer should try (as much as possible, but no
> more) to ensure that types are emitted just once.  In the past, it was
> the first point where this was done.  Then slowly, we built
> de-duplication features throughout the stack.  They are not perfect yet,
> so I think we still need to ensuring that at the writer level.  Much
> less now, but we still do.
>
> Note that we do much less de-duplication at the level of the writer than
> we used to do in the past.  Hopefully at some point we won't need it
> that anymore, and that point I'll be happy to remove that from the
> writer.  But I don't think that time has come yet.
>
> [...]
>
>>> --- a/src/abg-ir.cc
>>> +++ b/src/abg-ir.cc
>>> @@ -23085,6 +23085,45 @@ size_t
>>>  hash_type_or_decl(const type_or_decl_base_sptr& tod)
>>>  {return hash_type_or_decl(tod.get());}
>>>
>>> +/// Hash a type by either returning the pointer value of its canonical
>>> +/// type or by returning a constant if the type doesn't have a
>>> +/// canonical type.
>>> +///
>>> +/// @param t the type to consider.
>>> +///
>>> +/// @return the hash value.
>>> +size_t
>>> +hash_as_canonical_type_or_constant(const type_base *t)
>>> +{
>>> +  type_base *canonical_type = 0;
>>> +
>>> +  if (t)
>>> +    canonical_type = t->get_naked_canonical_type();
>>> +
>>> +  if (!canonical_type)
>>> +    {
>>>
>>
>> Is the following code definitely compatible with the definition of equality
>> or is there a chance you'll determine two different canonical types of
>> definitions of declarations but equality would actually succeed? If you
>> have any doubts, then it's safer to remove this.
>
> If two decl-only classes have definitions, then their definitions are
> compared.
>
> So I do expect the following code to comply with the equality code, yes.
>
>>
>>
>>> +      // If the type doesn't have a canonical type, maybe it's because
>>> +      // it's a declaration-only type?  If that's the case, let's try
>>> +      // to get the canonical type of the definition of this
>>> +      // declaration.
>>> +      decl_base *decl = is_decl(t);
>>> +      if (decl
>>> +         && decl->get_is_declaration_only()
>>> +         && decl->get_naked_definition_of_declaration())
>>> +       {
>>> +         type_base *definition =
>>> +           is_type(decl->get_naked_definition_of_declaration());
>>> +         ABG_ASSERT(definition);
>>> +         canonical_type = definition->get_naked_canonical_type();
>>> +       }
>>> +    }
>>> +
>>> +  if (canonical_type)
>>> +    return reinterpret_cast<size_t>(canonical_type);
>>> +
>>> +  return 0xDEADBABE;
>>> +}
>>> +
>>>  /// Test if the pretty representation of a given @ref function_decl is
>>>  /// lexicographically less then the pretty representation of another
>>>  /// @ref function_decl.
>>> diff --git a/src/abg-writer.cc b/src/abg-writer.cc
>>> index 4c751c2..59060e1 100644
>>> --- a/src/abg-writer.cc
>>> +++ b/src/abg-writer.cc
>>> @@ -136,7 +136,7 @@ struct type_hasher
>>>  {
>>>    size_t
>>>    operator()(const type_base* t) const
>>> -  {return hash_type(t);}
>>> +  {return hash_as_canonical_type_or_constant(t);}
>>>  }; // end struct type_hasher
>>>
>>>  /// A convenience typedef for a map that associates a pointer to type
>>> diff --git a/tests/data/test-read-dwarf/test16-pr18904.so.abi
>>> b/tests/data/test-read-dwarf/test16-pr18904.so.abi
>>> index 0075a6e..377d322 100644
>>>
>>
>> Modulo my comments above,
>>
>> Signed-off-by: Giuliano Procida <gprocida@google.com>
>
> Thanks! 

Applied to master at https://sourceware.org/git/?p=libabigail.git;a=commit;h=5cf2473d3ca3acdb5664313e33c4ced618cf023a.

Cheers,

-- 
		Dodji


      parent reply	other threads:[~2020-09-10 14:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-09  8:50 Dodji Seketeli
     [not found] ` <CAGvU0HkgoizCB9X4idnfdyJF2cdpWMBQZhm4Jd+9uR=UnD9s=g@mail.gmail.com>
     [not found]   ` <87r1rbrlds.fsf@redhat.com>
2020-09-10 14:27     ` Dodji Seketeli [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878sdhso4e.fsf@redhat.com \
    --to=dodji@redhat.com \
    --cc=gprocida@google.com \
    --cc=libabigail@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).