#!/usr/bin/perl use strict; use IO::Seekable; my $littleendian = (unpack("L", pack("N", 0xabcd1234)) != 0xabcd1234); sub add_image_subdir { my $image = shift; if (!($image =~ m/\/img/)) { $image = "./img/".$image }; return $image; } my $image_offset = $ENV{"HAL_IMAGE_OFFSET"}; if (not $image_offset) { $image_offset = "0x0"; }; $image_offset = hex $image_offset; my $image; my $all_modules = 0; my @modules = (); if ($#ARGV == -1) { die "gensyms [modules]\n"; } if ($#ARGV == 0) { $all_modules = 1; } else { @modules = @ARGV[1..$#ARGV]; } $image = add_image_subdir($ARGV[0]); open IMAGE, "< $image"; binmode(IMAGE); my %module_offsets = (); open MODINFO, "< $image.modinfo"; while (my $modline = ) { chomp $modline; my @splitline = split /,/, $modline; $module_offsets{@splitline[0]} = (hex @splitline[1]) + $image_offset; if ($all_modules) { push @modules, @splitline[0]; } } my @output = (); foreach my $module (@modules) { open OBJDUMP, ("ppc64-mcp6-objdump --syms -C ".add_image_subdir($module)."|"); while (my $line = ) { if (($line =~ m/\*ABS\*/) || ($line =~ m/\*UND\*/)) { next; } if ("d" eq substr($line, 22, 1)) { next; } if (!($line =~ m/^[0-9a-f]{16}/)) { next; } $line =~ s/[\s]*$//; my $address = (hex substr($line, 0, 16)) + $module_offsets{$module}; my $is_function = ("F" eq substr($line, 23, 1)); my $size = (hex substr($line, 32, 16)); my $name = substr($line, 48); my $code_loc = 0; if ($is_function) { seek IMAGE, ($address - $image_offset), SEEK_SET; read IMAGE, $code_loc, 8; if ($littleendian) { $code_loc = unpack("Q", reverse($code_loc)) + $image_offset; } else { $code_loc = unpack("Q", $code_loc) + $image_offset; } my $tmp = $code_loc; $code_loc = $address; $address = $tmp; } my $outstring = ""; $outstring = sprintf "%s,%08x,%08x,%08x,%s\n", ($is_function?"F":"V"),$address,$code_loc,$size,$name; push @output, $outstring; } close OBJDUMP; } close IMAGE; foreach my $outstring (sort { substr($a,2) cmp substr($b,2) } @output) { print $outstring; }