Icarus Sparry wrote:
> On Wed, 29 Mar 2006 02:57:46 -0800, jeniffer wrote:
> > $ cat a.c
> > #include<stdio.h>
> > static void abc()
> > {
> > printf("hi");
> > }
> > extern void pqr()
> > {
> > printf("hello");
> > }
> > void f_called()
> > {
> > printf("df");
> > }
> > void f_not_called()
> > {
> > printf("\nnt");
> > }
> > void Func_calling_static()
> > {
> > abc();
> > }
> > int main()
> > {
> > abc();
> > pqr();
> > f_called();
> > return 0;
> > }
> > -------------
> > $ objdump -r a.o
> > a.o: file format elf32-i386
> > RELOCATION RECORDS FOR [.text]:
> > OFFSET TYPE VALUE
> > 0000000a R_386_32 .rodata
> > 0000000f R_386_PC32 printf
> > 00000022 R_386_32 .rodata
> > 00000027 R_386_PC32 printf
> > 0000003a R_386_32 .rodata
> > 0000003f R_386_PC32 printf
> > 00000052 R_386_32 .rodata
> > 00000057 R_386_PC32 printf
> > 0000008f R_386_PC32 pqr
> > 00000094 R_386_PC32 f_called
> > abc() being a static function is not included in the ouptut of objdump
> > ...I need to find out all the functions that are called..included static
> > ones..Is there any way?
> What you are asking for when you use 'objdump -r' is the relocation
> information. This has almost nothing to do with function calls. It is just
> that a function call to an external function will require the "call"
> instruction to be adjusted at link time (either the explicit link step or
> the runtime linker) and so has a relocation element associated with it.
> When you call a function in the same file you *may* be able to do the call
> as a program counter relative call, and if so you will not need a
> relocation record.
> It is also possible that the compiler has just automatically inlined your
> function so it no longer exists. If a function is "static" and only used
> in one place then this is a sensible thing for it to do, it will never be
> slower or bigger, and usually will be smaller and faster.
> objdump -r is the wrong tool for this job.
> I have already suggested that you look at 'cflow', which is a lot closer
> to doing what you want.
> If you want to pursue using 'objdump, then "objdump -d" or "objdump -t" is
> a better choice.
Thanks i understood that.
nm tool with the -r option gives functions that are defined in that
file or defined in the library/external file [ if we grep T,t,U ]....Is
is an appropriate method or has some problem?
my aim :From a set of .o files I need to find out those functions that
are
defined but not called from anywhere. I had firstly use nm tool (-r
option)
to get all functions [T,t,U] ,then used objdump -r (this was wrong) to
get all functions that are called so as to get required functions .
cflow is not working in the environment i work and I am not
understanding how will objdump - t or objdump -d help me to get the
required functions:-
$ objdump -t a.o|more
a.o: file format elf32-i386
SYMBOL TABLE:
00000000 l df *ABS* 00000000 a.c
00000000 l d .text 00000000
00000000 l d .data 00000000
00000000 l d .bss 00000000
00000000 l d .rodata 00000000
00000000 l F .text 00000018 abc
00000000 l d .note.GNU-stack 00000000
00000000 l d .comment 00000000
00000000 *UND* 00000000 printf
00000018 g F .text 00000018 pqr
00000030 g F .text 00000018 f_called
00000048 g F .text 00000018 f_not_called
00000060 g F .text 0000000d Func_calling_static
0000006d g F .text 00000026 main
-----------
objdump -d a.o :-
a.o: file format elf32-i386
Disassembly of section .text:
00000000 <abc>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 ec 08 sub $0x8,%esp
6: 83 ec 0c sub $0xc,%esp
9: 68 00 00 00 00 push $0x0
e: e8 fc ff ff ff call f <abc+0xf>
13: 83 c4 10 add $0x10,%esp
16: c9 leave
17: c3 ret
00000018 <pqr>:
18: 55 push %ebp
19: 89 e5 mov %esp,%ebp
1b: 83 ec 08 sub $0x8,%esp
1e: 83 ec 0c sub $0xc,%esp
21: 68 03 00 00 00 push $0x3
26: e8 fc ff ff ff call 27 <pqr+0xf>
2b: 83 c4 10 add $0x10,%esp
2e: c9 leave
2f: c3 ret
00000030 <f_called>:
30: 55 push %ebp
31: 89 e5 mov %esp,%ebp
33: 83 ec 08 sub $0x8,%esp
36: 83 ec 0c sub $0xc,%esp
39: 68 09 00 00 00 push $0x9
3e: e8 fc ff ff ff call 3f <f_called+0xf>
43: 83 c4 10 add $0x10,%esp
46: c9 leave
47: c3 ret
00000048 <f_not_called>:
48: 55 push %ebp
49: 89 e5 mov %esp,%ebp
4b: 83 ec 08 sub $0x8,%esp
4e: 83 ec 0c sub $0xc,%esp
51: 68 0c 00 00 00 push $0xc
56: e8 fc ff ff ff call 57 <f_not_called+0xf>
5b: 83 c4 10 add $0x10,%esp
5e: c9 leave
5f: c3 ret
00000060 <Func_calling_static>:
60: 55 push %ebp
61: 89 e5 mov %esp,%ebp
63: 83 ec 08 sub $0x8,%esp
66: e8 95 ff ff ff call 0 <abc>
6b: c9 leave
6c: c3 ret
0000006d <main>:
6d: 55 push %ebp
6e: 89 e5 mov %esp,%ebp
70: 83 ec 08 sub $0x8,%esp
73: 83 e4 f0 and $0xfffffff0,%esp
76: b8 00 00 00 00 mov $0x0,%eax
7b: 29 c4 sub %eax,%esp
7d: e8 7e ff ff ff call 0 <abc>
82: e8 fc ff ff ff call 83 <main+0x16>
87: e8 fc ff ff ff call 88 <main+0x1b>
8c: b8 00 00 00 00 mov $0x0,%eax
91: c9 leave
92: c3 ret