From patchwork Mon Jun 15 21:07:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 39636 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BAB143893652; Mon, 15 Jun 2020 21:07:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BAB143893652 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1592255278; bh=WVVJmLVC0eVWsvz4Z5KdxkYFbQRRA+UieAgLKbsDSf0=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=qkDbAL+97FncnDvGIDGJl2k/LMhrgHrp9xNrECta49zB0Ki9nig0E7XWpfJi5+ZqV NaBIh7WmroEjMWXYXJSpthdftB3aF3+tK+Ed5W73ukk22AhYyHEMREM+ea+kYGb+ux 29q4XKc3WcNp4OFaLCz1JfLpkfYXAY4QlJ21ijRc= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by sourceware.org (Postfix) with ESMTPS id BA5D63893646 for ; Mon, 15 Jun 2020 21:07:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BA5D63893646 Received: by mail-qk1-x74a.google.com with SMTP id w14so15299126qkb.0 for ; Mon, 15 Jun 2020 14:07:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=WVVJmLVC0eVWsvz4Z5KdxkYFbQRRA+UieAgLKbsDSf0=; b=Fvhau+yweOMlr2bNKpDjKBY6kd06XybFln5gP0bvQXneRBi5s8gqWN2mRryQ2D9tJB gZvZ09LC1MPVoQ4VeZefGA6BX5cETcf+CXGe2LCcIpaElZ0KrsU9SbKGDmW4jlwgqCB/ b+OMTZ/aRqEOywn296JFlT0uzG3u2Yk6DBgN0XAMaRwICev5rAAvifrRZCIytkWA3e9v TvYt47ccxE/VEjHkgBrhEJjnUuwy4Cw8isFbMnoT7whhmpP6EwRaa0a0ErbtowuGVH8u WXE0/4M4HPk0s7OfELaXwInUVHQkO1vYm7gohp70DsimMr7FL/3i/yiWZlWBtO5JaHeH Vwcg== X-Gm-Message-State: AOAM533hmGrVtTstlKNVoBz6S5KM4SLJqa6fmkaatp5N4/MnxPgsV1i/ ddWz7VWxupOFyM7QwvgADqgvT1Ykpm1GlTWdQdqsi+ZWRmpZ4I+gNLFy5mP4AMAYIebuhViu4xj jKV5CtqoqILekl9enYZ/aQwVTL+dwIKN0HyCOTbHeVjl+NOkVncVD4JE5kBTXIfT+rdvML4E= X-Google-Smtp-Source: ABdhPJy9ntxNOWL9TC92D04kBxbAIGKINC8QfXqSHJrz4tmAVwE7xtqZExoIZ0/dU8VCWhMUm0NfH3uIMx/GFA== X-Received: by 2002:a0c:f9c3:: with SMTP id j3mr27443686qvo.125.1592255271130; Mon, 15 Jun 2020 14:07:51 -0700 (PDT) Date: Mon, 15 Jun 2020 22:07:41 +0100 In-Reply-To: <20200615210741.92897-1-gprocida@google.com> Message-Id: <20200615210741.92897-2-gprocida@google.com> Mime-Version: 1.0 References: <20200612095917.2146-2-gprocida@google.com> <20200615210741.92897-1-gprocida@google.com> X-Mailer: git-send-email 2.27.0.290.gba653c62da-goog Subject: [PATCH v2 1/1] abg-writer: Add support for stable hash type ids. To: libabigail@sourceware.org X-Spam-Status: No, score=-24.1 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Giuliano Procida via Libabigail From: Giuliano Procida Reply-To: Giuliano Procida Cc: maennich@google.com, kernel-team@android.com, mark@klomp.org, gprocida@google.com Errors-To: libabigail-bounces@sourceware.org Sender: "Libabigail" The type ids currently emitted by the XML writer are simply type-id-1, type-id-2 etc. Additions or removals of types early in this sequence result in cascading changes to many other XML elements. This commit adds support for stable type ids in the form of hashes of libabigail's internal type names. On fairly rare occasions (typically involving unnamed types), the names of two distinct types can be the same. In any case, if there is a hash collision the XML writer will find the next unused id and so preserve uniqueness. Diffs between large XML files produced using --type-id-style hash will be much smaller and easier to review. This also commit adds some test cases to verify that the hashing is actually stable across architectures. * doc/manuals/abidw.rst: Replace stray documentation of --named-type-ids with documention of new --type-id-style option. * include/abg-writer.h (type_id_style_kind): Add new enum. (set_type_id_style): Add new write_context setter. (set_common_options): Set type id style in write context. * include/abg-hash.h (fnv_hash): Declare new 32-bit FNV-1a hash function in abigail::hashing namespace. * src/abg-hash.h (fnv_hash): Define new 32-bit FNV-1a hash function in abigail::hashing namespace. * src/abg-writer.cc (write_context): Add m_type_id_style member to record type style to use, defaulting to SEQUENCE_TYPE_ID_STYLE; add m_used_type_id_hashes to record already-used hashes. (write_context::get_type_id_style): Add new getter. (write_context::set_type_id_style): Add new setter. (get_id_for_type): Add support for HASH_TYPE_ID_STYLE style. (set_type_id_style): Add new helper function. * tools/abidw.cc (options): Add type_id_style member. (display_usage): Add description of --type-id-style option. (parse_command_line): Parse --type-id-style option. * tests/data/Makefile.am: Add new hash type id ABI files. * tests/test-read-dwarf.cc: (InOutSpec): Add type_id_style member. (in_out_specs): Set type_id_style to SEQUENCE_TYPE_ID_STYLE in existing test specifications. Duplicate first 9 test cases with type_id_style set to HASH_TYPE_ID_STYLE. * tests/data/test-read-dwarf/test0.hash.abi: New ABI XML file with hash type ids. * tests/data/test-read-dwarf/test1.hash.abi: Ditto. * tests/data/test-read-dwarf/test2.so.hash.abi: Ditto. * tests/data/test-read-dwarf/test3.so.hash.abi: Ditto. * tests/data/test-read-dwarf/test4.so.hash.abi: Ditto. * tests/data/test-read-dwarf/test5.o.hash.abi: Ditto. * tests/data/test-read-dwarf/test6.so.hash.abi: Ditto. * tests/data/test-read-dwarf/test7.so.hash.abi: Ditto. * tests/data/test-read-dwarf/test8-qualified-this-pointer.so.hash.abi: Ditto. Signed-off-by: Giuliano Procida --- doc/manuals/abidw.rst | 15 +- include/abg-hash.h | 5 + include/abg-writer.h | 11 ++ src/abg-hash.cc | 30 ++++ src/abg-writer.cc | 63 ++++++++- tests/data/Makefile.am | 9 ++ tests/data/test-read-dwarf/test0.hash.abi | 70 ++++++++++ tests/data/test-read-dwarf/test1.hash.abi | 129 ++++++++++++++++++ tests/data/test-read-dwarf/test2.so.hash.abi | 79 +++++++++++ tests/data/test-read-dwarf/test3.so.hash.abi | 19 +++ tests/data/test-read-dwarf/test4.so.hash.abi | 23 ++++ tests/data/test-read-dwarf/test5.o.hash.abi | 13 ++ tests/data/test-read-dwarf/test6.so.hash.abi | 42 ++++++ tests/data/test-read-dwarf/test7.so.hash.abi | 77 +++++++++++ .../test8-qualified-this-pointer.so.hash.abi | 37 +++++ tests/test-read-dwarf.cc | 107 ++++++++++++++- tools/abidw.cc | 20 ++- 17 files changed, 732 insertions(+), 17 deletions(-) create mode 100644 tests/data/test-read-dwarf/test0.hash.abi create mode 100644 tests/data/test-read-dwarf/test1.hash.abi create mode 100644 tests/data/test-read-dwarf/test2.so.hash.abi create mode 100644 tests/data/test-read-dwarf/test3.so.hash.abi create mode 100644 tests/data/test-read-dwarf/test4.so.hash.abi create mode 100644 tests/data/test-read-dwarf/test5.o.hash.abi create mode 100644 tests/data/test-read-dwarf/test6.so.hash.abi create mode 100644 tests/data/test-read-dwarf/test7.so.hash.abi create mode 100644 tests/data/test-read-dwarf/test8-qualified-this-pointer.so.hash.abi diff --git a/doc/manuals/abidw.rst b/doc/manuals/abidw.rst index e1fce997..5834923b 100644 --- a/doc/manuals/abidw.rst +++ b/doc/manuals/abidw.rst @@ -197,13 +197,14 @@ Options 1.8 will not set the default size and will interpret types without a size-in-bits attribute as zero sized. - * ``--named-type-ids`` - - Without this option ids used to reference types in the XML file - use simple numbers. With this option the ids used are derived - from the type name to make it easier to see which type is - referenced and make the XML file more stable in case new types are - added (without this option that might mean all id numbers change). + * ``--type-id-style`` ( ``sequence`` | ``hash`` ) + + This option controls how types are idenfied in the generated XML + files. The default ``sequence`` style just numbers (with + ``type-id-`` as prefix) the types in the order they are + encountered. The ``hash`` style uses a (stable, portable) hash of + libabigail's internal type names and is intended to make the XML + files easier to diff. * ``--check-alternate-debug-info-base-name`` <*elf-path*> diff --git a/include/abg-hash.h b/include/abg-hash.h index 10adedee..ccf50c12 100644 --- a/include/abg-hash.h +++ b/include/abg-hash.h @@ -24,6 +24,8 @@ #define __ABG_HASH_H__ #include +#include +#include namespace abigail { @@ -34,6 +36,9 @@ namespace hashing /// This is copied from tree.c in GCC. std::size_t combine_hashes(std::size_t, std::size_t); + + uint32_t + fnv_hash(const std::string& str); }//end namespace hashing }//end namespace abigail diff --git a/include/abg-writer.h b/include/abg-writer.h index 8086d828..d44b4838 100644 --- a/include/abg-writer.h +++ b/include/abg-writer.h @@ -38,6 +38,13 @@ namespace xml_writer using namespace abigail::ir; +/// The style of type id the XML writer will output. +enum type_id_style_kind +{ + SEQUENCE_TYPE_ID_STYLE, + HASH_TYPE_ID_STYLE +}; + class write_context; /// A convenience typedef for a shared pointer to write_context. @@ -74,6 +81,9 @@ set_short_locs(write_context& ctxt, bool flag); void set_write_parameter_names(write_context& ctxt, bool flag); +void +set_type_id_style(write_context& ctxt, type_id_style_kind style); + /// A convenience generic function to set common options (usually used /// by Libabigail tools) from a generic options carrying-object, into /// a given @ref write_context. @@ -96,6 +106,7 @@ set_common_options(write_context& ctxt, const OPTS& opts) set_write_parameter_names(ctxt, opts.write_parameter_names); set_short_locs(ctxt, opts.short_locs); set_write_default_sizes(ctxt, opts.default_sizes); + set_type_id_style(ctxt, opts.type_id_style); } void diff --git a/src/abg-hash.cc b/src/abg-hash.cc index 0646ab16..c1cdc57b 100644 --- a/src/abg-hash.cc +++ b/src/abg-hash.cc @@ -60,6 +60,36 @@ combine_hashes(size_t val1, size_t val2) return val2; } +/// Compute a stable string hash. +/// +/// std::hash has no portability or stability guarantees so is +/// unsuitable where reproducibility is a requirement such as in XML +/// output. +/// +/// This is the 32-bit FNV-1a algorithm. The algorithm, reference code +/// and constants are all unencumbered. It is fast and has reasonable +/// distribution properties. +/// +/// https://en.wikipedia.org/wiki/Fowler-Noll-Vo_hash_function +/// +/// @param str the string to hash. +/// +/// @return an unsigned 32 bit hash value. +uint32_t +fnv_hash(const std::string& str) +{ + const uint32_t prime = 0x01000193; + const uint32_t offset_basis = 0x811c9dc5; + uint32_t hash = offset_basis; + for (std::string::const_iterator i = str.begin(); i != str.end(); ++i) + { + uint8_t byte = *i; + hash = hash ^ byte; + hash = hash * prime; + } + return hash; +} + }//end namespace hashing using std::list; diff --git a/src/abg-writer.cc b/src/abg-writer.cc index bafa3024..ce0bae2d 100644 --- a/src/abg-writer.cc +++ b/src/abg-writer.cc @@ -27,6 +27,7 @@ #include "config.h" #include +#include #include #include #include @@ -44,6 +45,7 @@ ABG_BEGIN_EXPORT_DECLARATIONS #include "abg-config.h" #include "abg-corpus.h" #include "abg-diff-utils.h" +#include "abg-hash.h" #include "abg-sptr-utils.h" #if WITH_ZIP_ARCHIVE @@ -177,7 +179,9 @@ class write_context bool m_write_parameter_names; bool m_short_locs; bool m_write_default_sizes; + type_id_style_kind m_type_id_style; mutable type_ptr_map m_type_id_map; + mutable unordered_set m_used_type_id_hashes; mutable type_ptr_set_type m_emitted_type_set; type_ptr_set_type m_emitted_decl_only_set; // A map of types that are referenced by emitted pointers, @@ -214,7 +218,8 @@ public: m_write_elf_needed(true), m_write_parameter_names(true), m_short_locs(false), - m_write_default_sizes(true) + m_write_default_sizes(true), + m_type_id_style(SEQUENCE_TYPE_ID_STYLE) {} /// Getter of the environment we are operating from. @@ -374,6 +379,24 @@ public: set_show_locs(bool f) {m_show_locs = f;} + /// Getter of the "type-id-style" option. + /// + /// This option controls the kind of type ids used in XML output. + /// + /// @return the value of the "type-id-style" option. + type_id_style_kind + get_type_id_style() const + {return m_type_id_style;} + + /// Setter of the "type-id-style" option. + /// + /// This option controls the kind of type ids used in XML output. + /// + /// @param style the new value of the "type-id-style" option. + void + set_type_id_style(type_id_style_kind style) + {m_type_id_style = style;} + /// Getter of the @ref id_manager. /// /// @return the @ref id_manager used by the current instance of @ref @@ -421,14 +444,29 @@ public: c = const_cast(t); type_ptr_map::const_iterator it = m_type_id_map.find(c); - if (it == m_type_id_map.end()) + if (it != m_type_id_map.end()) + return it->second; + + switch (m_type_id_style) { - interned_string id = - get_id_manager().get_id_with_prefix("type-id-"); - m_type_id_map[c] = id; - return id; + case SEQUENCE_TYPE_ID_STYLE: + { + interned_string id = get_id_manager().get_id_with_prefix("type-id-"); + return m_type_id_map[c] = id; + } + case HASH_TYPE_ID_STYLE: + { + interned_string pretty = c->get_cached_pretty_representation(true); + size_t hash = hashing::fnv_hash(*pretty.raw()); + while (!m_used_type_id_hashes.insert(hash).second) + ++hash; + std::ostringstream os; + os << std::hex << std::setfill('0') << std::setw(8) << hash; + return m_type_id_map[c] = c->get_environment()->intern(os.str()); + } } - return it->second; + ABG_ASSERT_NOT_REACHED; + return interned_string(); } string @@ -2131,6 +2169,17 @@ void set_write_default_sizes(write_context& ctxt, bool flag) {ctxt.set_write_default_sizes(flag);} +/// Set the 'type-id-style' property. +/// +/// This property controls the kind of type ids used in XML output. +/// +/// @param ctxt the context to set this property on. +/// +/// @param style the new value of the 'type-id-style' property. +void +set_type_id_style(write_context& ctxt, type_id_style_kind style) +{ctxt.set_type_id_style(style);} + /// Serialize the canonical types of a given scope. /// /// @param scope the scope to consider. diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am index 6592ba32..8ccd50a0 100644 --- a/tests/data/Makefile.am +++ b/tests/data/Makefile.am @@ -395,33 +395,42 @@ test-diff-dwarf/PR25058-liblttng-ctl2.10.so \ \ test-read-dwarf/test0 \ test-read-dwarf/test0.abi \ +test-read-dwarf/test0.hash.abi \ test-read-dwarf/test0.cc \ test-read-dwarf/test1 \ test-read-dwarf/test1.abi \ +test-read-dwarf/test1.hash.abi \ test-read-dwarf/test1.cc \ test-read-dwarf/test2.h \ test-read-dwarf/test2-0.cc \ test-read-dwarf/test2-1.cc \ test-read-dwarf/test2.so \ test-read-dwarf/test2.so.abi \ +test-read-dwarf/test2.so.hash.abi \ test-read-dwarf/test3.c \ test-read-dwarf/test3.so \ test-read-dwarf/test3.so.abi \ +test-read-dwarf/test3.so.hash.abi \ test-read-dwarf/test4.c \ test-read-dwarf/test4.so \ test-read-dwarf/test4.so.abi \ +test-read-dwarf/test4.so.hash.abi \ test-read-dwarf/test5.cc \ test-read-dwarf/test5.o \ test-read-dwarf/test5.o.abi \ +test-read-dwarf/test5.o.hash.abi \ test-read-dwarf/test6.cc \ test-read-dwarf/test6.so \ test-read-dwarf/test6.so.abi \ +test-read-dwarf/test6.so.hash.abi \ test-read-dwarf/test7.cc \ test-read-dwarf/test7.so \ test-read-dwarf/test7.so.abi \ +test-read-dwarf/test7.so.hash.abi \ test-read-dwarf/test8-qualified-this-pointer.cc \ test-read-dwarf/test8-qualified-this-pointer.so \ test-read-dwarf/test8-qualified-this-pointer.so.abi \ +test-read-dwarf/test8-qualified-this-pointer.so.hash.abi \ test-read-dwarf/test9-pr18818-clang.so \ test-read-dwarf/test10-pr18818-gcc.so \ test-read-dwarf/test9-pr18818-clang.so.abi \ diff --git a/tests/data/test-read-dwarf/test0.hash.abi b/tests/data/test-read-dwarf/test0.hash.abi new file mode 100644 index 00000000..3d34a9de --- /dev/null +++ b/tests/data/test-read-dwarf/test0.hash.abi @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/test-read-dwarf/test1.hash.abi b/tests/data/test-read-dwarf/test1.hash.abi new file mode 100644 index 00000000..0bd86868 --- /dev/null +++ b/tests/data/test-read-dwarf/test1.hash.abi @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/test-read-dwarf/test2.so.hash.abi b/tests/data/test-read-dwarf/test2.so.hash.abi new file mode 100644 index 00000000..bb814f73 --- /dev/null +++ b/tests/data/test-read-dwarf/test2.so.hash.abi @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/test-read-dwarf/test3.so.hash.abi b/tests/data/test-read-dwarf/test3.so.hash.abi new file mode 100644 index 00000000..e01f3959 --- /dev/null +++ b/tests/data/test-read-dwarf/test3.so.hash.abi @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/test-read-dwarf/test4.so.hash.abi b/tests/data/test-read-dwarf/test4.so.hash.abi new file mode 100644 index 00000000..446df1da --- /dev/null +++ b/tests/data/test-read-dwarf/test4.so.hash.abi @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/test-read-dwarf/test5.o.hash.abi b/tests/data/test-read-dwarf/test5.o.hash.abi new file mode 100644 index 00000000..9ed9932a --- /dev/null +++ b/tests/data/test-read-dwarf/test5.o.hash.abi @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/tests/data/test-read-dwarf/test6.so.hash.abi b/tests/data/test-read-dwarf/test6.so.hash.abi new file mode 100644 index 00000000..7867a28f --- /dev/null +++ b/tests/data/test-read-dwarf/test6.so.hash.abi @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/test-read-dwarf/test7.so.hash.abi b/tests/data/test-read-dwarf/test7.so.hash.abi new file mode 100644 index 00000000..a04025f6 --- /dev/null +++ b/tests/data/test-read-dwarf/test7.so.hash.abi @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/data/test-read-dwarf/test8-qualified-this-pointer.so.hash.abi b/tests/data/test-read-dwarf/test8-qualified-this-pointer.so.hash.abi new file mode 100644 index 00000000..7197425d --- /dev/null +++ b/tests/data/test-read-dwarf/test8-qualified-this-pointer.so.hash.abi @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/test-read-dwarf.cc b/tests/test-read-dwarf.cc index 7c99d218..5ddb8e4e 100644 --- a/tests/test-read-dwarf.cc +++ b/tests/test-read-dwarf.cc @@ -46,7 +46,11 @@ using abigail::dwarf_reader::read_corpus_from_elf; using abigail::dwarf_reader::read_context; using abigail::dwarf_reader::read_context_sptr; using abigail::dwarf_reader::create_read_context; +using abigail::xml_writer::SEQUENCE_TYPE_ID_STYLE; +using abigail::xml_writer::HASH_TYPE_ID_STYLE; using abigail::xml_writer::create_write_context; +using abigail::xml_writer::set_type_id_style; +using abigail::xml_writer::type_id_style_kind; using abigail::xml_writer::write_context_sptr; using abigail::xml_writer::write_corpus; @@ -56,6 +60,7 @@ struct InOutSpec { const char* in_elf_path; const char* in_suppr_spec_path; + type_id_style_kind type_id_style; const char* in_abi_path; const char* out_abi_path; };// end struct InOutSpec @@ -66,174 +71,266 @@ InOutSpec in_out_specs[] = { "data/test-read-dwarf/test0", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test0.abi", "output/test-read-dwarf/test0.abi" }, + { + "data/test-read-dwarf/test0", + "", + HASH_TYPE_ID_STYLE, + "data/test-read-dwarf/test0.hash.abi", + "output/test-read-dwarf/test0.hash.abi" + }, { "data/test-read-dwarf/test1", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test1.abi", "output/test-read-dwarf/test1.abi" }, + { + "data/test-read-dwarf/test1", + "", + HASH_TYPE_ID_STYLE, + "data/test-read-dwarf/test1.hash.abi", + "output/test-read-dwarf/test1.hash.abi" + }, { "data/test-read-dwarf/test2.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test2.so.abi", "output/test-read-dwarf/test2.so.abi" }, + { + "data/test-read-dwarf/test2.so", + "", + HASH_TYPE_ID_STYLE, + "data/test-read-dwarf/test2.so.hash.abi", + "output/test-read-dwarf/test2.so.hash.abi" + }, { "data/test-read-dwarf/test3.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test3.so.abi", "output/test-read-dwarf/test3.so.abi" }, + { + "data/test-read-dwarf/test3.so", + "", + HASH_TYPE_ID_STYLE, + "data/test-read-dwarf/test3.so.hash.abi", + "output/test-read-dwarf/test3.so.hash.abi" + }, { "data/test-read-dwarf/test4.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test4.so.abi", "output/test-read-dwarf/test4.so.abi" }, + { + "data/test-read-dwarf/test4.so", + "", + HASH_TYPE_ID_STYLE, + "data/test-read-dwarf/test4.so.hash.abi", + "output/test-read-dwarf/test4.so.hash.abi" + }, { "data/test-read-dwarf/test5.o", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test5.o.abi", "output/test-read-dwarf/test5.o.abi" }, + { + "data/test-read-dwarf/test5.o", + "", + HASH_TYPE_ID_STYLE, + "data/test-read-dwarf/test5.o.hash.abi", + "output/test-read-dwarf/test5.o.hash.abi" + }, { "data/test-read-dwarf/test6.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test6.so.abi", "output/test-read-dwarf/test6.so.abi" }, + { + "data/test-read-dwarf/test6.so", + "", + HASH_TYPE_ID_STYLE, + "data/test-read-dwarf/test6.so.hash.abi", + "output/test-read-dwarf/test6.so.hash.abi" + }, { "data/test-read-dwarf/test7.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test7.so.abi", "output/test-read-dwarf/test7.so.abi" }, + { + "data/test-read-dwarf/test7.so", + "", + HASH_TYPE_ID_STYLE, + "data/test-read-dwarf/test7.so.hash.abi", + "output/test-read-dwarf/test7.so.hash.abi" + }, { "data/test-read-dwarf/test8-qualified-this-pointer.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test8-qualified-this-pointer.so.abi", "output/test-read-dwarf/test8-qualified-this-pointer.so.abi" }, + { + "data/test-read-dwarf/test8-qualified-this-pointer.so", + "", + HASH_TYPE_ID_STYLE, + "data/test-read-dwarf/test8-qualified-this-pointer.so.hash.abi", + "output/test-read-dwarf/test8-qualified-this-pointer.so.hash.abi" + }, { "data/test-read-dwarf/test9-pr18818-clang.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test9-pr18818-clang.so.abi", "output/test-read-dwarf/test9-pr18818-clang.so.abi" }, { "data/test-read-dwarf/test10-pr18818-gcc.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test10-pr18818-gcc.so.abi", "output/test-read-dwarf/test10-pr18818-gcc.so.abi" }, { "data/test-read-dwarf/test11-pr18828.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test11-pr18828.so.abi", "output/test-read-dwarf/test11-pr18828.so.abi", }, { "data/test-read-dwarf/test12-pr18844.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test12-pr18844.so.abi", "output/test-read-dwarf/test12-pr18844.so.abi", }, { "data/test-read-dwarf/test13-pr18894.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test13-pr18894.so.abi", "output/test-read-dwarf/test13-pr18894.so.abi", }, { "data/test-read-dwarf/test14-pr18893.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test14-pr18893.so.abi", "output/test-read-dwarf/test14-pr18893.so.abi", }, { "data/test-read-dwarf/test15-pr18892.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test15-pr18892.so.abi", "output/test-read-dwarf/test15-pr18892.so.abi", }, { "data/test-read-dwarf/test16-pr18904.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test16-pr18904.so.abi", "output/test-read-dwarf/test16-pr18904.so.abi", }, { "data/test-read-dwarf/test17-pr19027.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test17-pr19027.so.abi", "output/test-read-dwarf/test17-pr19027.so.abi", }, { "data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so.abi", "output/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so.abi", }, { "data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi", "output/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi", }, { "data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi", "output/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi", }, { "data/test-read-dwarf/test21-pr19092.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test21-pr19092.so.abi", "output/test-read-dwarf/test21-pr19092.so.abi", }, { "data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi", "output/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi", }, { "data/test-read-dwarf/libtest23.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/libtest23.so.abi", "output/test-read-dwarf/libtest23.so.abi", }, { "data/test-read-dwarf/libtest24-drop-fns.so", "data/test-read-dwarf/test24-drop-fns-0.suppr", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/libtest24-drop-fns.so.abi", "output/test-read-dwarf/libtest24-drop-fns.so.abi", }, { "data/test-read-dwarf/libtest24-drop-fns.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/libtest24-drop-fns-2.so.abi", "output/test-read-dwarf/libtest24-drop-fns-2.so.abi", }, { "data/test-read-dwarf/PR22015-libboost_iostreams.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/PR22015-libboost_iostreams.so.abi", "output/test-read-dwarf/PR22015-libboost_iostreams.so.abi", }, { "data/test-read-dwarf/PR22122-libftdc.so", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/PR22122-libftdc.so.abi", "output/test-read-dwarf/PR22122-libftdc.so.abi", }, { "data/test-read-dwarf/PR24378-fn-is-not-scope.o", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/PR24378-fn-is-not-scope.abi", "output/test-read-dwarf/PR24378-fn-is-not-scope.abi", }, @@ -241,6 +338,7 @@ InOutSpec in_out_specs[] = { "data/test-read-dwarf/PR25007-sdhci.ko", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/PR25007-sdhci.ko.abi", "output/test-read-dwarf/PR25007-sdhci.ko.abi", }, @@ -249,6 +347,7 @@ InOutSpec in_out_specs[] = { "data/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0", "", + SEQUENCE_TYPE_ID_STYLE, "data/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi", "output/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi", }, @@ -256,23 +355,26 @@ InOutSpec in_out_specs[] = { "data/test-read-dwarf/test25-bogus-binary.elf", "", + SEQUENCE_TYPE_ID_STYLE, "", "", }, { "data/test-read-dwarf/test26-bogus-binary.elf", "", + SEQUENCE_TYPE_ID_STYLE, "", "", }, { "data/test-read-dwarf/test27-bogus-binary.elf", "", + SEQUENCE_TYPE_ID_STYLE, "", "", }, // This should be the last entry. - {NULL, NULL, NULL, NULL} + {NULL, NULL, SEQUENCE_TYPE_ID_STYLE, NULL, NULL} }; using abigail::suppr::suppression_sptr; @@ -377,8 +479,9 @@ struct test_task : public abigail::workers::task is_ok = false; return; } - const write_context_sptr write_ctxt + write_context_sptr write_ctxt = create_write_context(corp->get_environment(), of); + set_type_id_style(*write_ctxt, spec.type_id_style); is_ok = write_corpus(*write_ctxt, corp, /*indent=*/0); of.close(); diff --git a/tools/abidw.cc b/tools/abidw.cc index 1de48f49..2cd848df 100644 --- a/tools/abidw.cc +++ b/tools/abidw.cc @@ -70,7 +70,10 @@ using abigail::comparison::corpus_diff_sptr; using abigail::comparison::compute_diff; using abigail::comparison::diff_context_sptr; using abigail::comparison::diff_context; +using abigail::xml_writer::SEQUENCE_TYPE_ID_STYLE; +using abigail::xml_writer::HASH_TYPE_ID_STYLE; using abigail::xml_writer::create_write_context; +using abigail::xml_writer::type_id_style_kind; using abigail::xml_writer::write_context_sptr; using abigail::xml_writer::write_corpus; using abigail::xml_reader::read_corpus_from_native_xml_file; @@ -114,6 +117,7 @@ struct options bool do_log; bool drop_private_types; bool drop_undefined_syms; + type_id_style_kind type_id_style; options() : display_version(), @@ -136,7 +140,8 @@ struct options annotate(), do_log(), drop_private_types(false), - drop_undefined_syms(false) + drop_undefined_syms(false), + type_id_style(SEQUENCE_TYPE_ID_STYLE) {} ~options() @@ -175,6 +180,7 @@ display_usage(const string& prog_name, ostream& out) << " --no-write-default-sizes do not emit pointer size when it equals" " the default address size of the translation unit\n" << " --no-parameter-names do not show names of function parameters\n" + << " --type-id-style (sequence|hash) type-id style (sequence(default): type-id-number; hash: hexdigits\n" << " --check-alternate-debug-info check alternate debug info " "of \n" << " --check-alternate-debug-info-base-name check alternate " @@ -301,6 +307,18 @@ parse_command_line(int argc, char* argv[], options& opts) opts.default_sizes = false; else if (!strcmp(argv[i], "--no-parameter-names")) opts.write_parameter_names = false; + else if (!strcmp(argv[i], "--type-id-style")) + { + ++i; + if (i >= argc) + return false; + if (!strcmp(argv[i], "sequence")) + opts.type_id_style = SEQUENCE_TYPE_ID_STYLE; + else if (!strcmp(argv[i], "hash")) + opts.type_id_style = HASH_TYPE_ID_STYLE; + else + return false; + } else if (!strcmp(argv[i], "--check-alternate-debug-info") || !strcmp(argv[i], "--check-alternate-debug-info-base-name")) {