#!/usr/bin/perl -w

#
# Use example: cd /opt/OOInstall/program
#              lreloc libsvx680li.so

$opt_plt_too = 0;

sub read_relocs($)
{
    my $file = shift;
    my $pipe;
    my %symbols;
    my %used;

#    print "Read '$file'\n";

    open ($pipe, "readelf -r -W $file |") || die "Can't readelf -r $file: $!";
    while (<$pipe>) {
	/'.rel.plt'/ && !$opt_plt_too && last;
	if (! m/(R_\S+)\s+([0-9a-f]+)\s+(.*)\s*/) {
#	    print "Bin line '$_'\n";
            next;
	}
	my ($type, $loc, $sym) = ($1, $2, $3);
	$symbols{$sym}++;
    }
    close ($pipe);

    return \%symbols;
}

for $lib (@ARGV) {
    my $symbols = read_relocs ($lib);
    print "File: $lib\n";
    for $a (sort keys %$symbols) {
	print $a . "\t" . $symbols->{$a} . "\n";
    }
}
