From patchwork Thu Mar 25 21:51:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 42777 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 E98B5385700B; Thu, 25 Mar 2021 21:52:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E98B5385700B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1616709134; bh=HcaYo5hYaKg7TpHYpU+q7TVR30n/F6ug5ZYX4oIPErU=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=VKGYB+XIoKow4lnv0lpVyncqkJzTWxJRM21DX9TXY8JRPRwKfBjREbbRoVyBLYe13 s6i0cW9K6owM4nQ+95WalZTIPr4LkaJLEaPyf38DtJCNb6iimD/CYMmI/0E/gP7aP0 aw1faTejBks9BLc5QXuWIeUYfUtTlpvRnT+gJi4k= 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 727FA3857C62 for ; Thu, 25 Mar 2021 21:52:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 727FA3857C62 Received: by mail-qv1-xf4a.google.com with SMTP id b15so4488833qvz.15 for ; Thu, 25 Mar 2021 14:52:12 -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=HcaYo5hYaKg7TpHYpU+q7TVR30n/F6ug5ZYX4oIPErU=; b=EnsdNz19d325gRnlYzpLgpQjC4Fzs5MYGnuTUKaZhWYxoXvzq+eiOi0bqUAQVQ6KLc UEiELCiAcgtmQnNs6aNHxqmSX2MXFHQwwlSiqbvPE5nj1qZIW1N4jc6CRnoitGczvR9F b0yV2zCMfg/GTy383Bz9koR+5qdoLU9jO0TypANb0clUZ44JoApSz1uiO7nY7ORMFqmP b/iSH4nKJuJ+1qE5GZl1qkOonL8BbkuFRG4DAxSkX1ZdfldmowBmLmRnP5W/bY5cnnKA BUxqLTte+fHlXa10gSUmTuA9NpNfuIZc76lCsZJK9tfy/TMZr1lL35ukO8SratO1Q3vN LhOg== X-Gm-Message-State: AOAM530Umo8eA4l+I+Z/LKz+y3R33/HltcuNkuFQmNatUGy6OQZQ2VSa 1QGbCCLFYYK6G+78oJGIZ6cNbvFAKrE5Zb63wfs95PrLxK3Of2TC5xXCo50hhmwzIfWAIeKdVqd 3vQR+bghhBydUTCwKhL8J3PrRCCHrHCheV572hNrIbyMV43xp3KqgOvfLCIaUyiZkicHTJoM= X-Google-Smtp-Source: ABdhPJxgReNnce90qT9+AOuDrD/LnqDuOydufncWU6QMfgctSLTAIQE2ro0lWJMeVJLeGusI2C3kOyKNnf2QbQ== X-Received: from tef.lon.corp.google.com ([2a00:79e0:d:110:2df6:f24a:7f54:86a8]) (user=gprocida job=sendgmr) by 2002:a05:6214:2ea:: with SMTP id h10mr1376656qvu.55.1616709132010; Thu, 25 Mar 2021 14:52:12 -0700 (PDT) Date: Thu, 25 Mar 2021 21:51:41 +0000 In-Reply-To: <20210325215146.3597963-1-gprocida@google.com> Message-Id: <20210325215146.3597963-5-gprocida@google.com> Mime-Version: 1.0 References: <20210316165509.2658452-1-gprocida@google.com> <20210325215146.3597963-1-gprocida@google.com> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog Subject: [RFC PATCH 4/9] Add pass to filter symbols To: libabigail@sourceware.org X-Spam-Status: No, score=-22.6 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" Currently symbol lists can be applied at the point of extraction (abidw) or comparison (abidiff). This commmit enables symbol lists to be applied directly to ABI XML files which will simplify workflows that use multiple symbol lists. * scripts/abitidy.pl (symbols): New variable to hold optional symbols to filter by. (filter_symbols): New function to filter out unlisted symbols. Signed-off-by: Giuliano Procida --- scripts/abitidy.pl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scripts/abitidy.pl b/scripts/abitidy.pl index c9f93ed8..468eeac4 100755 --- a/scripts/abitidy.pl +++ b/scripts/abitidy.pl @@ -347,14 +347,35 @@ seen = $count_seen remove_unwanted($dom); } +# Read symbols from a file. +sub read_symbols($file) { + my %symbols; + my $fh = new IO::File $file, '<'; + while (<$fh>) { + chomp; + $symbols{$_} = undef; + } + close $fh; + return \%symbols; +} + +# Remove unlisted ELF symbols, +sub filter_symbols($symbols, $dom) { + for my $node ($dom->findnodes('elf-symbol')) { + remove_node($node) unless exists $symbols->{$node->getAttribute('name')}; + } +} + # Parse arguments. my $input_opt; my $output_opt; +my $symbols_opt; my $all_opt; my $drop_opt; my $prune_opt; GetOptions('i|input=s' => \$input_opt, 'o|output=s' => \$output_opt, + 's|symbols=s' => \$symbols_opt, 'a|all' => sub { $drop_opt = $prune_opt = 1 }, @@ -364,6 +385,7 @@ GetOptions('i|input=s' => \$input_opt, map { (' ', $_) } ( '[-i|--input file]', '[-o|--output file]', + '[-s|--symbols file]', '[-a|--all]', '[-d|--[no-]drop-empty]', '[-p|--[no-]prune-unreachable]', @@ -379,6 +401,9 @@ close $input; # This simplifies DOM analysis and manipulation. strip_text($dom); +# Remove unlisted symbols. +filter_symbols(read_symbols($symbols_opt), $dom) if defined $symbols_opt; + # Prune unreachable elements. prune_unreachable($dom) if $prune_opt;