200_Dpkg_Shlibs.t 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. # -*- mode: cperl;-*-
  2. use Test::More tests => 36;
  3. use IO::String;
  4. use strict;
  5. use warnings;
  6. use_ok('Dpkg::Shlibs');
  7. my @save_paths = @Dpkg::Shlibs::librarypaths;
  8. @Dpkg::Shlibs::librarypaths = ();
  9. my $srcdir = $ENV{srcdir} || '.';
  10. $srcdir .= '/t/200_Dpkg_Shlibs';
  11. Dpkg::Shlibs::parse_ldso_conf("t.tmp/ld.so.conf");
  12. use Data::Dumper;
  13. is_deeply([qw(/nonexistant32 /nonexistant/lib64
  14. /usr/local/lib /nonexistant/lib128 )],
  15. \@Dpkg::Shlibs::librarypaths, "parsed library paths");
  16. use_ok('Dpkg::Shlibs::Objdump');
  17. my $obj = Dpkg::Shlibs::Objdump::Object->new;
  18. open my $objdump, '<', "$srcdir/objdump.dbd-pg"
  19. or die "$srcdir/objdump.dbd-pg: $!";
  20. $obj->_parse($objdump);
  21. close $objdump;
  22. ok(!$obj->is_public_library(), 'Pg.so is not a public library');
  23. ok(!$obj->is_executable(), 'Pg.so is not an executable');
  24. open $objdump, '<', "$srcdir/objdump.ls"
  25. or die "$srcdir/objdump.ls: $!";
  26. $obj->reset();
  27. $obj->_parse($objdump);
  28. close $objdump;
  29. ok(!$obj->is_public_library(), 'ls is not a public library');
  30. ok($obj->is_executable(), 'ls is an executable');
  31. my $sym = $obj->get_symbol('optarg@GLIBC_2.0');
  32. ok($sym, 'optarg@GLIBC_2.0 exists');
  33. ok(!$sym->{'defined'}, 'R_*_COPY relocations are taken into account');
  34. open $objdump, '<', "$srcdir/objdump.libc6-2.6"
  35. or die "$srcdir/objdump.libc6-2.6: $!";
  36. $obj->reset();
  37. $obj->_parse($objdump);
  38. close $objdump;
  39. ok($obj->is_public_library(), 'libc6 is a public library');
  40. ok(!$obj->is_executable(), 'libc6 is not an executable');
  41. is($obj->{SONAME}, 'libc.so.6', 'SONAME');
  42. is($obj->{HASH}, '0x13d99c', 'HASH');
  43. is($obj->{GNU_HASH}, '0x194', 'GNU_HASH');
  44. is($obj->{format}, 'elf32-i386', 'format');
  45. is_deeply($obj->{flags}, { DYNAMIC => 1, HAS_SYMS => 1, D_PAGED => 1 }, 'flags');
  46. is_deeply($obj->{NEEDED}, [ 'ld-linux.so.2' ], 'NEEDED');
  47. is_deeply([ $obj->get_needed_libraries ], [ 'ld-linux.so.2' ], 'NEEDED');
  48. $sym = $obj->get_symbol('_sys_nerr@GLIBC_2.3');
  49. is_deeply( $sym, { name => '_sys_nerr', version => 'GLIBC_2.3',
  50. soname => 'libc.so.6', section => '.rodata', dynamic => 1,
  51. debug => '', type => 'O', weak => '',
  52. local => '', global => 1, visibility => '',
  53. hidden => 1, defined => 1 }, 'Symbol' );
  54. $sym = $obj->get_symbol('_IO_stdin_used');
  55. is_deeply( $sym, { name => '_IO_stdin_used', version => '',
  56. soname => 'libc.so.6', section => '*UND*', dynamic => 1,
  57. debug => '', type => ' ', weak => 1,
  58. local => '', global => '', visibility => '',
  59. hidden => '', defined => '' }, 'Symbol 2' );
  60. my @syms = $obj->get_exported_dynamic_symbols;
  61. is( scalar @syms, 2231, 'defined && dynamic' );
  62. @syms = $obj->get_undefined_dynamic_symbols;
  63. is( scalar @syms, 9, 'undefined && dynamic' );
  64. my $obj_old = Dpkg::Shlibs::Objdump::Object->new;
  65. open $objdump, '<', "$srcdir/objdump.libc6-2.3"
  66. or die "$srcdir/objdump.libc6-2.3: $!";
  67. $obj_old->_parse($objdump);
  68. close $objdump;
  69. use_ok('Dpkg::Shlibs::SymbolFile');
  70. my $sym_file = Dpkg::Shlibs::SymbolFile->new("$srcdir/symbol_file.tmp");
  71. my $sym_file_dup = Dpkg::Shlibs::SymbolFile->new("$srcdir/symbol_file.tmp");
  72. my $sym_file_old = Dpkg::Shlibs::SymbolFile->new("$srcdir/symbol_file.tmp");
  73. $sym_file->merge_symbols($obj_old, "2.3.6.ds1-13");
  74. $sym_file_old->merge_symbols($obj_old, "2.3.6.ds1-13");
  75. ok( $sym_file->has_object('libc.so.6'), 'SONAME in sym file' );
  76. $sym_file->merge_symbols($obj, "2.6-1");
  77. ok( $sym_file->has_new_symbols($sym_file_old), 'has new symbols' );
  78. ok( $sym_file_old->has_lost_symbols($sym_file), 'has lost symbols' );
  79. is( $sym_file_old->lookup_symbol('__bss_start@Base', ['libc.so.6']),
  80. undef, 'internal symbols are blacklisted');
  81. $sym = $sym_file->lookup_symbol('_errno@GLIBC_2.0', ['libc.so.6'], 1);
  82. is_deeply($sym, { 'minver' => '2.3.6.ds1-13', 'dep_id' => 0,
  83. 'deprecated' => '2.6-1', 'depends' => '',
  84. 'soname' => 'libc.so.6' }, 'deprecated symbol');
  85. use File::Temp;
  86. my $save_file = new File::Temp;
  87. $sym_file->save($save_file->filename);
  88. $sym_file_dup->load($save_file->filename);
  89. $sym_file_dup->{file} = "$srcdir/symbol_file.tmp";
  90. is_deeply($sym_file_dup, $sym_file, 'save -> load' );
  91. # Test include mechanism of SymbolFile
  92. $sym_file = Dpkg::Shlibs::SymbolFile->new("$srcdir/symbols.include-1");
  93. $sym = $sym_file->lookup_symbol('symbol_before@Base', ['libfake.so.1']);
  94. is_deeply($sym, { 'minver' => '0.9', 'dep_id' => 0, 'deprecated' => 0,
  95. 'depends' => 'libfake1 #MINVER#', 'soname' => 'libfake.so.1' },
  96. 'symbol before include not lost');
  97. $sym = $sym_file->lookup_symbol('symbol_after@Base', ['libfake.so.1']);
  98. is_deeply($sym, {'minver' => '1.1', 'dep_id' => 0, 'deprecated' => 0,
  99. 'depends' => 'libfake1 #MINVER#', 'soname' => 'libfake.so.1' },
  100. 'symbol after include not lost');
  101. $sym = $sym_file->lookup_symbol('symbol1_fake1@Base', ['libfake.so.1']);
  102. is_deeply($sym, {'minver' => '1.0', 'dep_id' => 0, 'deprecated' => 0,
  103. 'depends' => 'libfake1 #MINVER#', 'soname' => 'libfake.so.1' },
  104. 'overrides order with #include');
  105. $sym = $sym_file->lookup_symbol('symbol3_fake1@Base', ['libfake.so.1']);
  106. is_deeply($sym, { 'minver' => '1.1', 'dep_id' => 0, 'deprecated' => 0,
  107. 'depends' => 'libfake1 #MINVER#', 'soname' => 'libfake.so.1' },
  108. 'overrides order with #include');
  109. $sym_file = Dpkg::Shlibs::SymbolFile->new("$srcdir/symbols.include-2");
  110. $sym = $sym_file->lookup_symbol('symbol1_fake2@Base', ['libfake.so.1']);
  111. is_deeply($sym, { 'minver' => '1.0', 'dep_id' => 1, 'deprecated' => 0,
  112. 'depends' => 'libvirtualfake', 'soname' => 'libfake.so.1' },
  113. 'overrides order with circular #include');
  114. # Check dump output
  115. my $io = IO::String->new();
  116. $sym_file->dump($io);
  117. is(${$io->string_ref()},
  118. 'libfake.so.1 libfake1 #MINVER#
  119. | libvirtualfake
  120. * Build-Depends-Package: libfake-dev
  121. symbol1_fake2@Base 1.0 1
  122. symbol2_fake2@Base 1.0
  123. symbol3_fake2@Base 1.0
  124. ', "Dump of $srcdir/symbols.include-2");
  125. # Check parsing of objdump output on ia64 (local symbols
  126. # without versions and with visibility attribute)
  127. $obj = Dpkg::Shlibs::Objdump::Object->new;
  128. open $objdump, '<', "$srcdir/objdump.glib-ia64"
  129. or die "$srcdir/objdump.glib-ia64: $!";
  130. $obj->_parse($objdump);
  131. close $objdump;
  132. $sym = $obj->get_symbol('IA__g_free');
  133. is_deeply( $sym, { name => 'IA__g_free', version => '',
  134. soname => 'libglib-2.0.so.0', section => '.text', dynamic => 1,
  135. debug => '', type => 'F', weak => '',
  136. local => 1, global => '', visibility => 'hidden',
  137. hidden => '', defined => 1 },
  138. 'symbol with visibility without version' );