Source
#!/usr/bin/env perl
# SPDX-License-Identifier: GPL-2.0
#
use ;
use ;
use :: ;
use "SEEK_SET";
die "Format: $0 [-s <systemmap-file>] <vmlinux-file> <keyring-file>\n"
if ($#ARGV != 1 && $#ARGV != 3 ||
$#ARGV == 3 && $ARGV[0] ne "-s");
my $sysmap = "";
if ($#ARGV == 3) {
shift;
$sysmap = $ARGV[0];
shift;
}
my $vmlinux = $ARGV[0];
my $keyring = $ARGV[1];
#
# Parse the vmlinux section table
#
open , "objdump -h $vmlinux |" || die $vmlinux;
my @lines = <>;
close( ) || die $vmlinux;
my @sections = ();
foreach my $line (@lines) {
chomp($line);
if ($line =~ /\s*([0-9]+)\s+(\S+)\s+([0-9a-f]+)\s+([0-9a-f]+)\s+([0-9a-f]+)\s+([0-9a-f]+)\s+2[*][*]([0-9]+)/
) {
my $seg = $1;
my $name = $2;
my $len = ::->new("0x" . $3);
my $vma = ::->new("0x" . $4);
my $lma = ::->new("0x" . $5);
my $foff = ::->new("0x" . $6);
my $align = 2 ** $7;
push @sections, { => $name,
=> $vma,
=> $len,
=> $foff };
}
}
print "Have $#sections sections\n";
#
# Try and parse the vmlinux symbol table. If the vmlinux file has been created
# from a vmlinuz file with extract-vmlinux then the symbol table will be empty.
#
open , "nm $vmlinux 2>/dev/null |" || die $vmlinux;
@lines = <>;
close( ) || die $vmlinux;
my %symbols = ();
my $nr_symbols = 0;