SymbolFile.pm 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. # Copyright © 2007 Raphaël Hertzog <hertzog@debian.org>
  2. # Copyright © 2009-2010 Modestas Vainius <modax@debian.org>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. package Dpkg::Shlibs::SymbolFile;
  17. use strict;
  18. use warnings;
  19. use Dpkg::Gettext;
  20. use Dpkg::ErrorHandling;
  21. use Dpkg::Version;
  22. use Dpkg::Control::Fields;
  23. use Dpkg::Shlibs::Symbol;
  24. use Dpkg::Arch qw(get_host_arch);
  25. my %blacklist = (
  26. '__bss_end__' => 1, # arm
  27. '__bss_end' => 1, # arm
  28. '_bss_end__' => 1, # arm
  29. '__bss_start' => 1, # ALL
  30. '__bss_start__' => 1, # arm
  31. '__data_start' => 1, # arm
  32. '__do_global_ctors_aux' => 1, # ia64
  33. '__do_global_dtors_aux' => 1, # ia64
  34. '__do_jv_register_classes' => 1,# ia64
  35. '_DYNAMIC' => 1, # ALL
  36. '_edata' => 1, # ALL
  37. '_end' => 1, # ALL
  38. '__end__' => 1, # arm
  39. '__exidx_end' => 1, # armel
  40. '__exidx_start' => 1, # armel
  41. '_fbss' => 1, # mips, mipsel
  42. '_fdata' => 1, # mips, mipsel
  43. '_fini' => 1, # ALL
  44. '_ftext' => 1, # mips, mipsel
  45. '_GLOBAL_OFFSET_TABLE_' => 1, # hppa, mips, mipsel
  46. '__gmon_start__' => 1, # hppa
  47. '__gnu_local_gp' => 1, # mips, mipsel
  48. '_gp' => 1, # mips, mipsel
  49. '_init' => 1, # ALL
  50. '_PROCEDURE_LINKAGE_TABLE_' => 1, # sparc, alpha
  51. '_SDA2_BASE_' => 1, # powerpc
  52. '_SDA_BASE_' => 1, # powerpc
  53. );
  54. for (my $i = 14; $i <= 31; $i++) {
  55. # Many powerpc specific symbols
  56. $blacklist{"_restfpr_$i"} = 1;
  57. $blacklist{"_restfpr_$i\_x"} = 1;
  58. $blacklist{"_restgpr_$i"} = 1;
  59. $blacklist{"_restgpr_$i\_x"} = 1;
  60. $blacklist{"_savefpr_$i"} = 1;
  61. $blacklist{"_savegpr_$i"} = 1;
  62. }
  63. # Many armel-specific symbols
  64. $blacklist{"__aeabi_$_"} = 1 foreach (qw(cdcmpeq cdcmple cdrcmple cfcmpeq
  65. cfcmple cfrcmple d2f d2iz d2lz d2uiz d2ulz dadd dcmpeq dcmpge dcmpgt
  66. dcmple dcmplt dcmpun ddiv dmul dneg drsub dsub f2d f2iz f2lz f2uiz f2ulz
  67. fadd fcmpeq fcmpge fcmpgt fcmple fcmplt fcmpun fdiv fmul fneg frsub fsub
  68. i2d i2f idiv idivmod l2d l2f lasr lcmp ldivmod llsl llsr lmul ui2d ui2f
  69. uidiv uidivmod ul2d ul2f ulcmp uldivmod unwind_cpp_pr0 unwind_cpp_pr1
  70. unwind_cpp_pr2 uread4 uread8 uwrite4 uwrite8));
  71. sub new {
  72. my $this = shift;
  73. my %opts=@_;
  74. my $class = ref($this) || $this;
  75. my $self = \%opts;
  76. bless $self, $class;
  77. $self->{arch} = get_host_arch() unless defined $self->{arch};
  78. $self->clear();
  79. if (exists $self->{file}) {
  80. $self->load($self->{file}) if -e $self->{file};
  81. }
  82. return $self;
  83. }
  84. sub clear {
  85. my ($self) = @_;
  86. $self->{objects} = {};
  87. }
  88. sub clear_except {
  89. my ($self, @ids) = @_;
  90. my %has;
  91. $has{$_} = 1 foreach (@ids);
  92. foreach my $objid (keys %{$self->{objects}}) {
  93. delete $self->{objects}{$objid} unless exists $has{$objid};
  94. }
  95. }
  96. # Create a symbol from the supplied string specification.
  97. sub create_symbol {
  98. my ($self, $spec, $symbol) = @_;
  99. $symbol = Dpkg::Shlibs::Symbol->new() unless defined $symbol;
  100. if ($symbol->parse($spec)) {
  101. $symbol->initialize(arch => $self->{arch});
  102. return $symbol;
  103. }
  104. return undef;
  105. }
  106. sub add_symbol {
  107. my ($self, $symbol, $soname) = @_;
  108. my $object = (ref $soname) ? $soname : $self->{objects}{$soname};
  109. if ($symbol->is_pattern()) {
  110. if (my $alias_type = $symbol->get_alias_type()) {
  111. unless (exists $object->{patterns}{aliases}{$alias_type}) {
  112. $object->{patterns}{aliases}{$alias_type} = {};
  113. }
  114. # Alias hash for matching.
  115. my $aliases = $object->{patterns}{aliases}{$alias_type};
  116. $aliases->{$symbol->get_symbolname()} = $symbol;
  117. } else {
  118. # Otherwise assume this is a generic sequential pattern. This
  119. # should be always safe.
  120. push @{$object->{patterns}{generic}}, $symbol;
  121. }
  122. return 'pattern';
  123. } else {
  124. # invalidate the minimum version cache
  125. $object->{minver_cache} = [];
  126. $object->{syms}{$symbol->get_symbolname()} = $symbol;
  127. return 'sym';
  128. }
  129. }
  130. # Parameter seen is only used for recursive calls
  131. sub load {
  132. my ($self, $file, $seen, $obj_ref, $base_symbol) = @_;
  133. sub new_symbol {
  134. my $base = shift || 'Dpkg::Shlibs::Symbol';
  135. return (ref $base) ? $base->dclone(@_) : $base->new(@_);
  136. }
  137. if (defined($seen)) {
  138. return if exists $seen->{$file}; # Avoid include loops
  139. } else {
  140. $self->{file} = $file;
  141. $seen = {};
  142. }
  143. $seen->{$file} = 1;
  144. if (not ref($obj_ref)) { # Init ref to name of current object/lib
  145. $$obj_ref = undef;
  146. }
  147. open(my $sym_file, "<", $file)
  148. || syserr(_g("cannot open %s"), $file);
  149. while (defined($_ = <$sym_file>)) {
  150. chomp($_);
  151. if (/^(?:\s+|#(?:DEPRECATED|MISSING): ([^#]+)#\s*)(.*)/) {
  152. if (not defined ($$obj_ref)) {
  153. error(_g("Symbol information must be preceded by a header (file %s, line %s)."), $file, $.);
  154. }
  155. # Symbol specification
  156. my $deprecated = ($1) ? $1 : 0;
  157. my $sym = new_symbol($base_symbol, deprecated => $deprecated);
  158. if ($self->create_symbol($2, $sym)) {
  159. $self->add_symbol($sym, $$obj_ref);
  160. } else {
  161. warning(_g("Failed to parse line in %s: %s"), $file, $_);
  162. }
  163. } elsif (/^(\(.*\))?#include\s+"([^"]+)"/) {
  164. my $tagspec = $1;
  165. my $filename = $2;
  166. my $dir = $file;
  167. my $new_base_symbol;
  168. if (defined $tagspec) {
  169. $new_base_symbol = new_symbol($base_symbol);
  170. $new_base_symbol->parse_tagspec($tagspec);
  171. }
  172. $dir =~ s{[^/]+$}{}; # Strip filename
  173. $self->load("$dir$filename", $seen, $obj_ref, $new_base_symbol);
  174. } elsif (/^#/) {
  175. # Skip possible comments
  176. } elsif (/^\|\s*(.*)$/) {
  177. # Alternative dependency template
  178. push @{$self->{objects}{$$obj_ref}{deps}}, "$1";
  179. } elsif (/^\*\s*([^:]+):\s*(.*\S)\s*$/) {
  180. # Add meta-fields
  181. $self->{objects}{$$obj_ref}{fields}{field_capitalize($1)} = $2;
  182. } elsif (/^(\S+)\s+(.*)$/) {
  183. # New object and dependency template
  184. $$obj_ref = $1;
  185. if (exists $self->{objects}{$$obj_ref}) {
  186. # Update/override infos only
  187. $self->{objects}{$$obj_ref}{deps} = [ "$2" ];
  188. } else {
  189. # Create a new object
  190. $self->create_object($$obj_ref, "$2");
  191. }
  192. } else {
  193. warning(_g("Failed to parse a line in %s: %s"), $file, $_);
  194. }
  195. }
  196. close($sym_file);
  197. delete $seen->{$file};
  198. }
  199. # Beware: we reuse the data structure of the provided symfile so make
  200. # sure to not modify them after having called this function
  201. sub merge_object_from_symfile {
  202. my ($self, $src, $objid) = @_;
  203. if (not $self->has_object($objid)) {
  204. $self->{objects}{$objid} = $src->{objects}{$objid};
  205. } else {
  206. warning(_g("Tried to merge the same object (%s) twice in a symfile."), $objid);
  207. }
  208. }
  209. sub save {
  210. my ($self, $file, %opts) = @_;
  211. $file = $self->{file} unless defined($file);
  212. my $fh;
  213. if ($file eq "-") {
  214. $fh = \*STDOUT;
  215. } else {
  216. open($fh, ">", $file)
  217. || syserr(_g("cannot write %s"), $file);
  218. }
  219. $self->dump($fh, %opts);
  220. close($fh) if ($file ne "-");
  221. }
  222. sub dump {
  223. my ($self, $fh, %opts) = @_;
  224. $opts{template_mode} = 0 unless exists $opts{template_mode};
  225. $opts{with_deprecated} = 1 unless exists $opts{with_deprecated};
  226. $opts{with_pattern_matches} = 0 unless exists $opts{with_pattern_matches};
  227. foreach my $soname (sort keys %{$self->{objects}}) {
  228. my @deps = @{$self->{objects}{$soname}{deps}};
  229. my $dep = shift @deps;
  230. $dep =~ s/#PACKAGE#/$opts{package}/g if exists $opts{package};
  231. print $fh "$soname $dep\n";
  232. foreach $dep (@deps) {
  233. $dep =~ s/#PACKAGE#/$opts{package}/g if exists $opts{package};
  234. print $fh "| $dep\n";
  235. }
  236. my $f = $self->{objects}{$soname}{fields};
  237. foreach my $field (sort keys %{$f}) {
  238. my $value = $f->{$field};
  239. $value =~ s/#PACKAGE#/$opts{package}/g if exists $opts{package};
  240. print $fh "* $field: $value\n";
  241. }
  242. my $syms = $self->{objects}{$soname}{syms};
  243. my @symbols;
  244. if ($opts{template_mode}) {
  245. # Exclude symbols matching a pattern, but include patterns themselves
  246. @symbols = grep { not $_->get_pattern() } values %$syms;
  247. push @symbols, $self->get_soname_patterns($soname);
  248. } else {
  249. @symbols = values %$syms;
  250. }
  251. foreach my $sym (sort { $a->get_symboltempl() cmp
  252. $b->get_symboltempl() } @symbols) {
  253. next if $sym->{deprecated} and not $opts{with_deprecated};
  254. # Do not dump symbols from foreign arch unless dumping a template.
  255. next if not $opts{template_mode} and
  256. not $sym->arch_is_concerned($self->{arch});
  257. # Dump symbol specification. Dump symbol tags only in template mode.
  258. print $fh $sym->get_symbolspec($opts{template_mode}), "\n";
  259. # Dump pattern matches as comments (if requested)
  260. if ($opts{with_pattern_matches} && $sym->is_pattern()) {
  261. for my $match (sort { $a->get_symboltempl() cmp
  262. $b->get_symboltempl() } $sym->get_pattern_matches())
  263. {
  264. print $fh "#MATCH:", $match->get_symbolspec(0), "\n";
  265. }
  266. }
  267. }
  268. }
  269. }
  270. # Tries to match a symbol name and/or version against the patterns defined.
  271. # Returns a pattern which matches (if any).
  272. sub find_matching_pattern {
  273. my ($self, $name, $sonames, $inc_deprecated) = @_;
  274. $inc_deprecated = 0 unless defined $inc_deprecated;
  275. my $pattern_ok = sub {
  276. my $p = shift;
  277. return defined $p && ($inc_deprecated || !$p->{deprecated}) &&
  278. $p->arch_is_concerned($self->{arch});
  279. };
  280. foreach my $soname (@$sonames) {
  281. my $obj = (ref $soname) ? $soname : $self->{objects}{$soname};
  282. my ($type, $pattern);
  283. next unless defined $obj;
  284. my $all_aliases = $obj->{patterns}{aliases};
  285. for my $type (Dpkg::Shlibs::Symbol::ALIAS_TYPES) {
  286. if (exists $all_aliases->{$type} && keys(%{$all_aliases->{$type}})) {
  287. my $aliases = $all_aliases->{$type};
  288. my $converter = $aliases->{(keys %$aliases)[0]};
  289. if (my $alias = $converter->convert_to_alias($name)) {
  290. if ($alias && exists $aliases->{$alias}) {
  291. $pattern = $aliases->{$alias};
  292. last if &$pattern_ok($pattern);
  293. $pattern = undef; # otherwise not found yet
  294. }
  295. }
  296. }
  297. }
  298. # Now try generic patterns and use the first that matches
  299. if (not defined $pattern) {
  300. for my $p (@{$obj->{patterns}{generic}}) {
  301. if (&$pattern_ok($p) && $p->matches_rawname($name)) {
  302. $pattern = $p;
  303. last;
  304. }
  305. }
  306. }
  307. if (defined $pattern) {
  308. return $pattern;
  309. }
  310. }
  311. return undef;
  312. }
  313. # merge_symbols($object, $minver)
  314. # Needs $Objdump->get_object($soname) as parameter
  315. # Don't merge blacklisted symbols related to the internal (arch-specific)
  316. # machinery
  317. sub merge_symbols {
  318. my ($self, $object, $minver) = @_;
  319. my $soname = $object->{SONAME} || error(_g("Can't merge symbols from objects without SONAME."));
  320. my %dynsyms;
  321. foreach my $sym ($object->get_exported_dynamic_symbols()) {
  322. my $name = $sym->{name} . '@' .
  323. ($sym->{version} ? $sym->{version} : "Base");
  324. my $symobj = $self->lookup_symbol($name, [ $soname ]);
  325. if (exists $blacklist{$sym->{name}}) {
  326. next unless (defined $symobj and $symobj->has_tag("ignore-blacklist"));
  327. }
  328. $dynsyms{$name} = $sym;
  329. }
  330. unless (exists $self->{objects}{$soname}) {
  331. $self->create_object($soname, '');
  332. }
  333. # Scan all symbols provided by the objects
  334. my $obj = $self->{objects}{$soname};
  335. my @obj = ( $obj );
  336. # invalidate the minimum version cache - it is not sufficient to
  337. # invalidate in add_symbol, since we might change a minimum
  338. # version for a particular symbol without adding it
  339. $obj->{minver_cache} = [];
  340. foreach my $name (keys %dynsyms) {
  341. my $sym;
  342. if (exists $obj->{syms}{$name}) {
  343. # If the symbol is already listed in the file
  344. $sym = $obj->{syms}{$name};
  345. $sym->mark_found_in_library($minver, $self->{arch});
  346. } else {
  347. # The exact symbol is not present in the file, but it might match a
  348. # pattern.
  349. my $symobj = $dynsyms{$name};
  350. my $pattern = $self->find_matching_pattern($name, \@obj, 1);
  351. if (defined $pattern) {
  352. $pattern->mark_found_in_library($minver, $self->{arch});
  353. $sym = $pattern->create_pattern_match(symbol => $name);
  354. } else {
  355. # Symbol without any special info as no pattern matched
  356. $sym = Dpkg::Shlibs::Symbol->new(symbol => $name,
  357. minver => $minver);
  358. }
  359. $self->add_symbol($sym, $obj);
  360. }
  361. }
  362. # Process all symbols which could not be found in the library.
  363. foreach my $name (keys %{$self->{objects}{$soname}{syms}}) {
  364. if (not exists $dynsyms{$name}) {
  365. my $sym = $self->{objects}{$soname}{syms}{$name};
  366. $sym->mark_not_found_in_library($minver, $self->{arch});
  367. }
  368. }
  369. # Deprecate patterns which didn't match anything
  370. for my $pattern (grep { $_->get_pattern_matches() == 0 }
  371. $self->get_soname_patterns($soname)) {
  372. $pattern->mark_not_found_in_library($minver, $self->{arch});
  373. }
  374. }
  375. sub is_empty {
  376. my ($self) = @_;
  377. return scalar(keys %{$self->{objects}}) ? 0 : 1;
  378. }
  379. sub has_object {
  380. my ($self, $soname) = @_;
  381. return exists $self->{objects}{$soname};
  382. }
  383. sub create_object {
  384. my ($self, $soname, @deps) = @_;
  385. $self->{objects}{$soname} = {
  386. syms => {},
  387. fields => {},
  388. patterns => {
  389. aliases => {},
  390. generic => [],
  391. },
  392. deps => [ @deps ],
  393. minver_cache => []
  394. };
  395. }
  396. sub get_dependency {
  397. my ($self, $soname, $dep_id) = @_;
  398. $dep_id = 0 unless defined($dep_id);
  399. return $self->{objects}{$soname}{deps}[$dep_id];
  400. }
  401. sub get_smallest_version {
  402. my ($self, $soname, $dep_id) = @_;
  403. $dep_id = 0 unless defined($dep_id);
  404. my $so_object = $self->{objects}{$soname};
  405. return $so_object->{minver_cache}[$dep_id] if(defined($so_object->{minver_cache}[$dep_id]));
  406. my $minver;
  407. foreach my $sym (values %{$so_object->{syms}}) {
  408. next if $dep_id != $sym->{dep_id};
  409. $minver = $sym->{minver} unless defined($minver);
  410. if (version_compare($minver, $sym->{minver}) > 0) {
  411. $minver = $sym->{minver};
  412. }
  413. }
  414. $so_object->{minver_cache}[$dep_id] = $minver;
  415. return $minver;
  416. }
  417. sub get_dependencies {
  418. my ($self, $soname) = @_;
  419. return @{$self->{objects}{$soname}{deps}};
  420. }
  421. sub get_field {
  422. my ($self, $soname, $name) = @_;
  423. if (exists $self->{objects}{$soname}{fields}{$name}) {
  424. return $self->{objects}{$soname}{fields}{$name};
  425. }
  426. return undef;
  427. }
  428. sub lookup_symbol {
  429. my ($self, $name, $sonames, $inc_deprecated) = @_;
  430. $inc_deprecated = 0 unless defined($inc_deprecated);
  431. foreach my $so (@{$sonames}) {
  432. next if (! exists $self->{objects}{$so});
  433. if (exists $self->{objects}{$so}{syms}{$name} and
  434. ($inc_deprecated or not
  435. $self->{objects}{$so}{syms}{$name}{deprecated}))
  436. {
  437. my $dep_id = $self->{objects}{$so}{syms}{$name}{dep_id};
  438. my $clone = $self->{objects}{$so}{syms}{$name}->sclone();
  439. $clone->{depends} = $self->{objects}{$so}{deps}[$dep_id];
  440. $clone->{soname} = $so;
  441. return $clone;
  442. }
  443. }
  444. return undef;
  445. }
  446. # Tries to find a pattern like the $refpat and returns it. If not found, undef
  447. # is returned.
  448. sub lookup_pattern {
  449. my ($self, $refpat, $sonames, $inc_deprecated) = @_;
  450. $inc_deprecated = 0 unless defined($inc_deprecated);
  451. foreach my $soname (@$sonames) {
  452. my $object = (ref $soname) ? $soname : $self->{objects}{$soname};
  453. my $pat;
  454. next unless defined $object;
  455. if (my $type = $refpat->get_alias_type()) {
  456. if (exists $object->{patterns}{aliases}{$type}) {
  457. $pat = $object->{patterns}{aliases}{$type}{$refpat->get_symbolname()};
  458. }
  459. } elsif ($refpat->get_pattern_type() eq "generic") {
  460. for my $p (@{$object->{patterns}{generic}}) {
  461. if (($inc_deprecated || !$p->{deprecated}) &&
  462. $p->equals($refpat, versioning => 0))
  463. {
  464. $pat = $p;
  465. last;
  466. }
  467. }
  468. }
  469. if ($pat && ($inc_deprecated || !$pat->{deprecated})) {
  470. return $pat;
  471. }
  472. }
  473. return undef;
  474. }
  475. # Collects all patterns of the given soname and returns them as an array.
  476. sub get_soname_patterns {
  477. my ($self, $soname) = @_;
  478. my $object = (ref $soname) ? $soname : $self->{objects}{$soname};
  479. my @aliases;
  480. foreach my $alias (values %{$object->{patterns}{aliases}}) {
  481. push @aliases, values %$alias;
  482. }
  483. return (@aliases, @{$object->{patterns}{generic}});
  484. }
  485. sub get_new_symbols {
  486. my ($self, $ref, %opts) = @_;
  487. my $with_optional = (exists $opts{with_optional}) ?
  488. $opts{with_optional} : 0;
  489. my @res;
  490. foreach my $soname (keys %{$self->{objects}}) {
  491. my $mysyms = $self->{objects}{$soname}{syms};
  492. next if not exists $ref->{objects}{$soname};
  493. my $refsyms = $ref->{objects}{$soname}{syms};
  494. my @soname = ( $soname );
  495. # Scan raw symbols first.
  496. foreach my $sym (grep { ($with_optional || ! $_->is_optional())
  497. && $_->is_legitimate($self->{arch}) }
  498. values %$mysyms)
  499. {
  500. my $refsym = $refsyms->{$sym->get_symbolname()};
  501. my $isnew;
  502. if (defined $refsym) {
  503. # If the symbol exists in the $ref symbol file, it might
  504. # still be new if $refsym is not legitimate.
  505. $isnew = not $refsym->is_legitimate($self->{arch});
  506. } else {
  507. # If the symbol does not exist in the $ref symbol file, it does
  508. # not mean that it's new. It might still match a pattern in the
  509. # symbol file. However, due to performance reasons, first check
  510. # if the pattern that the symbol matches (if any) exists in the
  511. # ref symbol file as well.
  512. $isnew = not (
  513. ($sym->get_pattern() and $ref->lookup_pattern($sym->get_pattern(), \@soname, 1)) or
  514. $ref->find_matching_pattern($sym->get_symbolname(), \@soname, 1)
  515. );
  516. }
  517. push @res, $sym->sclone(soname => $soname) if $isnew;
  518. }
  519. # Now scan patterns
  520. foreach my $p (grep { ($with_optional || ! $_->is_optional())
  521. && $_->is_legitimate($self->{arch}) }
  522. $self->get_soname_patterns($soname))
  523. {
  524. my $refpat = $ref->lookup_pattern($p, \@soname, 0);
  525. # If reference pattern was not found or it is not legitimate,
  526. # considering current one as new.
  527. if (not defined $refpat or
  528. not $refpat->is_legitimate($self->{arch}))
  529. {
  530. push @res, $p->sclone(soname => $soname);
  531. }
  532. }
  533. }
  534. return @res;
  535. }
  536. sub get_lost_symbols {
  537. my ($self, $ref, %opts) = @_;
  538. return $ref->get_new_symbols($self, %opts);
  539. }
  540. sub get_new_libs {
  541. my ($self, $ref) = @_;
  542. my @res;
  543. foreach my $soname (keys %{$self->{objects}}) {
  544. push @res, $soname if not exists $ref->{objects}{$soname};
  545. }
  546. return @res;
  547. }
  548. sub get_lost_libs {
  549. my ($self, $ref) = @_;
  550. return $ref->get_new_libs($self);
  551. }
  552. 1;