diff mbox series

[RFC,4/9] Add pass to filter symbols

Message ID 20210325215146.3597963-5-gprocida@google.com
State New
Headers show
Series Utility to manipulate ABI XML | expand

Commit Message

Giuliano Procida March 25, 2021, 9:51 p.m. UTC
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 <gprocida@google.com>
---
 scripts/abitidy.pl | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
diff mbox series

Patch

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;