relinfo.pl 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #! /usr/bin/perl
  2. eval "exec /usr/bin/env perl -w -S $0 $@"
  3. if 0;
  4. # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Red Hat, Inc.
  5. # Written by Ulrich Drepper <drepper@redhat.com>, 2000.
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License version 2 as
  8. # published by the Free Software Foundation.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, see <http://www.gnu.org/licenses/>.
  17. for ($cnt = 0; $cnt <= $#ARGV; ++$cnt) {
  18. $relent = 0;
  19. $relsz = 0;
  20. $relcount = 0;
  21. $pltrelsz = 0;
  22. $extplt = 0;
  23. $users = 0;
  24. open (READLINK, "readlink -f $ARGV[$cnt] |") || die "cannot open readlink";
  25. while (<READLINK>) {
  26. chop;
  27. $fullpath = $_;
  28. }
  29. close (READLINK);
  30. open (READELF, "eu-readelf -d $ARGV[$cnt] |") || die "cannot open $ARGV[$cnt]";
  31. while (<READELF>) {
  32. chop;
  33. if (/.* RELA?ENT *([0-9]*).*/) {
  34. $relent = $1 + 0;
  35. } elsif (/.* RELA?SZ *([0-9]*).*/) {
  36. $relsz = $1 + 0;
  37. } elsif (/.* RELA?COUNT *([0-9]*).*/) {
  38. $relcount = $1 + 0;
  39. } elsif (/.* PLTRELSZ *([0-9]*).*/) {
  40. $pltrelsz = $1 + 0;
  41. }
  42. }
  43. close (READELF);
  44. open (READELF, "eu-readelf -r $ARGV[$cnt] | sed '/'.gnu.conflict'/,/^\$/d' |") || die "cannot open $ARGV[$cnt]";
  45. while (<READELF>) {
  46. chop;
  47. if (/.*JU?MP_SLOT *0+ .*/) {
  48. ++$extplt;
  49. }
  50. }
  51. close (READELF);
  52. if (open (PRELINK, "/usr/sbin/prelink -p 2>/dev/null | fgrep \"$fullpath\" |")) {
  53. while (<PRELINK>) {
  54. ++$users;
  55. }
  56. close(PRELINK);
  57. } else {
  58. $users = -1;
  59. }
  60. printf ("%s: %d relocations, %d relative (%d%%), %d PLT entries, %d for local syms (%d%%)",
  61. $ARGV[$cnt], $relent == 0 ? 0 : $relsz / $relent, $relcount,
  62. $relent == 0 ? 0 : ($relcount * 100) / ($relsz / $relent),
  63. $relent == 0 ? 0 : $pltrelsz / $relent,
  64. $relent == 0 ? 0 : $pltrelsz / $relent - $extplt,
  65. $relent == 0 ? 0 : (($pltrelsz / $relent - $extplt) * 100) / ($pltrelsz / $relent));
  66. if ($users >= 0) {
  67. printf(", %d users", $users);
  68. }
  69. printf("\n");
  70. }