relinfo.pl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #! /usr/bin/perl
  2. eval "exec /usr/bin/perl -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, write to the Free Software Foundation,
  17. # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  18. for ($cnt = 0; $cnt <= $#ARGV; ++$cnt) {
  19. $relent = 0;
  20. $relsz = 0;
  21. $relcount = 0;
  22. $pltrelsz = 0;
  23. $extplt = 0;
  24. $users = 0;
  25. open (READLINK, "readlink -f $ARGV[$cnt] |") || die "cannot open readlink";
  26. while (<READLINK>) {
  27. chop;
  28. $fullpath = $_;
  29. }
  30. close (READLINK);
  31. open (READELF, "eu-readelf -d $ARGV[$cnt] |") || die "cannot open $ARGV[$cnt]";
  32. while (<READELF>) {
  33. chop;
  34. if (/.* RELA?ENT *([0-9]*).*/) {
  35. $relent = $1 + 0;
  36. } elsif (/.* RELA?SZ *([0-9]*).*/) {
  37. $relsz = $1 + 0;
  38. } elsif (/.* RELA?COUNT *([0-9]*).*/) {
  39. $relcount = $1 + 0;
  40. } elsif (/.* PLTRELSZ *([0-9]*).*/) {
  41. $pltrelsz = $1 + 0;
  42. }
  43. }
  44. close (READELF);
  45. open (READELF, "eu-readelf -r $ARGV[$cnt] | sed '/'.gnu.conflict'/,/^\$/d' |") || die "cannot open $ARGV[$cnt]";
  46. while (<READELF>) {
  47. chop;
  48. if (/.*JU?MP_SLOT *0+ .*/) {
  49. ++$extplt;
  50. }
  51. }
  52. close (READELF);
  53. if (open (PRELINK, "/usr/sbin/prelink -p 2>/dev/null | fgrep \"$fullpath\" |")) {
  54. while (<PRELINK>) {
  55. ++$users;
  56. }
  57. close(PRELINK);
  58. } else {
  59. $users = -1;
  60. }
  61. printf ("%s: %d relocations, %d relative (%d%%), %d PLT entries, %d for local syms (%d%%)",
  62. $ARGV[$cnt], $relent == 0 ? 0 : $relsz / $relent, $relcount,
  63. $relent == 0 ? 0 : ($relcount * 100) / ($relsz / $relent),
  64. $relent == 0 ? 0 : $pltrelsz / $relent,
  65. $relent == 0 ? 0 : $pltrelsz / $relent - $extplt,
  66. $relent == 0 ? 0 : (($pltrelsz / $relent - $extplt) * 100) / ($pltrelsz / $relent));
  67. if ($users >= 0) {
  68. printf(", %d users", $users);
  69. }
  70. printf("\n");
  71. }