HomeFreeBSD

libctf: Improve check for duplicate SOU definitions in ctf_add_type()

Description

libctf: Improve check for duplicate SOU definitions in ctf_add_type()

When copying a struct or union from one CTF container to another,
ctf_add_type() checks whether it matches an existing type in the
destination container. It does so by looking for a type with the same
name and kind as the new type, and if one exists, it iterates over all
members of the source type and checks whether a member with matching
name and offset exists in the matched destination type. This can
produce false positives, for example because member types are not
compared, but this is not expected to arise in practice. If the match
fails, ctf_add_type() returns an error.

The procedure used for member comparison breaks down in the face of
anonymous struct and union members. ctf_member_iter() visits each
member in the source definition and looks up the corresponding member in
the desination definition by name using ctf_member_info(), but this
function will descend into anonymous members and thus fail to match.
Fix the problem by introducing a custom comparison routine which does
not assume member names are unique. This should also be faster for
types with many members; in the previous scheme, membcmp() would perform
a linear scan of the desination type's members to perform a lookup by
name. The new routine steps through the members of both types in a
single loop.

Approved by: re (gjb)
PR: 258763
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 105fd928b0b5b35ab529e5f6914788dc49582901)
(cherry picked from commit 39545ce06ca8088aecc68b92c028b78bcae888a2)

Details

Provenance
markjAuthored on Oct 4 2021, 4:28 PM
Parents
rG22082f15f9bb: When copying types from one CTF container to another, ensure that we
Branches
Unknown
Tags
Unknown