How to extract function caller callee relation from an object file?

Peng Yu pengyu.ut@gmail.com
Sun Mar 21 13:42:23 GMT 2021


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


More information about the Binutils mailing list