From patchwork Tue Apr 27 11:28:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 43163 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 ABB8C3944821; Tue, 27 Apr 2021 11:29:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ABB8C3944821 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1619522950; bh=7MGIWxebQCE9R2fFJAsju1FVAt19v2yOn7JkdTU/2x8=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=jek2dJ2ZzRK6zlMWzvb2i3aOorkZA04v/Mwq0s/780gLXQLmy/qJX6NRyoYFou3Tk bLEQTRcCEwm+O0FvuFv2yHU0JcY3bKdbfj6CrgSgZk9+ShCXCBJHFkuSS/ro4Lbend xAw74tVFQQJhc88RrOKWHCCusvX2x2YqFsAlKTVI= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by sourceware.org (Postfix) with ESMTPS id C32E43944821 for ; Tue, 27 Apr 2021 11:29:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C32E43944821 Received: by mail-qv1-xf4a.google.com with SMTP id t1-20020a0ca6810000b029019e892416e6so25250946qva.9 for ; Tue, 27 Apr 2021 04:29:07 -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; bh=7MGIWxebQCE9R2fFJAsju1FVAt19v2yOn7JkdTU/2x8=; b=j1RSgMe/gYYp7S7mFnyKPRubV8lEvixgfBl1PCKdUjL+uC+T8Yxs4Ld5QMGW10YMGz NWpCSfLtP5MgyIRcYI9aYQltyR8OT6/qzDSH8KQ7vtC4WPWBib0dFWQ+gqckVHQIaY0L u7iwmbZPpCvzdovneJUt2ue+j7Q75cWtBynacHf1V06Oigdyoi7sukODJQa0IfezhMQa LYAEvbJbTTiorpzcabhN0TaxhJIbsF5WK1ZzWUQ3Uh4NZhPJOH2srPytWwWvpQ6o2ck9 jRoTlZalcA5hgI1cJ5B1C3/I/PErvanDHaO14HYVIuQwISGSC/csB4VEM8c5/DwBunpC flWw== X-Gm-Message-State: AOAM531gIkyQ6xwtd398dCfMg8aD6vdWoW1AgjE9uwBMKuufeUaSKNSR +PFOXiuelodsjEJrStngkn1vU1N3eTVka1r1s9THWho3PUZNdpepm/7Mw41FoHoYCgl4ILEmk1M 2ZSsBpUTlHXmzezR/FqeQWzmUboswrru+2BWgfpeYTOTrWVzEHzUHsQQ6BB6ffAm1VTONd7g= X-Google-Smtp-Source: ABdhPJzjl4icnDclgoIjT6yO28Jz45o2b+0LjXxkvNGViP3zfL3AjLMwJFJ4ze2tGHDAApEWZD0LThekA/eNzA== X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:110:a94:13c5:d1bb:c50d]) (user=gprocida job=sendgmr) by 2002:a0c:f404:: with SMTP id h4mr11230293qvl.6.1619522947268; Tue, 27 Apr 2021 04:29:07 -0700 (PDT) Date: Tue, 27 Apr 2021 12:28:52 +0100 In-Reply-To: <20210427112853.1338240-1-gprocida@google.com> Message-Id: <20210427112853.1338240-3-gprocida@google.com> Mime-Version: 1.0 References: <20210427112853.1338240-1-gprocida@google.com> X-Mailer: git-send-email 2.31.1.498.g6c1eba8ee3d-goog Subject: [PATCH 2/3] abg-reader: ensure corpus always has a symtab reader To: libabigail@sourceware.org X-Spam-Status: No, score=-22.5 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 Errors-To: libabigail-bounces@sourceware.org Sender: "Libabigail" In the presence of an empty abi-corpus element and with the following change to always allocate a fresh corpus object, such objects can sometimes be left without a symtab reader, instead of inheritng one from the previous corpus. The reader is called to obtain sorted lists of symbols during ABI comparisons. The simplest way to avoid a crash is to maintain the invariant that a reader object is always present. With this change, if there is bad XML preventing symbols from being read, no error is raised as before, but the logic has been tweaked so that abi-instr parsing will nevertheless be attempted. * src/abg-reader.cc (read_symbol_db_from_input): Fix documentation for this function. Allow "successful parsing" to include the case where no symbols were present in the input. (read_corpus_from_input): Unconditionally set a symtab reader on the corpus object. Unconditionally parse the abi-instr of a corpus. Signed-off-by: Giuliano Procida --- src/abg-reader.cc | 59 ++++++++++++++--------------------------------- 1 file changed, 17 insertions(+), 42 deletions(-) diff --git a/src/abg-reader.cc b/src/abg-reader.cc index 17b75914..313af4c9 100644 --- a/src/abg-reader.cc +++ b/src/abg-reader.cc @@ -1497,8 +1497,8 @@ read_translation_unit_from_input(read_context& ctxt) return tu; } -/// Parse the input XML document containing a function symbols -/// or a variable symbol database. +/// Parse the input XML document that may contain function symbol and +/// variable symbol databases. /// /// A function symbols database is an XML element named /// "elf-function-symbols" and a variable symbols database is an XML @@ -1507,12 +1507,11 @@ read_translation_unit_from_input(read_context& ctxt) /// /// @param ctxt the read_context to use for the parsing. /// -/// @param function_symbols is true if this function should look for a -/// function symbols database, false if it should look for a variable -/// symbols database. +/// @param fn_symdb any resulting function symbol database object, if +/// elf-function-symbols was present. /// -/// @param symdb the resulting symbol database object. This is set -/// iff the function return true. +/// @param var_symdb any resulting variable symbol database object, if +/// elf-variable-symbols was present. /// /// @return true upon successful parsing, false otherwise. static bool @@ -1524,8 +1523,6 @@ read_symbol_db_from_input(read_context& ctxt, if (!reader) return false; - bool found = false; - if (!ctxt.get_corpus_node()) for (;;) { @@ -1552,17 +1549,9 @@ read_symbol_db_from_input(read_context& ctxt, return false; if (has_fn_syms) - { - fn_symdb = build_elf_symbol_db(ctxt, node, true); - if (fn_symdb) - found = true; - } + fn_symdb = build_elf_symbol_db(ctxt, node, true); else if (has_var_syms) - { - var_symdb = build_elf_symbol_db(ctxt, node, false); - if (var_symdb) - found = true; - } + var_symdb = build_elf_symbol_db(ctxt, node, false); xmlTextReaderNext(reader.get()); } @@ -1579,22 +1568,16 @@ read_symbol_db_from_input(read_context& ctxt, else break; if (has_fn_syms) - { - fn_symdb = build_elf_symbol_db(ctxt, n, true); - found = true; - } + fn_symdb = build_elf_symbol_db(ctxt, n, true); else if (has_var_syms) - { - var_symdb = build_elf_symbol_db(ctxt, n, false); - found = true; - } + var_symdb = build_elf_symbol_db(ctxt, n, false); else break; } ctxt.set_corpus_node(n); } - return found; + return true; } /// From an "elf-needed" XML_ELEMENT node, build a vector of strings @@ -1894,24 +1877,16 @@ read_corpus_from_input(read_context& ctxt) string_elf_symbols_map_sptr fn_sym_db, var_sym_db; // Read the symbol databases. - bool is_ok = read_symbol_db_from_input(ctxt, fn_sym_db, var_sym_db); - if (is_ok) - { - // Note that it's possible that both fn_sym_db and var_sym_db - // are nil, due to potential suppression specifications. That's - // fine. - corp.set_symtab(symtab_reader::symtab::load(fn_sym_db, var_sym_db)); - } + read_symbol_db_from_input(ctxt, fn_sym_db, var_sym_db); + // Note that it's possible that both fn_sym_db and var_sym_db are nil, + // due to potential suppression specifications. That's fine. + corp.set_symtab(symtab_reader::symtab::load(fn_sym_db, var_sym_db)); ctxt.get_environment()->canonicalization_is_done(false); // Read the translation units. - do - { - translation_unit_sptr tu = read_translation_unit_from_input(ctxt); - is_ok = bool(tu); - } - while (is_ok); + while (read_translation_unit_from_input(ctxt)) + ; if (ctxt.tracking_non_reachable_types()) {