This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Can objdump show friendly symbolic function name?
Hi Maciej
Thanks for the hints.
I have taken some time to write a tiny tool to patch the objdump
outputs since there is no way to display friendly symbolic function
names.
I hope the tool will be useful to somebody else in the future.
================================================
#
# Show friendly symbolic names for PIC ELF.
#
# BY P.R.C <panruochen@gmail.com>
# Jul 15,2010
gawk '
FILENAME==ARGV[1] {
symbols[$1] = $3;
}
FILENAME==ARGV[2]{
if($1=="Local" && $2=="entries:") {
flag = 1
next
} else if($1=="Global" && $2=="entries:") {
flag = 2
next
}
if( $1 ) {
if ( flag == 1 ) {
if ( $3 in symbols )
name = symbols[$3];
else
name = $3
gp_local[$2] = name
} else if( flag == 2 ) {
gp_global[$2] = $7
}
}
}
FILENAME==ARGV[3] {
n = match($0, /[ls]w t9,(.+\(gp\))/, m);
if(n > 0) {
gp = substr($0, m[1,"start"], m[1,"length"]);
if( gp in gp_local )
name = gp_local[gp];
else if ( gp in gp_global )
name = gp_global[gp];
}
if( name != "" )
printf("%s <%s>\n", $0, name)
else
print $0
name = "";
} ' libuClibc.map libuClibc.gp libuClibc.lst
================================================
usage:
$mips-linux-gnu-objdump -d libuClibc.so > libuClibc.lst
$mips-linux-gnu-readelf -A libuClibc.so > libuClibc.gp
$mips-linux-gnu-nm -D libuClibc.so > libuClibc.map
$./pic-elf-objdump.sh
The output is patched as following:
-------------------------------------------------------------------------
000144a4 <regfree>:
144a4: 3c1c0005 lui gp,0x5
144a8: 279c5f4c addiu gp,gp,24396
144ac: 0399e021 addu gp,gp,t9
144b0: 27bdffe0 addiu sp,sp,-32
144b4: afbf001c sw ra,28(sp)
144b8: afb00018 sw s0,24(sp)
144bc: afbc0010 sw gp,16(sp)
144c0: 00808021 move s0,a0
144c4: 8f998814 lw t9,-30700(gp) <free>
144c8: 0320f809 jalr t9
144cc: 8c840000 lw a0,0(a0)
144d0: 8fbc0010 lw gp,16(sp)
144d4: 8e040010 lw a0,16(s0)
144d8: ae000000 sw zero,0(s0)
144dc: 8f998814 lw t9,-30700(gp) <free>
144e0: ae000004 sw zero,4(s0)
144e4: 0320f809 jalr t9
144e8: ae000008 sw zero,8(s0)
144ec: 8fbc0010 lw gp,16(sp)
144f0: 8e02001c lw v0,28(s0)
144f4: 8e040014 lw a0,20(s0)
144f8: 8f998814 lw t9,-30700(gp) <free>
-------------------------------------------------------------------------
>
> ?There's no such problem with non-PIC objects like this one because
> addresses used by call instructions are immediates (or the instructions
> have relocations associated) that can be cross-referred to the symbol
> table.
>
> ?Maciej
>