public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* How to extract function caller callee relation from an object file?
@ 2021-03-21 13:42 Peng Yu
  2021-03-26 16:13 ` Nick Clifton
  2021-03-26 16:15 ` Andreas Schwab
  0 siblings, 2 replies; 4+ messages in thread
From: Peng Yu @ 2021-03-21 13:42 UTC (permalink / raw)
  To: binutils

Hi,

I want to extract function caller and function callee relation. In the
following case, it should be

print -> print2

System functions like puts() are ignored. One way is to extract the
info from the disassembled code. But is there a better way to do so?

Also, I don't quite understand "   b:	e8 00 00 00 00       	callq  10
<print+0x10>". Why I don't see a call to `puts()`? Thanks.

$ cat print.c
#include <stdio.h>

void print() {
  puts("Hello World!\n");
}

void print2() {
  print();
}
$ gcc -c -o print.o print.c
$ objdump -d print.o

print.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <print>:
   0:	55                   	push   %rbp
   1:	48 89 e5             	mov    %rsp,%rbp
   4:	48 8d 3d 00 00 00 00 	lea    0x0(%rip),%rdi        # b <print+0xb>
   b:	e8 00 00 00 00       	callq  10 <print+0x10>
  10:	90                   	nop
  11:	5d                   	pop    %rbp
  12:	c3                   	retq

0000000000000013 <print2>:
  13:	55                   	push   %rbp
  14:	48 89 e5             	mov    %rsp,%rbp
  17:	b8 00 00 00 00       	mov    $0x0,%eax
  1c:	e8 00 00 00 00       	callq  21 <print2+0xe>
  21:	90                   	nop
  22:	5d                   	pop    %rbp
  23:	c3                   	retq

-- 
Regards,
Peng

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to extract function caller callee relation from an object file?
  2021-03-21 13:42 How to extract function caller callee relation from an object file? Peng Yu
@ 2021-03-26 16:13 ` Nick Clifton
  2021-03-26 16:22   ` Orlando Arias
  2021-03-26 16:15 ` Andreas Schwab
  1 sibling, 1 reply; 4+ messages in thread
From: Nick Clifton @ 2021-03-26 16:13 UTC (permalink / raw)
  To: Peng Yu, binutils

Hi Peng,

> I want to extract function caller and function callee relation. In the
> following case, it should be
> 
> print -> print2

Probably the best way to do this is to enable profiling when you compile
the code, and then examine the profile information after the program is run.

  
> Also, I don't quite understand "   b:	e8 00 00 00 00       	callq  10
> <print+0x10>". Why I don't see a call to `puts()`? Thanks.

The compiler has probably replaced the call to puts() with a call to printf() instead.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to extract function caller callee relation from an object file?
  2021-03-21 13:42 How to extract function caller callee relation from an object file? Peng Yu
  2021-03-26 16:13 ` Nick Clifton
@ 2021-03-26 16:15 ` Andreas Schwab
  1 sibling, 0 replies; 4+ messages in thread
From: Andreas Schwab @ 2021-03-26 16:15 UTC (permalink / raw)
  To: Peng Yu via Binutils

On Mär 21 2021, Peng Yu via Binutils wrote:

> Also, I don't quite understand "   b:	e8 00 00 00 00       	callq  10
> <print+0x10>". Why I don't see a call to `puts()`? Thanks.

You need to look at the relocations.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to extract function caller callee relation from an object file?
  2021-03-26 16:13 ` Nick Clifton
@ 2021-03-26 16:22   ` Orlando Arias
  0 siblings, 0 replies; 4+ messages in thread
From: Orlando Arias @ 2021-03-26 16:22 UTC (permalink / raw)
  To: binutils


[-- Attachment #1.1: Type: text/plain, Size: 708 bytes --]

Greetings,

On 3/26/21 12:13 PM, Nick Clifton via Binutils wrote:
>> Also, I don't quite understand "   b:    e8 00 00 00 00          
>> callq  10
>> <print+0x10>". Why I don't see a call to `puts()`? Thanks.
> 
> The compiler has probably replaced the call to puts() with a call to
> printf() instead.


Not quite. We are dealing with an object file here. At this point,
[link-time] addresses have not been resolved, so we are given a call
instruction with an `empty' predicate. When the linker runs, generating
the final executable, the proper address will be placed in there. This
is what we are seeing in both print() and print2() functions.


Cheers,
Orlando.




[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-26 16:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-21 13:42 How to extract function caller callee relation from an object file? Peng Yu
2021-03-26 16:13 ` Nick Clifton
2021-03-26 16:22   ` Orlando Arias
2021-03-26 16:15 ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).