200_Dpkg_Shlibs.t 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. # -*- mode: cperl;-*-
  2. use Test::More tests => 61;
  3. use IO::String;
  4. use strict;
  5. use warnings;
  6. use_ok('Dpkg::Shlibs');
  7. my @tmp;
  8. my @save_paths = @Dpkg::Shlibs::librarypaths;
  9. @Dpkg::Shlibs::librarypaths = ();
  10. my $srcdir = $ENV{srcdir} || '.';
  11. $srcdir .= '/t/200_Dpkg_Shlibs';
  12. Dpkg::Shlibs::parse_ldso_conf("t.tmp/ld.so.conf");
  13. use Data::Dumper;
  14. is_deeply([qw(/nonexistant32 /nonexistant/lib64
  15. /usr/local/lib /nonexistant/lib128 )],
  16. \@Dpkg::Shlibs::librarypaths, "parsed library paths");
  17. use_ok('Dpkg::Shlibs::Objdump');
  18. my $obj = Dpkg::Shlibs::Objdump::Object->new;
  19. open my $objdump, '<', "$srcdir/objdump.dbd-pg"
  20. or die "$srcdir/objdump.dbd-pg: $!";
  21. $obj->_parse($objdump);
  22. close $objdump;
  23. ok(!$obj->is_public_library(), 'Pg.so is not a public library');
  24. ok(!$obj->is_executable(), 'Pg.so is not an executable');
  25. open $objdump, '<', "$srcdir/objdump.ls"
  26. or die "$srcdir/objdump.ls: $!";
  27. $obj->reset();
  28. $obj->_parse($objdump);
  29. close $objdump;
  30. ok(!$obj->is_public_library(), 'ls is not a public library');
  31. ok($obj->is_executable(), 'ls is an executable');
  32. my $sym = $obj->get_symbol('optarg@GLIBC_2.0');
  33. ok($sym, 'optarg@GLIBC_2.0 exists');
  34. ok(!$sym->{'defined'}, 'R_*_COPY relocations are taken into account');
  35. # Non-regression test for #506139
  36. $sym = $obj->get_symbol('singlespace');
  37. ok($sym, 'version less symbol separated by a single space are correctly parsed');
  38. open $objdump, '<', "$srcdir/objdump.libc6-2.6"
  39. or die "$srcdir/objdump.libc6-2.6: $!";
  40. $obj->reset();
  41. $obj->_parse($objdump);
  42. close $objdump;
  43. ok($obj->is_public_library(), 'libc6 is a public library');
  44. ok(!$obj->is_executable(), 'libc6 is not an executable');
  45. is($obj->{SONAME}, 'libc.so.6', 'SONAME');
  46. is($obj->{HASH}, '0x13d99c', 'HASH');
  47. is($obj->{GNU_HASH}, '0x194', 'GNU_HASH');
  48. is($obj->{format}, 'elf32-i386', 'format');
  49. is_deeply($obj->{flags}, { DYNAMIC => 1, HAS_SYMS => 1, D_PAGED => 1 }, 'flags');
  50. is_deeply($obj->{NEEDED}, [ 'ld-linux.so.2' ], 'NEEDED');
  51. is_deeply([ $obj->get_needed_libraries ], [ 'ld-linux.so.2' ], 'NEEDED');
  52. $sym = $obj->get_symbol('_sys_nerr@GLIBC_2.3');
  53. is_deeply( $sym, { name => '_sys_nerr', version => 'GLIBC_2.3',
  54. soname => 'libc.so.6', objid => 'libc.so.6',
  55. section => '.rodata', dynamic => 1,
  56. debug => '', type => 'O', weak => '',
  57. local => '', global => 1, visibility => '',
  58. hidden => 1, defined => 1 }, 'Symbol' );
  59. $sym = $obj->get_symbol('_IO_stdin_used');
  60. is_deeply( $sym, { name => '_IO_stdin_used', version => '',
  61. soname => 'libc.so.6', objid => 'libc.so.6',
  62. section => '*UND*', dynamic => 1,
  63. debug => '', type => ' ', weak => 1,
  64. local => '', global => '', visibility => '',
  65. hidden => '', defined => '' }, 'Symbol 2' );
  66. my @syms = $obj->get_exported_dynamic_symbols;
  67. is( scalar @syms, 2231, 'defined && dynamic' );
  68. @syms = $obj->get_undefined_dynamic_symbols;
  69. is( scalar @syms, 9, 'undefined && dynamic' );
  70. my $obj_old = Dpkg::Shlibs::Objdump::Object->new;
  71. open $objdump, '<', "$srcdir/objdump.libc6-2.3"
  72. or die "$srcdir/objdump.libc6-2.3: $!";
  73. $obj_old->_parse($objdump);
  74. close $objdump;
  75. use_ok('Dpkg::Shlibs::SymbolFile');
  76. use_ok('Dpkg::Shlibs::Symbol');
  77. my $sym_file = Dpkg::Shlibs::SymbolFile->new(file => "$srcdir/symbol_file.tmp");
  78. my $sym_file_dup = Dpkg::Shlibs::SymbolFile->new(file => "$srcdir/symbol_file.tmp");
  79. my $sym_file_old = Dpkg::Shlibs::SymbolFile->new(file => "$srcdir/symbol_file.tmp");
  80. $sym_file->merge_symbols($obj_old, "2.3.6.ds1-13");
  81. $sym_file_old->merge_symbols($obj_old, "2.3.6.ds1-13");
  82. ok( $sym_file->has_object('libc.so.6'), 'SONAME in sym file' );
  83. $sym_file->merge_symbols($obj, "2.6-1");
  84. ok( $sym_file->get_new_symbols($sym_file_old), 'has new symbols' );
  85. ok( $sym_file_old->get_lost_symbols($sym_file), 'has lost symbols' );
  86. is( $sym_file_old->lookup_symbol('__bss_start@Base', ['libc.so.6']),
  87. undef, 'internal symbols are blacklisted');
  88. $sym = $sym_file->lookup_symbol('_errno@GLIBC_2.0', ['libc.so.6'], 1);
  89. isa_ok($sym, 'Dpkg::Shlibs::Symbol');
  90. is_deeply($sym, Dpkg::Shlibs::Symbol->new( 'symbol' => '_errno@GLIBC_2.0',
  91. 'minver' => '2.3.6.ds1-13', 'dep_id' => 0,
  92. 'deprecated' => '2.6-1', 'depends' => '',
  93. 'soname' => 'libc.so.6' ), 'deprecated symbol');
  94. use File::Temp;
  95. my $save_file = new File::Temp;
  96. $sym_file->save($save_file->filename);
  97. $sym_file_dup->load($save_file->filename);
  98. $sym_file_dup->{file} = "$srcdir/symbol_file.tmp";
  99. is_deeply($sym_file_dup, $sym_file, 'save -> load' );
  100. # Test include mechanism of SymbolFile
  101. $sym_file = Dpkg::Shlibs::SymbolFile->new(file => "$srcdir/symbols.include-1");
  102. $sym = $sym_file->lookup_symbol('symbol_before@Base', ['libfake.so.1']);
  103. is_deeply($sym, Dpkg::Shlibs::Symbol->new( 'symbol' => 'symbol_before@Base',
  104. 'minver' => '0.9', 'dep_id' => 0, 'deprecated' => 0,
  105. 'depends' => 'libfake1 #MINVER#', 'soname' => 'libfake.so.1' ),
  106. 'symbol before include not lost');
  107. $sym = $sym_file->lookup_symbol('symbol_after@Base', ['libfake.so.1']);
  108. is_deeply($sym, Dpkg::Shlibs::Symbol->new( 'symbol' => 'symbol_after@Base',
  109. 'minver' => '1.1', 'dep_id' => 0, 'deprecated' => 0,
  110. 'depends' => 'libfake1 #MINVER#', 'soname' => 'libfake.so.1' ),
  111. 'symbol after include not lost');
  112. $sym = $sym_file->lookup_symbol('symbol1_fake1@Base', ['libfake.so.1']);
  113. is_deeply($sym, Dpkg::Shlibs::Symbol->new( 'symbol' => 'symbol1_fake1@Base',
  114. 'minver' => '1.0', 'dep_id' => 0, 'deprecated' => 0,
  115. 'depends' => 'libfake1 #MINVER#', 'soname' => 'libfake.so.1' ),
  116. 'overrides order with #include');
  117. $sym = $sym_file->lookup_symbol('symbol3_fake1@Base', ['libfake.so.1']);
  118. is_deeply($sym, Dpkg::Shlibs::Symbol->new ( 'symbol' => 'symbol3_fake1@Base',
  119. 'minver' => '0', 'dep_id' => 0, 'deprecated' => 0,
  120. 'depends' => 'libfake1 #MINVER#', 'soname' => 'libfake.so.1' ),
  121. 'overrides order with #include');
  122. is($sym_file->get_smallest_version('libfake.so.1'), "0",
  123. 'get_smallest_version with null version');
  124. $sym_file = Dpkg::Shlibs::SymbolFile->new(file => "$srcdir/symbols.include-2");
  125. $sym = $sym_file->lookup_symbol('symbol1_fake2@Base', ['libfake.so.1']);
  126. is_deeply($sym, Dpkg::Shlibs::Symbol->new ( 'symbol' => 'symbol1_fake2@Base',
  127. 'minver' => '1.0', 'dep_id' => 1, 'deprecated' => 0,
  128. 'depends' => 'libvirtualfake', 'soname' => 'libfake.so.1' ),
  129. 'overrides order with circular #include');
  130. is($sym_file->get_smallest_version('libfake.so.1'), "1.0",
  131. 'get_smallest_version');
  132. # Check dump output
  133. my $io = IO::String->new();
  134. $sym_file->dump($io, package => "libfake1");
  135. is(${$io->string_ref()},
  136. 'libfake.so.1 libfake1 #MINVER#
  137. | libvirtualfake
  138. * Build-Depends-Package: libfake-dev
  139. symbol1_fake2@Base 1.0 1
  140. symbol2_fake2@Base 1.0
  141. symbol3_fake2@Base 1.1
  142. ', "Dump of $srcdir/symbols.include-2");
  143. # Check parsing of objdump output on ia64 (local symbols
  144. # without versions and with visibility attribute)
  145. $obj = Dpkg::Shlibs::Objdump::Object->new;
  146. open $objdump, '<', "$srcdir/objdump.glib-ia64"
  147. or die "$srcdir/objdump.glib-ia64: $!";
  148. $obj->_parse($objdump);
  149. close $objdump;
  150. $sym = $obj->get_symbol('IA__g_free');
  151. is_deeply( $sym, { name => 'IA__g_free', version => '',
  152. soname => 'libglib-2.0.so.0', objid => 'libglib-2.0.so.0',
  153. section => '.text', dynamic => 1,
  154. debug => '', type => 'F', weak => '',
  155. local => 1, global => '', visibility => 'hidden',
  156. hidden => '', defined => 1 },
  157. 'symbol with visibility without version' );
  158. ####### Test symbol tagging support ######
  159. # Parsing/dumping
  160. # Template mode
  161. $sym_file = Dpkg::Shlibs::SymbolFile->new(file => "$srcdir/symbols.tags.in", arch => 'amd64');
  162. $sym_file->save($save_file->filename, template_mode => 1);
  163. $sym_file_dup = Dpkg::Shlibs::SymbolFile->new(file => $save_file, arch => 'amd64');
  164. $sym_file_dup->{file} = "$srcdir/symbols.tags.in";
  165. is_deeply($sym_file_dup, $sym_file, 'template save -> load' );
  166. is( system("diff -u '$srcdir/symbols.tags.in' '" . $save_file->filename . "' >&2"), 0, "symbols.tags.in template dumped identical" );
  167. # Dumping in non-template mode (amd64) (test for arch, subst tags)
  168. $io = IO::String->new();
  169. $sym_file->dump($io);
  170. is(${$io->string_ref()},
  171. 'libsymboltags.so.1 libsymboltags1 #MINVER#
  172. | libsymboltags1 (>= 1.1)
  173. symbol11_optional@Base 1.1 1
  174. symbol21_amd64@Base 2.1
  175. symbol31_randomtag@Base 3.1
  176. symbol51_untagged@Base 5.1
  177. ', "template vs. non-template on amd64" );
  178. # Dumping in non-template mode (i386) (test for arch, subst tags)
  179. $io = IO::String->new();
  180. $sym_file = Dpkg::Shlibs::SymbolFile->new(file => "$srcdir/symbols.tags.in", arch => 'i386');
  181. $sym_file_dup = Dpkg::Shlibs::SymbolFile->new(file => "$srcdir/symbols.tags.in", arch => 'i386');
  182. $sym_file->dump($io);
  183. is(${$io->string_ref()},
  184. 'libsymboltags.so.1 libsymboltags1 #MINVER#
  185. | libsymboltags1 (>= 1.1)
  186. symbol11_optional@Base 1.1 1
  187. symbol22_i386@Base 2.2
  188. symbol31_randomtag@Base 3.1
  189. symbol41_i386_and_optional@Base 4.1
  190. symbol51_untagged@Base 5.1
  191. ', "template vs. non-template on i386" );
  192. ok (defined $sym_file->{objects}{'libsymboltags.so.1'}{syms}{'symbol21_amd64@Base'},
  193. "syms keys are symbol names without quotes");
  194. # Preload objdumps
  195. my $tags_obj_i386 = Dpkg::Shlibs::Objdump::Object->new();
  196. open $objdump, '<', "$srcdir/objdump.tags-i386" or die "$srcdir/objdump.tags-i386: $!";
  197. $tags_obj_i386->_parse($objdump);
  198. close $objdump;
  199. $sym_file->merge_symbols($tags_obj_i386, '100.MISSING');
  200. is_deeply($sym_file, $sym_file_dup, "is objdump.tags-i386 and symbols.tags.in in sync");
  201. my $tags_obj_amd64 = Dpkg::Shlibs::Objdump::Object->new();
  202. open $objdump, '<', "$srcdir/objdump.tags-amd64" or die "$srcdir/objdump.tags-amd64: $!";
  203. $tags_obj_amd64->_parse($objdump);
  204. close $objdump;
  205. # Merge/get_{new,lost} tests for optional tag:
  206. # - disappeared
  207. my $symbol11 = $tags_obj_i386->get_symbol('symbol11_optional@Base');
  208. delete $tags_obj_i386->{dynsyms}{'symbol11_optional@Base'};
  209. $sym_file->merge_symbols($tags_obj_i386, '100.MISSING');
  210. $sym = $sym_file->lookup_symbol('symbol11_optional@Base', ['libsymboltags.so.1'], 1);
  211. is_deeply($sym, Dpkg::Shlibs::Symbol->new( 'symbol' => 'symbol11_optional@Base', 'symbol_templ' => 'symbol11_optional@Base',
  212. 'minver' => '1.1', 'dep_id' => 1, 'deprecated' => '100.MISSING',
  213. 'depends' => 'libsymboltags1 (>= 1.1)', 'soname' => 'libsymboltags.so.1',
  214. 'tags' => { 'optional' => undef }, 'tagorder' => [ 'optional' ] ),
  215. 'disappered optional symbol gets deprecated');
  216. $sym_file->merge_symbols($tags_obj_i386, '101.MISSING');
  217. $sym = $sym_file->lookup_symbol('symbol11_optional@Base', ['libsymboltags.so.1'], 1);
  218. is_deeply($sym, Dpkg::Shlibs::Symbol->new( 'symbol' => 'symbol11_optional@Base', 'symbol_templ' => 'symbol11_optional@Base',
  219. 'minver' => '1.1', 'dep_id' => 1, 'deprecated' => '101.MISSING',
  220. 'depends' => 'libsymboltags1 (>= 1.1)', 'soname' => 'libsymboltags.so.1',
  221. 'tags' => { 'optional' => undef }, 'tagorder' => [ 'optional' ] ),
  222. 'deprecated text of MISSING optional symbol gets rebumped each merge');
  223. is( scalar($sym_file->get_lost_symbols($sym_file_dup)), 0, "missing optional symbol is not LOST");
  224. # - reappeared (undeprecate, minver should be 1.1, not 100.MISSED)
  225. $tags_obj_i386->add_dynamic_symbol($symbol11);
  226. $sym_file->merge_symbols($tags_obj_i386, '100.MISSING');
  227. $sym = $sym_file->lookup_symbol('symbol11_optional@Base', ['libsymboltags.so.1']);
  228. is_deeply($sym, Dpkg::Shlibs::Symbol->new( 'symbol' => 'symbol11_optional@Base', 'symbol_templ' => 'symbol11_optional@Base',
  229. 'minver' => '1.1', 'dep_id' => 1, 'deprecated' => 0,
  230. 'depends' => 'libsymboltags1 (>= 1.1)', 'soname' => 'libsymboltags.so.1',
  231. 'tags' => { 'optional' => undef }, 'tagorder' => [ 'optional' ] ),
  232. 'reappered optional symbol gets undeprecated + minver');
  233. is( scalar($sym_file->get_lost_symbols($sym_file_dup) +
  234. $sym_file->get_new_symbols($sym_file_dup)), 0, "reappeared optional symbol: neither NEW nor LOST");
  235. # Merge/get_{new,lost} tests for arch tag:
  236. # - arch specific appears on wrong arch: 'arch' tag should be removed
  237. my $symbol21 = $tags_obj_amd64->get_symbol('symbol21_amd64@Base');
  238. $tags_obj_i386->add_dynamic_symbol($symbol21);
  239. $sym_file->merge_symbols($tags_obj_i386, '100.MISSING');
  240. $sym = $sym_file->lookup_symbol('symbol21_amd64@Base', ['libsymboltags.so.1']);
  241. is_deeply($sym, Dpkg::Shlibs::Symbol->new( 'symbol' => 'symbol21_amd64@Base', 'symbol_templ' => 'symbol21_amd64@Base',
  242. 'symbol_quoted' => "'", 'minver' => '2.1', 'dep_id' => 0, 'deprecated' => 0,
  243. 'depends' => 'libsymboltags1 #MINVER#', 'soname' => 'libsymboltags.so.1' ),
  244. 'symbol appears on foreign arch, arch tag should be removed');
  245. @tmp = map { $_->get_symbolname() } $sym_file->get_new_symbols($sym_file_dup);
  246. is_deeply( \@tmp, [ 'symbol21_amd64@Base' ], "symbol from foreign arch is NEW");
  247. is( $sym->get_symbolspec(1), ' symbol21_amd64@Base 2.1', 'no tags => no quotes in the symbol name' );
  248. # - arch specific symbol disappears
  249. delete $tags_obj_i386->{dynsyms}{'symbol22_i386@Base'};
  250. delete $tags_obj_i386->{dynsyms}{'symbol41_i386_and_optional@Base'};
  251. $sym_file->merge_symbols($tags_obj_i386, '100.MISSING');
  252. $sym = $sym_file->lookup_symbol('symbol22_i386@Base', ['libsymboltags.so.1'], 1);
  253. is_deeply($sym, Dpkg::Shlibs::Symbol->new( 'symbol' => 'symbol22_i386@Base', 'symbol_templ' => 'symbol22_i386@Base',
  254. 'minver' => '2.2', 'dep_id' => 0, 'deprecated' => '100.MISSING',
  255. 'depends' => 'libsymboltags1 #MINVER#', 'soname' => 'libsymboltags.so.1',
  256. 'tags' => { 'arch' => '!amd64 !ia64 !alpha' }, 'tagorder' => [ 'arch' ] ),
  257. 'disappeared arch specific symbol gets deprecated');
  258. $sym = $sym_file->lookup_symbol('symbol41_i386_and_optional@Base', ['libsymboltags.so.1'], 1);
  259. is_deeply($sym, Dpkg::Shlibs::Symbol->new( 'symbol' => 'symbol41_i386_and_optional@Base',
  260. 'symbol_templ' => 'symbol41_i386_and_optional@Base', 'symbol_quoted' => '"',
  261. 'minver' => '4.1', 'dep_id' => 0, 'deprecated' => '100.MISSING',
  262. 'depends' => 'libsymboltags1 #MINVER#', 'soname' => 'libsymboltags.so.1',
  263. 'tags' => { 'arch' => 'i386', 'optional' => 'reason' }, 'tagorder' => [ 'arch', 'optional' ] ),
  264. 'disappeared optional arch specific symbol gets deprecated');
  265. @tmp = map { $_->get_symbolname() } $sym_file->get_lost_symbols($sym_file_dup);
  266. is_deeply( \@tmp, [ 'symbol22_i386@Base' ], "missing arch specific is LOST, but optional arch specific isn't");
  267. # Tests for tagged #includes
  268. $sym_file = Dpkg::Shlibs::SymbolFile->new(file => "$srcdir/symbols.include-3", arch => 'i386');
  269. $sym = $sym_file->lookup_symbol('symbol2_fake1@Base', ['libsymboltags.so.2']);
  270. is_deeply($sym, Dpkg::Shlibs::Symbol->new( 'symbol' => 'symbol2_fake1@Base',
  271. 'minver' => '1.0', 'depends' => 'libsymboltags2', 'soname' => 'libsymboltags.so.2',
  272. 'tags' => { 'optional' => undef, 'random tag' => 'random value' },
  273. 'tagorder' => [ 'optional', 'random tag' ] ),
  274. 'symbols from #included file inherits tags');
  275. $sym = $sym_file->lookup_symbol('symbol41_i386_and_optional@Base', ['libsymboltags.so.1']);
  276. is_deeply($sym, Dpkg::Shlibs::Symbol->new( 'symbol' => 'symbol41_i386_and_optional@Base',
  277. 'symbol_templ' => 'symbol41_i386_and_optional@Base', symbol_quoted => '"',
  278. 'minver' => '4.1', 'depends' => 'libsymboltags1 #MINVER#', 'soname' => 'libsymboltags.so.1',
  279. 'tags' => { 'optional' => 'reason', 't' => 'v', 'arch' => 'i386' },
  280. 'tagorder' => [ 'optional', 't', 'arch' ] ),
  281. 'symbols in #included file can override tag values');
  282. $sym = $sym_file->lookup_symbol('symbol51_untagged@Base', ['libsymboltags.so.1']);
  283. is_deeply($sym, Dpkg::Shlibs::Symbol->new( 'symbol' => 'symbol51_untagged@Base',
  284. 'minver' => '5.1', 'depends' => 'libsymboltags1 #MINVER#', 'soname' => 'libsymboltags.so.1',
  285. 'tags' => { 'optional' => 'from parent', 't' => 'v' },
  286. 'tagorder' => [ 'optional', 't' ] ),
  287. 'symbols are properly cloned when #including');