fix regression from a745c4bfc8a9b5db4e48387170da0dc1d39e3abe
[uclibc-ng.git] / extra / scripts / relinfo.pl
blobcb990b36fdd5205d6cef1e6d882ecd7d3b636f89
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.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License version 2 as
9 # published by the Free Software Foundation.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, see <http://www.gnu.org/licenses/>.
19 for ($cnt = 0; $cnt <= $#ARGV; ++$cnt) {
20 $relent = 0;
21 $relsz = 0;
22 $relcount = 0;
23 $pltrelsz = 0;
24 $extplt = 0;
25 $users = 0;
27 open (READLINK, "readlink -f $ARGV[$cnt] |") || die "cannot open readlink";
28 while (<READLINK>) {
29 chop;
30 $fullpath = $_;
32 close (READLINK);
34 open (READELF, "eu-readelf -d $ARGV[$cnt] |") || die "cannot open $ARGV[$cnt]";
35 while (<READELF>) {
36 chop;
37 if (/.* RELA?ENT *([0-9]*).*/) {
38 $relent = $1 + 0;
39 } elsif (/.* RELA?SZ *([0-9]*).*/) {
40 $relsz = $1 + 0;
41 } elsif (/.* RELA?COUNT *([0-9]*).*/) {
42 $relcount = $1 + 0;
43 } elsif (/.* PLTRELSZ *([0-9]*).*/) {
44 $pltrelsz = $1 + 0;
47 close (READELF);
49 open (READELF, "eu-readelf -r $ARGV[$cnt] | sed '/'.gnu.conflict'/,/^\$/d' |") || die "cannot open $ARGV[$cnt]";
50 while (<READELF>) {
51 chop;
52 if (/.*JU?MP_SLOT *0+ .*/) {
53 ++$extplt;
56 close (READELF);
58 if (open (PRELINK, "/usr/sbin/prelink -p 2>/dev/null | fgrep \"$fullpath\" |")) {
59 while (<PRELINK>) {
60 ++$users;
62 close(PRELINK);
63 } else {
64 $users = -1;
67 printf ("%s: %d relocations, %d relative (%d%%), %d PLT entries, %d for local syms (%d%%)",
68 $ARGV[$cnt], $relent == 0 ? 0 : $relsz / $relent, $relcount,
69 $relent == 0 ? 0 : ($relcount * 100) / ($relsz / $relent),
70 $relent == 0 ? 0 : $pltrelsz / $relent,
71 $relent == 0 ? 0 : $pltrelsz / $relent - $extplt,
72 $relent == 0 ? 0 : (($pltrelsz / $relent - $extplt) * 100) / ($pltrelsz / $relent));
73 if ($users >= 0) {
74 printf(", %d users", $users);
76 printf("\n");