SymbolFile.pm 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  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, $soname, $symbol) = @_;
  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. my $aliases = $object->{patterns}{aliases}{$alias_type};
  115. # A converter object for transforming a raw symbol name to alias
  116. # of this type. Must support convert_to_alias() method.
  117. unless (exists $aliases->{converter}) {
  118. $aliases->{converter} = $symbol;
  119. }
  120. # Alias hash for matching.
  121. $aliases->{names}{$symbol->get_symbolname()} = $symbol;
  122. } else {
  123. # Otherwise assume this is a generic sequential pattern. This
  124. # should be always safe.
  125. push @{$object->{patterns}{generic}}, $symbol;
  126. }
  127. return 'pattern';
  128. } else {
  129. # invalidate the minimum version cache
  130. $object->{minver_cache} = [];
  131. $object->{syms}{$symbol->get_symbolname()} = $symbol;
  132. return 'sym';
  133. }
  134. }
  135. # Parameter seen is only used for recursive calls
  136. sub load {
  137. my ($self, $file, $seen, $obj_ref, $base_symbol) = @_;
  138. sub new_symbol {
  139. my $base = shift || 'Dpkg::Shlibs::Symbol';
  140. return (ref $base) ? $base->dclone(@_) : $base->new(@_);
  141. }
  142. if (defined($seen)) {
  143. return if exists $seen->{$file}; # Avoid include loops
  144. } else {
  145. $self->{file} = $file;
  146. $seen = {};
  147. }
  148. $seen->{$file} = 1;
  149. if (not ref($obj_ref)) { # Init ref to name of current object/lib
  150. $$obj_ref = undef;
  151. }
  152. open(my $sym_file, "<", $file)
  153. || syserr(_g("cannot open %s"), $file);
  154. while (defined($_ = <$sym_file>)) {
  155. chomp($_);
  156. if (/^(?:\s+|#(?:DEPRECATED|MISSING): ([^#]+)#\s*)(.*)/) {
  157. if (not defined ($$obj_ref)) {
  158. error(_g("Symbol information must be preceded by a header (file %s, line %s)."), $file, $.);
  159. }
  160. # Symbol specification
  161. my $deprecated = ($1) ? $1 : 0;
  162. my $sym = new_symbol($base_symbol, deprecated => $deprecated);
  163. if ($self->create_symbol($2, $sym)) {
  164. $self->add_symbol($$obj_ref, $sym);
  165. } else {
  166. warning(_g("Failed to parse line in %s: %s"), $file, $_);
  167. }
  168. } elsif (/^(\(.*\))?#include\s+"([^"]+)"/) {
  169. my $tagspec = $1;
  170. my $filename = $2;
  171. my $dir = $file;
  172. my $new_base_symbol;
  173. if (defined $tagspec) {
  174. $new_base_symbol = new_symbol($base_symbol);
  175. $new_base_symbol->parse_tagspec($tagspec);
  176. }
  177. $dir =~ s{[^/]+$}{}; # Strip filename
  178. $self->load("$dir$filename", $seen, $obj_ref, $new_base_symbol);
  179. } elsif (/^#/) {
  180. # Skip possible comments
  181. } elsif (/^\|\s*(.*)$/) {
  182. # Alternative dependency template
  183. push @{$self->{objects}{$$obj_ref}{deps}}, "$1";
  184. } elsif (/^\*\s*([^:]+):\s*(.*\S)\s*$/) {
  185. # Add meta-fields
  186. $self->{objects}{$$obj_ref}{fields}{field_capitalize($1)} = $2;
  187. } elsif (/^(\S+)\s+(.*)$/) {
  188. # New object and dependency template
  189. $$obj_ref = $1;
  190. if (exists $self->{objects}{$$obj_ref}) {
  191. # Update/override infos only
  192. $self->{objects}{$$obj_ref}{deps} = [ "$2" ];
  193. } else {
  194. # Create a new object
  195. $self->create_object($$obj_ref, "$2");
  196. }
  197. } else {
  198. warning(_g("Failed to parse a line in %s: %s"), $file, $_);
  199. }
  200. }
  201. close($sym_file);
  202. delete $seen->{$file};
  203. }
  204. # Beware: we reuse the data structure of the provided symfile so make
  205. # sure to not modify them after having called this function
  206. sub merge_object_from_symfile {
  207. my ($self, $src, $objid) = @_;
  208. if (not $self->has_object($objid)) {
  209. $self->{objects}{$objid} = $src->{objects}{$objid};
  210. } else {
  211. warning(_g("Tried to merge the same object (%s) twice in a symfile."), $objid);
  212. }
  213. }
  214. sub save {
  215. my ($self, $file, %opts) = @_;
  216. $file = $self->{file} unless defined($file);
  217. my $fh;
  218. if ($file eq "-") {
  219. $fh = \*STDOUT;
  220. } else {
  221. open($fh, ">", $file)
  222. || syserr(_g("cannot write %s"), $file);
  223. }
  224. $self->dump($fh, %opts);
  225. close($fh) if ($file ne "-");
  226. }
  227. sub dump {
  228. my ($self, $fh, %opts) = @_;
  229. $opts{template_mode} = 0 unless exists $opts{template_mode};
  230. $opts{with_deprecated} = 1 unless exists $opts{with_deprecated};
  231. $opts{with_pattern_matches} = 0 unless exists $opts{with_pattern_matches};
  232. foreach my $soname (sort keys %{$self->{objects}}) {
  233. my @deps = @{$self->{objects}{$soname}{deps}};
  234. my $dep = shift @deps;
  235. $dep =~ s/#PACKAGE#/$opts{package}/g if exists $opts{package};
  236. print $fh "$soname $dep\n";
  237. foreach $dep (@deps) {
  238. $dep =~ s/#PACKAGE#/$opts{package}/g if exists $opts{package};
  239. print $fh "| $dep\n";
  240. }
  241. my $f = $self->{objects}{$soname}{fields};
  242. foreach my $field (sort keys %{$f}) {
  243. my $value = $f->{$field};
  244. $value =~ s/#PACKAGE#/$opts{package}/g if exists $opts{package};
  245. print $fh "* $field: $value\n";
  246. }
  247. my $syms = $self->{objects}{$soname}{syms};
  248. my @symbols;
  249. if ($opts{template_mode}) {
  250. # Exclude symbols matching a pattern, but include patterns themselves
  251. @symbols = grep { not $_->get_pattern() } values %$syms;
  252. push @symbols, $self->get_soname_patterns($soname);
  253. } else {
  254. @symbols = values %$syms;
  255. }
  256. foreach my $sym (sort { $a->get_symboltempl() cmp
  257. $b->get_symboltempl() } @symbols) {
  258. next if $sym->{deprecated} and not $opts{with_deprecated};
  259. # Do not dump symbols from foreign arch unless dumping a template.
  260. next if not $opts{template_mode} and
  261. not $sym->arch_is_concerned($self->{arch});
  262. # Dump symbol specification. Dump symbol tags only in template mode.
  263. print $fh $sym->get_symbolspec($opts{template_mode}), "\n";
  264. # Dump pattern matches as comments (if requested)
  265. if ($opts{with_pattern_matches} && $sym->is_pattern()) {
  266. for my $match (sort { $a->get_symboltempl() cmp
  267. $b->get_symboltempl() } $sym->get_pattern_matches())
  268. {
  269. print $fh "#MATCH:", $match->get_symbolspec(0), "\n";
  270. }
  271. }
  272. }
  273. }
  274. }
  275. # Tries to match a symbol name and/or version against the patterns defined.
  276. # Returns a pattern which matches (if any).
  277. sub find_matching_pattern {
  278. my ($self, $name, $sonames, $inc_deprecated) = @_;
  279. $inc_deprecated = 0 unless defined $inc_deprecated;
  280. my $pattern_ok = sub {
  281. my $p = shift;
  282. return defined $p && ($inc_deprecated || !$p->{deprecated}) &&
  283. $p->arch_is_concerned($self->{arch});
  284. };
  285. foreach my $soname (@$sonames) {
  286. my $obj = (ref $soname) ? $soname : $self->{objects}{$soname};
  287. my ($type, $pattern);
  288. next unless defined $obj;
  289. my $all_aliases = $obj->{patterns}{aliases};
  290. for my $type (Dpkg::Shlibs::Symbol::ALIAS_TYPES) {
  291. if (exists $all_aliases->{$type}) {
  292. my $aliases = $all_aliases->{$type};
  293. if (my $alias = $aliases->{converter}->convert_to_alias($name)) {
  294. if ($alias && exists $aliases->{names}{$alias}) {
  295. $pattern = $aliases->{names}{$alias};
  296. last if &$pattern_ok($pattern);
  297. $pattern = undef; # otherwise not found yet
  298. }
  299. }
  300. }
  301. }
  302. # Now try generic patterns and use the first that matches
  303. if (not defined $pattern) {
  304. for my $p (@{$obj->{patterns}{generic}}) {
  305. if (&$pattern_ok($p) && $p->matches_rawname($name)) {
  306. $pattern = $p;
  307. last;
  308. }
  309. }
  310. }
  311. if (defined $pattern) {
  312. return $pattern;
  313. }
  314. }
  315. return undef;
  316. }
  317. # merge_symbols($object, $minver)
  318. # Needs $Objdump->get_object($soname) as parameter
  319. # Don't merge blacklisted symbols related to the internal (arch-specific)
  320. # machinery
  321. sub merge_symbols {
  322. my ($self, $object, $minver) = @_;
  323. my $soname = $object->{SONAME} || error(_g("Can't merge symbols from objects without SONAME."));
  324. my %dynsyms;
  325. foreach my $sym ($object->get_exported_dynamic_symbols()) {
  326. my $name = $sym->{name} . '@' .
  327. ($sym->{version} ? $sym->{version} : "Base");
  328. my $symobj = $self->lookup_symbol($name, [ $soname ]);
  329. if (exists $blacklist{$sym->{name}}) {
  330. next unless (defined $symobj and $symobj->has_tag("ignore-blacklist"));
  331. }
  332. $dynsyms{$name} = $sym;
  333. }
  334. unless (exists $self->{objects}{$soname}) {
  335. $self->create_object($soname, '');
  336. }
  337. # Scan all symbols provided by the objects
  338. my $obj = $self->{objects}{$soname};
  339. my @obj = ( $obj );
  340. # invalidate the minimum version cache - it is not sufficient to
  341. # invalidate in add_symbol, since we might change a minimum
  342. # version for a particular symbol without adding it
  343. $obj->{minver_cache} = [];
  344. foreach my $name (keys %dynsyms) {
  345. my $sym;
  346. if (exists $obj->{syms}{$name}) {
  347. # If the symbol is already listed in the file
  348. $sym = $obj->{syms}{$name};
  349. $sym->mark_found_in_library($minver, $self->{arch});
  350. } else {
  351. # The exact symbol is not present in the file, but it might match a
  352. # pattern.
  353. my $symobj = $dynsyms{$name};
  354. my $pattern = $self->find_matching_pattern($name, \@obj, 1);
  355. if (defined $pattern) {
  356. $pattern->mark_found_in_library($minver, $self->{arch});
  357. $sym = $pattern->create_pattern_match(symbol => $name);
  358. } else {
  359. # Symbol without any special info as no pattern matched
  360. $sym = Dpkg::Shlibs::Symbol->new(symbol => $name,
  361. minver => $minver);
  362. }
  363. $self->add_symbol($obj, $sym);
  364. }
  365. }
  366. # Process all symbols which could not be found in the library.
  367. foreach my $name (keys %{$self->{objects}{$soname}{syms}}) {
  368. if (not exists $dynsyms{$name}) {
  369. my $sym = $self->{objects}{$soname}{syms}{$name};
  370. $sym->mark_not_found_in_library($minver, $self->{arch});
  371. }
  372. }
  373. # Deprecate patterns which didn't match anything
  374. for my $pattern (grep { $_->get_pattern_matches() == 0 }
  375. $self->get_soname_patterns($soname)) {
  376. $pattern->mark_not_found_in_library($minver, $self->{arch});
  377. }
  378. }
  379. sub is_empty {
  380. my ($self) = @_;
  381. return scalar(keys %{$self->{objects}}) ? 0 : 1;
  382. }
  383. sub has_object {
  384. my ($self, $soname) = @_;
  385. return exists $self->{objects}{$soname};
  386. }
  387. sub create_object {
  388. my ($self, $soname, @deps) = @_;
  389. $self->{objects}{$soname} = {
  390. syms => {},
  391. fields => {},
  392. patterns => {
  393. aliases => {},
  394. generic => [],
  395. },
  396. deps => [ @deps ],
  397. minver_cache => []
  398. };
  399. }
  400. sub get_dependency {
  401. my ($self, $soname, $dep_id) = @_;
  402. $dep_id = 0 unless defined($dep_id);
  403. return $self->{objects}{$soname}{deps}[$dep_id];
  404. }
  405. sub get_smallest_version {
  406. my ($self, $soname, $dep_id) = @_;
  407. $dep_id = 0 unless defined($dep_id);
  408. my $so_object = $self->{objects}{$soname};
  409. return $so_object->{minver_cache}[$dep_id] if(defined($so_object->{minver_cache}[$dep_id]));
  410. my $minver;
  411. foreach my $sym (values %{$so_object->{syms}}) {
  412. next if $dep_id != $sym->{dep_id};
  413. $minver = $sym->{minver} unless defined($minver);
  414. if (version_compare($minver, $sym->{minver}) > 0) {
  415. $minver = $sym->{minver};
  416. }
  417. }
  418. $so_object->{minver_cache}[$dep_id] = $minver;
  419. return $minver;
  420. }
  421. sub get_dependencies {
  422. my ($self, $soname) = @_;
  423. return @{$self->{objects}{$soname}{deps}};
  424. }
  425. sub get_field {
  426. my ($self, $soname, $name) = @_;
  427. if (exists $self->{objects}{$soname}{fields}{$name}) {
  428. return $self->{objects}{$soname}{fields}{$name};
  429. }
  430. return undef;
  431. }
  432. sub lookup_symbol {
  433. my ($self, $name, $sonames, $inc_deprecated) = @_;
  434. $inc_deprecated = 0 unless defined($inc_deprecated);
  435. foreach my $so (@{$sonames}) {
  436. next if (! exists $self->{objects}{$so});
  437. if (exists $self->{objects}{$so}{syms}{$name} and
  438. ($inc_deprecated or not
  439. $self->{objects}{$so}{syms}{$name}{deprecated}))
  440. {
  441. my $dep_id = $self->{objects}{$so}{syms}{$name}{dep_id};
  442. my $clone = $self->{objects}{$so}{syms}{$name}->sclone();
  443. $clone->{depends} = $self->{objects}{$so}{deps}[$dep_id];
  444. $clone->{soname} = $so;
  445. return $clone;
  446. }
  447. }
  448. return undef;
  449. }
  450. # Tries to find a pattern like the $refpat and returns it. If not found, undef
  451. # is returned.
  452. sub lookup_pattern {
  453. my ($self, $refpat, $sonames, $inc_deprecated) = @_;
  454. $inc_deprecated = 0 unless defined($inc_deprecated);
  455. foreach my $soname (@$sonames) {
  456. my $object = (ref $soname) ? $soname : $self->{objects}{$soname};
  457. my $pat;
  458. next unless defined $object;
  459. if (my $type = $refpat->get_alias_type()) {
  460. $pat = $object->{patterns}{aliases}{$type}{names}{$refpat->get_symbolname()};
  461. } elsif ($refpat->get_pattern_type() eq "generic") {
  462. for my $p (@{$object->{patterns}{generic}}) {
  463. if (($inc_deprecated || !$p->{deprecated}) &&
  464. $p->equals($refpat, versioning => 0))
  465. {
  466. $pat = $p;
  467. last;
  468. }
  469. }
  470. }
  471. if ($pat && ($inc_deprecated || !$pat->{deprecated})) {
  472. return $pat;
  473. }
  474. }
  475. return undef;
  476. }
  477. # Collects all patterns of the given soname and returns them as an array.
  478. sub get_soname_patterns {
  479. my ($self, $soname) = @_;
  480. my $object = (ref $soname) ? $soname : $self->{objects}{$soname};
  481. my @aliases;
  482. foreach my $alias (values %{$object->{patterns}{aliases}}) {
  483. push @aliases, values %{$alias->{names}};
  484. }
  485. return (@aliases, @{$object->{patterns}{generic}});
  486. }
  487. sub get_new_symbols {
  488. my ($self, $ref, %opts) = @_;
  489. my $with_optional = (exists $opts{with_optional}) ?
  490. $opts{with_optional} : 0;
  491. my @res;
  492. foreach my $soname (keys %{$self->{objects}}) {
  493. my $mysyms = $self->{objects}{$soname}{syms};
  494. next if not exists $ref->{objects}{$soname};
  495. my $refsyms = $ref->{objects}{$soname}{syms};
  496. my @soname = ( $soname );
  497. # Scan raw symbols first.
  498. foreach my $sym (grep { ($with_optional || ! $_->is_optional())
  499. && $_->is_legitimate($self->{arch}) }
  500. values %$mysyms)
  501. {
  502. my $refsym = $refsyms->{$sym->get_symbolname()};
  503. my $isnew;
  504. if (defined $refsym) {
  505. # If the symbol exists in the $ref symbol file, it might
  506. # still be new if $refsym is not legitimate.
  507. $isnew = not $refsym->is_legitimate($self->{arch});
  508. } else {
  509. # If the symbol does not exist in the $ref symbol file, it does
  510. # not mean that it's new. It might still match a pattern in the
  511. # symbol file. However, due to performance reasons, first check
  512. # if the pattern that the symbol matches (if any) exists in the
  513. # ref symbol file as well.
  514. $isnew = not (
  515. ($sym->get_pattern() and $ref->lookup_pattern($sym->get_pattern(), \@soname, 1)) or
  516. $ref->find_matching_pattern($sym->get_symbolname(), \@soname, 1)
  517. );
  518. }
  519. push @res, $sym->sclone(soname => $soname) if $isnew;
  520. }
  521. # Now scan patterns
  522. foreach my $p (grep { ($with_optional || ! $_->is_optional())
  523. && $_->is_legitimate($self->{arch}) }
  524. $self->get_soname_patterns($soname))
  525. {
  526. my $refpat = $ref->lookup_pattern($p, \@soname, 0);
  527. # If reference pattern was not found or it is not legitimate,
  528. # considering current one as new.
  529. if (not defined $refpat or
  530. not $refpat->is_legitimate($self->{arch}))
  531. {
  532. push @res, $p->sclone(soname => $soname);
  533. }
  534. }
  535. }
  536. return @res;
  537. }
  538. sub get_lost_symbols {
  539. my ($self, $ref, %opts) = @_;
  540. return $ref->get_new_symbols($self, %opts);
  541. }
  542. sub get_new_libs {
  543. my ($self, $ref) = @_;
  544. my @res;
  545. foreach my $soname (keys %{$self->{objects}}) {
  546. push @res, $soname if not exists $ref->{objects}{$soname};
  547. }
  548. return @res;
  549. }
  550. sub get_lost_libs {
  551. my ($self, $ref) = @_;
  552. return $ref->get_new_libs($self);
  553. }
  554. 1;