Cmpsymtbl.pl

aus Metalab Wiki, dem offenen Zentrum für meta-disziplinäre Magier und technisch-kreative Enthusiasten.
Version vom 27. Januar 2013, 04:25 Uhr von Vierlex (Diskussion | Beiträge)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Zur Navigation springenZur Suche springen

Script to compare the symbol tables of two objects and show missing symbols from the second. Example execution:

./symbtblcmp.pl objdump tpsession/tpsession-0.1/tpsession/libtpsession.so.0.1.0 \
   ~/nokiaqtsdk/Maemo/4.6.2/targets/fremantle-1030/bin/objdump \
   ~/nokiaqtsdk/Maemo/4.6.2/sysroots/fremantle-arm-sysroot-1030-slim/usr/lib/libtpsession.so.0.1.0

cmpsymtbl.pl

#!/usr/bin/perl

if ($#ARGV < 3) {
    print "USAGE:\n\t$. <objdump1_path> <master_obj> <objdump2_path> <cmp_object>\n\n"
}

my $objdump1 = $ARGV[0];
my $file1 = $ARGV[1];
my $objdump2 = $ARGV[2];
my $file2 = $ARGV[3];

my $matches = 0;
my $missinginfile2 = 0;

my %symtbl2 = ();
foreach my $line (`$objdump2 -t $file2`) {
	if ($line =~ m/^[0-9A-Fa-f]{8}.*\s(\S+)$/) {
		#print ".";
		$symtbl2{"$1"} = 0;
	}
}

my %symtbl1 = ();
my $count = 0;
foreach my $line (`$objdump1 -t $file1`) {
	if ($line =~ m/^[0-9A-Fa-f]{8}.*\s(\S+)$/) {
		if (exists $symtbl1{"$1"}) { next }; # handle duplicate entries
		$symtbl1{"$1"} = 0;
		if (exists $symtbl2{"$1"}) {
			$matches++;
		}
		else {
			$missinginfile2++;
			print "missing $1\n";
		}
	}
}
print "\n";

print `file $file1`;
print `file $file2`, "\n";
print scalar keys %symtbl1, " in $file1\n";
print scalar keys %symtbl2, " in $file2\n";
print "latter missing $missinginfile2 with $matches matching\n";