<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># Copyright В© 2007 RaphaГ«l Hertzog &lt;hertzog@debian.org&gt;
# Copyright В© 2009-2010 Modestas Vainius &lt;modax@debian.org&gt;
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see &lt;https://www.gnu.org/licenses/&gt;.

package Dpkg::Shlibs::SymbolFile;

use strict;
use warnings;

our $VERSION = '0.01';

use Dpkg::Gettext;
use Dpkg::ErrorHandling;
use Dpkg::Version;
use Dpkg::Control::Fields;
use Dpkg::Shlibs::Symbol;
use Dpkg::Arch qw(get_host_arch);

use parent qw(Dpkg::Interface::Storable);

# Needed by the deprecated key, which is a correct use.
no if $Dpkg::Version::VERSION ge '1.02',
    warnings =&gt; qw(Dpkg::Version::semantic_change::overload::bool);

my %blacklist = (
    __bss_end__ =&gt; 1,                   # arm
    __bss_end =&gt; 1,                     # arm
    _bss_end__ =&gt; 1,                    # arm
    __bss_start =&gt; 1,                   # ALL
    __bss_start__ =&gt; 1,                 # arm
    __data_start =&gt; 1,                  # arm
    __do_global_ctors_aux =&gt; 1,         # ia64
    __do_global_dtors_aux =&gt; 1,         # ia64
    __do_jv_register_classes =&gt; 1,      # ia64
    _DYNAMIC =&gt; 1,                      # ALL
    _edata =&gt; 1,                        # ALL
    _end =&gt; 1,                          # ALL
    __end__ =&gt; 1,                       # arm
    __exidx_end =&gt; 1,                   # armel
    __exidx_start =&gt; 1,                 # armel
    _fbss =&gt; 1,                         # mips, mipsel
    _fdata =&gt; 1,                        # mips, mipsel
    _fini =&gt; 1,                         # ALL
    _ftext =&gt; 1,                        # mips, mipsel
    _GLOBAL_OFFSET_TABLE_ =&gt; 1,         # hppa, mips, mipsel
    __gmon_start__ =&gt; 1,                # hppa
    __gnu_local_gp =&gt; 1,                # mips, mipsel
    _gp =&gt; 1,                           # mips, mipsel
    _init =&gt; 1,                         # ALL
    _PROCEDURE_LINKAGE_TABLE_ =&gt; 1,     # sparc, alpha
    _SDA2_BASE_ =&gt; 1,                   # powerpc
    _SDA_BASE_ =&gt; 1,                    # powerpc
);

for my $i (14 .. 31) {
    # Many powerpc specific symbols
    $blacklist{"_restfpr_$i"} = 1;
    $blacklist{"_restfpr_$i\_x"} = 1;
    $blacklist{"_restgpr_$i"} = 1;
    $blacklist{"_restgpr_$i\_x"} = 1;
    $blacklist{"_savefpr_$i"} = 1;
    $blacklist{"_savegpr_$i"} = 1;
}

sub symbol_is_blacklisted {
    my ($symbol, $include_groups) = @_;

    return 1 if exists $blacklist{$symbol};

    # The ARM Embedded ABI spec states symbols under this namespace as
    # possibly appearing in output objects.
    return 1 if not ${$include_groups}{aeabi} and $symbol =~ /^__aeabi_/;

    # The GNU implementation of the OpenMP spec, specifies symbols under
    # this namespace as possibly appearing in output objects.
    return 1 if not ${$include_groups}{gomp}
                and $symbol =~ /^\.gomp_critical_user_/;

    return 0;
}

sub new {
    my ($this, %opts) = @_;
    my $class = ref($this) || $this;
    my $self = \%opts;
    bless $self, $class;
    $self-&gt;{arch} //= get_host_arch();
    $self-&gt;clear();
    if (exists $self-&gt;{file}) {
	$self-&gt;load($self-&gt;{file}) if -e $self-&gt;{file};
    }
    return $self;
}

sub get_arch {
    my $self = shift;
    return $self-&gt;{arch};
}

sub clear {
    my $self = shift;
    $self-&gt;{objects} = {};
}

sub clear_except {
    my ($self, @ids) = @_;

    my %has = map { $_ =&gt; 1 } @ids;
    foreach my $objid (keys %{$self-&gt;{objects}}) {
	delete $self-&gt;{objects}{$objid} unless exists $has{$objid};
    }
}

sub get_sonames {
    my $self = shift;
    return keys %{$self-&gt;{objects}};
}

sub get_symbols {
    my ($self, $soname) = @_;
    if (defined $soname) {
	my $obj = $self-&gt;get_object($soname);
	return (defined $obj) ? values %{$obj-&gt;{syms}} : ();
    } else {
	my @syms;
	foreach my $soname ($self-&gt;get_sonames()) {
	    push @syms, $self-&gt;get_symbols($soname);
	}
	return @syms;
    }
}

sub get_patterns {
    my ($self, $soname) = @_;
    my @patterns;
    if (defined $soname) {
	my $obj = $self-&gt;get_object($soname);
	foreach my $alias (values %{$obj-&gt;{patterns}{aliases}}) {
	    push @patterns, values %$alias;
	}
	return (@patterns, @{$obj-&gt;{patterns}{generic}});
    } else {
	foreach my $soname ($self-&gt;get_sonames()) {
	    push @patterns, $self-&gt;get_patterns($soname);
	}
	return @patterns;
    }
}

# Create a symbol from the supplied string specification.
sub create_symbol {
    my ($self, $spec, %opts) = @_;
    my $symbol = (exists $opts{base}) ? $opts{base} :
	Dpkg::Shlibs::Symbol-&gt;new();

    my $ret = $opts{dummy} ? $symbol-&gt;parse_symbolspec($spec, default_minver =&gt; 0) :
	$symbol-&gt;parse_symbolspec($spec);
    if ($ret) {
	$symbol-&gt;initialize(arch =&gt; $self-&gt;get_arch());
	return $symbol;
    }
    return;
}

sub add_symbol {
    my ($self, $symbol, $soname) = @_;
    my $object = $self-&gt;get_object($soname);

    if ($symbol-&gt;is_pattern()) {
	if (my $alias_type = $symbol-&gt;get_alias_type()) {
	    $object-&gt;{patterns}{aliases}{$alias_type} //= {};
	    # Alias hash for matching.
	    my $aliases = $object-&gt;{patterns}{aliases}{$alias_type};
	    $aliases-&gt;{$symbol-&gt;get_symbolname()} = $symbol;
	} else {
	    # Otherwise assume this is a generic sequential pattern. This
	    # should be always safe.
	    push @{$object-&gt;{patterns}{generic}}, $symbol;
	}
	return 'pattern';
    } else {
	# invalidate the minimum version cache
        $object-&gt;{minver_cache} = [];
	$object-&gt;{syms}{$symbol-&gt;get_symbolname()} = $symbol;
	return 'sym';
    }
}

sub _new_symbol {
    my $base = shift || 'Dpkg::Shlibs::Symbol';
    return (ref $base) ? $base-&gt;clone(@_) : $base-&gt;new(@_);
}

# Option state is only used for recursive calls.
sub parse {
    my ($self, $fh, $file, %opts) = @_;
    my $state = $opts{state} //= {};

    if (exists $state-&gt;{seen}) {
	return if exists $state-&gt;{seen}{$file}; # Avoid include loops
    } else {
	$self-&gt;{file} = $file;
        $state-&gt;{seen} = {};
    }
    $state-&gt;{seen}{$file} = 1;

    if (not ref $state-&gt;{obj_ref}) { # Init ref to name of current object/lib
        ${$state-&gt;{obj_ref}} = undef;
    }

    while (&lt;$fh&gt;) {
	chomp;

	if (/^(?:\s+|#(?:DEPRECATED|MISSING): ([^#]+)#\s*)(.*)/) {
	    if (not defined ${$state-&gt;{obj_ref}}) {
		error(g_('symbol information must be preceded by a header (file %s, line %s)'), $file, $.);
	    }
	    # Symbol specification
	    my $deprecated = ($1) ? Dpkg::Version-&gt;new($1) : 0;
	    my $sym = _new_symbol($state-&gt;{base_symbol}, deprecated =&gt; $deprecated);
	    if ($self-&gt;create_symbol($2, base =&gt; $sym)) {
		$self-&gt;add_symbol($sym, ${$state-&gt;{obj_ref}});
	    } else {
		warning(g_('failed to parse line in %s: %s'), $file, $_);
	    }
	} elsif (/^(\(.*\))?#include\s+"([^"]+)"/) {
	    my $tagspec = $1;
	    my $filename = $2;
	    my $dir = $file;
	    my $old_base_symbol = $state-&gt;{base_symbol};
	    my $new_base_symbol;
	    if (defined $tagspec) {
		$new_base_symbol = _new_symbol($old_base_symbol);
		$new_base_symbol-&gt;parse_tagspec($tagspec);
	    }
	    $state-&gt;{base_symbol} = $new_base_symbol;
	    $dir =~ s{[^/]+$}{}; # Strip filename
	    $self-&gt;load("$dir$filename", %opts);
	    $state-&gt;{base_symbol} = $old_base_symbol;
	} elsif (/^#|^$/) {
	    # Skip possible comments and empty lines
	} elsif (/^\|\s*(.*)$/) {
	    # Alternative dependency template
	    push @{$self-&gt;{objects}{${$state-&gt;{obj_ref}}}{deps}}, "$1";
	} elsif (/^\*\s*([^:]+):\s*(.*\S)\s*$/) {
	    # Add meta-fields
	    $self-&gt;{objects}{${$state-&gt;{obj_ref}}}{fields}{field_capitalize($1)} = $2;
	} elsif (/^(\S+)\s+(.*)$/) {
	    # New object and dependency template
	    ${$state-&gt;{obj_ref}} = $1;
	    if (exists $self-&gt;{objects}{${$state-&gt;{obj_ref}}}) {
		# Update/override infos only
		$self-&gt;{objects}{${$state-&gt;{obj_ref}}}{deps} = [ "$2" ];
	    } else {
		# Create a new object
		$self-&gt;create_object(${$state-&gt;{obj_ref}}, "$2");
	    }
	} else {
	    warning(g_('failed to parse a line in %s: %s'), $file, $_);
	}
    }
    delete $state-&gt;{seen}{$file};
}

# Beware: we reuse the data structure of the provided symfile so make
# sure to not modify them after having called this function
sub merge_object_from_symfile {
    my ($self, $src, $objid) = @_;
    if (not $self-&gt;has_object($objid)) {
        $self-&gt;{objects}{$objid} = $src-&gt;get_object($objid);
    } else {
        warning(g_('tried to merge the same object (%s) twice in a symfile'), $objid);
    }
}

sub output {
    my ($self, $fh, %opts) = @_;
    $opts{template_mode} //= 0;
    $opts{with_deprecated} //= 1;
    $opts{with_pattern_matches} //= 0;
    my $res = '';
    foreach my $soname (sort $self-&gt;get_sonames()) {
	my @deps = $self-&gt;get_dependencies($soname);
	my $dep_first = shift @deps;
	if (exists $opts{package} and not $opts{template_mode}) {
	    $dep_first =~ s/#PACKAGE#/$opts{package}/g;
	}
	print { $fh } "$soname $dep_first\n" if defined $fh;
	$res .= "$soname $dep_first\n" if defined wantarray;

	foreach my $dep_next (@deps) {
	    if (exists $opts{package} and not $opts{template_mode}) {
	        $dep_next =~ s/#PACKAGE#/$opts{package}/g;
	    }
	    print { $fh } "| $dep_next\n" if defined $fh;
	    $res .= "| $dep_next\n" if defined wantarray;
	}
	my $f = $self-&gt;{objects}{$soname}{fields};
	foreach my $field (sort keys %{$f}) {
	    my $value = $f-&gt;{$field};
	    if (exists $opts{package} and not $opts{template_mode}) {
	        $value =~ s/#PACKAGE#/$opts{package}/g;
	    }
	    print { $fh } "* $field: $value\n" if defined $fh;
	    $res .= "* $field: $value\n" if defined wantarray;
	}

	my @symbols;
	if ($opts{template_mode}) {
	    # Exclude symbols matching a pattern, but include patterns themselves
	    @symbols = grep { not $_-&gt;get_pattern() } $self-&gt;get_symbols($soname);
	    push @symbols, $self-&gt;get_patterns($soname);
	} else {
	    @symbols = $self-&gt;get_symbols($soname);
	}
	foreach my $sym (sort { $a-&gt;get_symboltempl() cmp
	                        $b-&gt;get_symboltempl() } @symbols) {
	    next if $sym-&gt;{deprecated} and not $opts{with_deprecated};
	    # Do not dump symbols from foreign arch unless dumping a template.
	    next if not $opts{template_mode} and
	            not $sym-&gt;arch_is_concerned($self-&gt;get_arch());
	    # Dump symbol specification. Dump symbol tags only in template mode.
	    print { $fh } $sym-&gt;get_symbolspec($opts{template_mode}), "\n" if defined $fh;
	    $res .= $sym-&gt;get_symbolspec($opts{template_mode}) . "\n" if defined wantarray;
	    # Dump pattern matches as comments (if requested)
	    if ($opts{with_pattern_matches} &amp;&amp; $sym-&gt;is_pattern()) {
		for my $match (sort { $a-&gt;get_symboltempl() cmp
		                      $b-&gt;get_symboltempl() } $sym-&gt;get_pattern_matches())
		{
		    print { $fh } '#MATCH:', $match-&gt;get_symbolspec(0), "\n" if defined $fh;
		    $res .= '#MATCH:' . $match-&gt;get_symbolspec(0) . "\n" if defined wantarray;
		}
	    }
	}
    }
    return $res;
}

# Tries to match a symbol name and/or version against the patterns defined.
# Returns a pattern which matches (if any).
sub find_matching_pattern {
    my ($self, $refsym, $sonames, $inc_deprecated) = @_;
    $inc_deprecated //= 0;
    my $name = (ref $refsym) ? $refsym-&gt;get_symbolname() : $refsym;

    my $pattern_ok = sub {
	my $p = shift;
	return defined $p &amp;&amp; ($inc_deprecated || !$p-&gt;{deprecated}) &amp;&amp;
	       $p-&gt;arch_is_concerned($self-&gt;get_arch());
    };

    foreach my $soname ((ref($sonames) eq 'ARRAY') ? @$sonames : $sonames) {
	my $obj = $self-&gt;get_object($soname);
	my ($type, $pattern);
	next unless defined $obj;

	my $all_aliases = $obj-&gt;{patterns}{aliases};
	for my $type (Dpkg::Shlibs::Symbol::ALIAS_TYPES) {
	    if (exists $all_aliases-&gt;{$type} &amp;&amp; keys(%{$all_aliases-&gt;{$type}})) {
		my $aliases = $all_aliases-&gt;{$type};
		my $converter = $aliases-&gt;{(keys %$aliases)[0]};
		if (my $alias = $converter-&gt;convert_to_alias($name)) {
		    if ($alias &amp;&amp; exists $aliases-&gt;{$alias}) {
			$pattern = $aliases-&gt;{$alias};
			last if $pattern_ok-&gt;($pattern);
			$pattern = undef; # otherwise not found yet
		    }
		}
	    }
	}

	# Now try generic patterns and use the first that matches
	if (not defined $pattern) {
	    for my $p (@{$obj-&gt;{patterns}{generic}}) {
		if ($pattern_ok-&gt;($p) &amp;&amp; $p-&gt;matches_rawname($name)) {
		    $pattern = $p;
		    last;
		}
	    }
	}
	if (defined $pattern) {
	    return (wantarray) ?
		( symbol =&gt; $pattern, soname =&gt; $soname ) : $pattern;
	}
    }
    return;
}

# merge_symbols($object, $minver)
# Needs $Objdump-&gt;get_object($soname) as parameter
# Don't merge blacklisted symbols related to the internal (arch-specific)
# machinery
sub merge_symbols {
    my ($self, $object, $minver) = @_;

    my $soname = $object-&gt;{SONAME};
    error(g_('cannot merge symbols from objects without SONAME'))
        unless $soname;

    my %include_groups = ();
    my $groups = $self-&gt;get_field($soname, 'Ignore-Blacklist-Groups');
    if (defined $groups) {
        $include_groups{$_} = 1 foreach (split ' ', $groups);
    }

    my %dynsyms;
    foreach my $sym ($object-&gt;get_exported_dynamic_symbols()) {
        my $name = $sym-&gt;{name} . '@' .
                   ($sym-&gt;{version} ? $sym-&gt;{version} : 'Base');
        my $symobj = $self-&gt;lookup_symbol($name, $soname);
        if (symbol_is_blacklisted($sym-&gt;{name}, \%include_groups)) {
            next unless (defined $symobj and $symobj-&gt;has_tag('ignore-blacklist'));
        }
        $dynsyms{$name} = $sym;
    }

    unless ($self-&gt;has_object($soname)) {
	$self-&gt;create_object($soname, '');
    }
    # Scan all symbols provided by the objects
    my $obj = $self-&gt;get_object($soname);
    # invalidate the minimum version cache - it is not sufficient to
    # invalidate in add_symbol, since we might change a minimum
    # version for a particular symbol without adding it
    $obj-&gt;{minver_cache} = [];
    foreach my $name (keys %dynsyms) {
        my $sym;
	if ($sym = $self-&gt;lookup_symbol($name, $obj, 1)) {
	    # If the symbol is already listed in the file
	    $sym-&gt;mark_found_in_library($minver, $self-&gt;get_arch());
	} else {
	    # The exact symbol is not present in the file, but it might match a
	    # pattern.
	    my $pattern = $self-&gt;find_matching_pattern($name, $obj, 1);
	    if (defined $pattern) {
		$pattern-&gt;mark_found_in_library($minver, $self-&gt;get_arch());
		$sym = $pattern-&gt;create_pattern_match(symbol =&gt; $name);
	    } else {
		# Symbol without any special info as no pattern matched
		$sym = Dpkg::Shlibs::Symbol-&gt;new(symbol =&gt; $name,
		                                 minver =&gt; $minver);
	    }
	    $self-&gt;add_symbol($sym, $obj);
	}
    }

    # Process all symbols which could not be found in the library.
    foreach my $sym ($self-&gt;get_symbols($soname)) {
	if (not exists $dynsyms{$sym-&gt;get_symbolname()}) {
	    $sym-&gt;mark_not_found_in_library($minver, $self-&gt;get_arch());
	}
    }

    # Deprecate patterns which didn't match anything
    for my $pattern (grep { $_-&gt;get_pattern_matches() == 0 }
                          $self-&gt;get_patterns($soname)) {
	$pattern-&gt;mark_not_found_in_library($minver, $self-&gt;get_arch());
    }
}

sub is_empty {
    my $self = shift;
    return scalar(keys %{$self-&gt;{objects}}) ? 0 : 1;
}

sub has_object {
    my ($self, $soname) = @_;
    return exists $self-&gt;{objects}{$soname};
}

sub get_object {
    my ($self, $soname) = @_;
    return ref($soname) ? $soname : $self-&gt;{objects}{$soname};
}

sub create_object {
    my ($self, $soname, @deps) = @_;
    $self-&gt;{objects}{$soname} = {
	syms =&gt; {},
	fields =&gt; {},
	patterns =&gt; {
	    aliases =&gt; {},
	    generic =&gt; [],
	},
	deps =&gt; [ @deps ],
        minver_cache =&gt; []
    };
}

sub get_dependency {
    my ($self, $soname, $dep_id) = @_;
    $dep_id //= 0;
    return $self-&gt;get_object($soname)-&gt;{deps}[$dep_id];
}

sub get_smallest_version {
    my ($self, $soname, $dep_id) = @_;
    $dep_id //= 0;
    my $so_object = $self-&gt;get_object($soname);
    return $so_object-&gt;{minver_cache}[$dep_id]
        if defined $so_object-&gt;{minver_cache}[$dep_id];
    my $minver;
    foreach my $sym ($self-&gt;get_symbols($so_object)) {
        next if $dep_id != $sym-&gt;{dep_id};
        $minver //= $sym-&gt;{minver};
        if (version_compare($minver, $sym-&gt;{minver}) &gt; 0) {
            $minver = $sym-&gt;{minver};
        }
    }
    $so_object-&gt;{minver_cache}[$dep_id] = $minver;
    return $minver;
}

sub get_dependencies {
    my ($self, $soname) = @_;
    return @{$self-&gt;get_object($soname)-&gt;{deps}};
}

sub get_field {
    my ($self, $soname, $name) = @_;
    if (my $obj = $self-&gt;get_object($soname)) {
	if (exists $obj-&gt;{fields}{$name}) {
	    return $obj-&gt;{fields}{$name};
	}
    }
    return;
}

# Tries to find a symbol like the $refsym and returns its descriptor.
# $refsym may also be a symbol name.
sub lookup_symbol {
    my ($self, $refsym, $sonames, $inc_deprecated) = @_;
    $inc_deprecated //= 0;
    my $name = (ref $refsym) ? $refsym-&gt;get_symbolname() : $refsym;

    foreach my $so ((ref($sonames) eq 'ARRAY') ? @$sonames : $sonames) {
	if (my $obj = $self-&gt;get_object($so)) {
	    my $sym = $obj-&gt;{syms}{$name};
	    if ($sym and ($inc_deprecated or not $sym-&gt;{deprecated}))
	    {
		return (wantarray) ?
		    ( symbol =&gt; $sym, soname =&gt; $so ) : $sym;
	    }
	}
    }
    return;
}

# Tries to find a pattern like the $refpat and returns its descriptor.
# $refpat may also be a pattern spec.
sub lookup_pattern {
    my ($self, $refpat, $sonames, $inc_deprecated) = @_;
    $inc_deprecated //= 0;
    # If $refsym is a string, we need to create a dummy ref symbol.
    $refpat = $self-&gt;create_symbol($refpat, dummy =&gt; 1) if ! ref($refpat);

    if ($refpat &amp;&amp; $refpat-&gt;is_pattern()) {
	foreach my $soname ((ref($sonames) eq 'ARRAY') ? @$sonames : $sonames) {
	    if (my $obj = $self-&gt;get_object($soname)) {
		my $pat;
		if (my $type = $refpat-&gt;get_alias_type()) {
		    if (exists $obj-&gt;{patterns}{aliases}{$type}) {
			$pat = $obj-&gt;{patterns}{aliases}{$type}{$refpat-&gt;get_symbolname()};
		    }
		} elsif ($refpat-&gt;get_pattern_type() eq 'generic') {
		    for my $p (@{$obj-&gt;{patterns}{generic}}) {
			if (($inc_deprecated || !$p-&gt;{deprecated}) &amp;&amp;
			    $p-&gt;equals($refpat, versioning =&gt; 0))
			{
			    $pat = $p;
			    last;
			}
		    }
		}
		if ($pat &amp;&amp; ($inc_deprecated || !$pat-&gt;{deprecated})) {
		    return (wantarray) ?
			(symbol =&gt; $pat, soname =&gt; $soname) : $pat;
		}
	    }
	}
    }
    return;
}

# Get symbol object reference either by symbol name or by a reference object.
sub get_symbol_object {
    my ($self, $refsym, $soname) = @_;
    my $sym = $self-&gt;lookup_symbol($refsym, $soname, 1);
    if (! defined $sym) {
	$sym = $self-&gt;lookup_pattern($refsym, $soname, 1);
    }
    return $sym;
}

sub get_new_symbols {
    my ($self, $ref, %opts) = @_;
    my $with_optional = (exists $opts{with_optional}) ?
	$opts{with_optional} : 0;
    my @res;
    foreach my $soname ($self-&gt;get_sonames()) {
	next if not $ref-&gt;has_object($soname);

	# Scan raw symbols first.
	foreach my $sym (grep { ($with_optional || ! $_-&gt;is_optional())
	                        &amp;&amp; $_-&gt;is_legitimate($self-&gt;get_arch()) }
	                      $self-&gt;get_symbols($soname))
	{
	    my $refsym = $ref-&gt;lookup_symbol($sym, $soname, 1);
	    my $isnew;
	    if (defined $refsym) {
		# If the symbol exists in the $ref symbol file, it might
		# still be new if $refsym is not legitimate.
		$isnew = not $refsym-&gt;is_legitimate($self-&gt;get_arch());
	    } else {
		# If the symbol does not exist in the $ref symbol file, it does
		# not mean that it's new. It might still match a pattern in the
		# symbol file. However, due to performance reasons, first check
		# if the pattern that the symbol matches (if any) exists in the
		# ref symbol file as well.
		$isnew = not (
		    ($sym-&gt;get_pattern() and $ref-&gt;lookup_pattern($sym-&gt;get_pattern(), $soname, 1)) or
		    $ref-&gt;find_matching_pattern($sym, $soname, 1)
		);
	    }
	    push @res, { symbol =&gt; $sym, soname =&gt; $soname } if $isnew;
	}

	# Now scan patterns
	foreach my $p (grep { ($with_optional || ! $_-&gt;is_optional())
	                      &amp;&amp; $_-&gt;is_legitimate($self-&gt;get_arch()) }
	                    $self-&gt;get_patterns($soname))
	{
	    my $refpat = $ref-&gt;lookup_pattern($p, $soname, 0);
	    # If reference pattern was not found or it is not legitimate,
	    # considering current one as new.
	    if (not defined $refpat or
	        not $refpat-&gt;is_legitimate($self-&gt;get_arch()))
	    {
		push @res, { symbol =&gt; $p , soname =&gt; $soname };
	    }
	}
    }
    return @res;
}

sub get_lost_symbols {
    my ($self, $ref, %opts) = @_;
    return $ref-&gt;get_new_symbols($self, %opts);
}


sub get_new_libs {
    my ($self, $ref) = @_;
    my @res;
    foreach my $soname ($self-&gt;get_sonames()) {
	push @res, $soname if not $ref-&gt;get_object($soname);
    }
    return @res;
}

sub get_lost_libs {
    my ($self, $ref) = @_;
    return $ref-&gt;get_new_libs($self);
}

1;
</pre></body></html>