From patchwork Wed Jan 27 12:58:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Matthias_M=C3=A4nnich?= X-Patchwork-Id: 41851 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 F0F15397282F; Wed, 27 Jan 2021 12:59:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F0F15397282F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611752394; bh=ZpL0TV5oyjDeuNzlo/TQIiJn1rpZjXshIf1WgPfr6rI=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=K9RB19ZSLvB5I+4q2NKJIZ6lldTWuwFOW/PXLsBvcjrltdUZygKPXJyi8Ivx1T8as Haf2OjVgKaJ2tPQuzvmVF/pj+6O0rvMfEpLAfqDTgbLZaOFEMEk742UCkBCWcB9zq6 4o5wqIxSJegQkVCkToi5uXI9DmFdPB3SwOMbPBo0= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by sourceware.org (Postfix) with ESMTPS id 9BD2E397282F for ; Wed, 27 Jan 2021 12:59:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9BD2E397282F Received: by mail-qt1-x849.google.com with SMTP id k11so1009256qtm.16 for ; Wed, 27 Jan 2021 04:59:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ZpL0TV5oyjDeuNzlo/TQIiJn1rpZjXshIf1WgPfr6rI=; b=NNWbycb3yVkI3O30qBU5+1B+obv8VflzRRgZXkdOfXjP83HBaLq0DFejZTuPNqpXbk v13+2j2Qx1UttBIq6683Mty5gWSsCFixu3BhaV6pkMu6ojZIBMgBOb95GXeS4vXpolFP moNheackjM10wFQ2oNx9tiUADzXHmvO1R6liL5ObDaTBaaInYz2FexY4UZT3MId8ve/Z Zxxx/YAluD0UNByUcyLYqmVJR/2021cuQXh65wsZAJFSvzpoGC8nDtkMufTiKI28YDcB 3Wk/J2JtSw/Jsg/5kSEkXORBwZMTDtk0rzTTa8kKBDcm6PhWYS/T6lNnxviOm8tMeOtZ 2mnQ== X-Gm-Message-State: AOAM531NVH1NNrGIBuTU8R908eJ/S3rTBTTLkfUj/coqXeDS3/HRs7eA gZxNnsf1/KoDCgUTy5oXD6/2wCFtFFFpAyeUQqeP1yT7mvowK4fCqYDohv51JXgRCjPJC8xNa1j QOEe7UpkAG1yW1uxPQM5YD+R80F2WpIC0MKn5oXtKquDnrz0VOLfbUABk8fShVA6G6LImnPM= X-Google-Smtp-Source: ABdhPJxhjsKzzMyBWJk0Li5m7MJYfskbB1gUKToVgnAatCFeTYEj28muEKmAZ309CfHg8Bn3HlsxDaqmV1ZJDg== X-Received: from lux.lon.corp.google.com ([2a00:79e0:d:210:7220:84ff:fe09:a3aa]) (user=maennich job=sendgmr) by 2002:a05:6214:2ee:: with SMTP id h14mr10172559qvu.34.1611752390118; Wed, 27 Jan 2021 04:59:50 -0800 (PST) Date: Wed, 27 Jan 2021 12:58:52 +0000 In-Reply-To: <20210127125853.886677-1-maennich@google.com> Message-Id: <20210127125853.886677-20-maennich@google.com> Mime-Version: 1.0 References: <20200619214305.562-1-maennich@google.com> <20210127125853.886677-1-maennich@google.com> X-Mailer: git-send-email 2.30.0.280.ga3ce27912f-goog Subject: [PATCH 19/20] abg-writer.cc: fix write_elf_symbol_reference loop To: libabigail@sourceware.org X-Spam-Status: No, score=-22.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: Matthias Maennich via Libabigail From: =?utf-8?q?Matthias_M=C3=A4nnich?= Reply-To: Matthias Maennich Cc: maennich@google.com, kernel-team@android.com Errors-To: libabigail-bounces@sourceware.org Sender: "Libabigail" From: Giuliano Procida The function write_elf_symbol_reference iterates through aliases, looking for an unsuppressed alias to use. The existing code went wrong in the case when aliases are present. In the case of all symbols suppressed, it would also have selected the last alias, rather than the first, if the data structure invariants had matched the code's expectations. The main symbol is always distinguished. When aliases are absent, the sole symbol's next pointer is null, but when aliases are present, they form a circular list. This makes traversal of aliases a bit tricky. The code now picks the first symbol from the following: - the given symbol, if unsuppressed - the main symbol, if unsuppressed - the unsuppressed aliases in the remainder of the alias chain - the main symbol (suppressed) The given symbol, which need not be the same as the main symbol, will be tested twice, if suppressed, but addressing this would make the code even more elaborate and fragile. The last case may be unreachable if symbol suppression triggers when all aliases are suppressed. I left this change stand-alone for easier review and to credit Giuliano for his work on it, though it fixes a previous commit. * src/abg-writer.cc (write_elf_symbol_reference): Check main symbol and aliases with more care. Fixes: commmit ("dwarf-reader/writer: consider aliases when dealing with suppressions") Signed-off-by: Giuliano Procida Signed-off-by: Matthias Maennich --- src/abg-writer.cc | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/abg-writer.cc b/src/abg-writer.cc index c2fdd8f0a043..4985174d3abd 100644 --- a/src/abg-writer.cc +++ b/src/abg-writer.cc @@ -1728,10 +1728,28 @@ write_elf_symbol_aliases(const elf_symbol& sym, ostream& out) static bool write_elf_symbol_reference(const elf_symbol& sym, ostream& o) { - auto actual_sym = &sym; - while (actual_sym->is_suppressed() && actual_sym->has_aliases()) - actual_sym = actual_sym->get_next_alias().get(); - o << " elf-symbol-id='" << actual_sym->get_id_string() << "'"; + const elf_symbol* main = sym.get_main_symbol().get(); + const elf_symbol* alias = &sym; + bool found = !alias->is_suppressed(); + // If the symbol itself is suppressed, check the alias chain. + if (!found) + { + alias = main; + found = !alias->is_suppressed(); + } + // If the main symbol is suppressed, search the remainder of the chain. + while (!found) + { + alias = alias->get_next_alias().get(); + // Two separate termination conditions at present. + if (!alias || alias == main) + break; + found = !alias->is_suppressed(); + } + // If all aliases are suppressed, just stick with the main symbol. + if (!found) + alias = main; + o << " elf-symbol-id='" << alias->get_id_string() << "'"; return true; }