public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* call_site address of __cyg_profile_func
@ 2021-11-30  7:16 Christian Weiss
  0 siblings, 0 replies; only message in thread
From: Christian Weiss @ 2021-11-30  7:16 UTC (permalink / raw)
  To: libc-help; +Cc: Felix Uhl

Dear all,

I have a problem understanding the second argument (call_site) of __cyg_profile_func_enter and __cyg_profile_func_exit. (https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Instrumentation-Options.html#Instrumentation-Options)

I have the following test program:

void foo3() {
}
void foo4() {
}
int main (int argc, char *argv[]) {
  foo1();
  foo2();
}
which is compiled with gcc 9.2.0 using the options -static -finstrument-functions -fno-inline-functions. The binary is linked against an external library which prints out the arguments of the function hooks.
Disassembling the binary with objdump -d reveals this part where the functions are called:

  402542:       b8 00 00 00 00          mov    $0x0,%eax
  402547:       e8 31 ff ff ff          callq  40247d <foo1>
  40254c:       b8 00 00 00 00          mov    $0x0,%eax
  402551:       e8 50 ff ff ff          callq  4024a6 <foo2>
  402556:       bb 00 00 00 00          mov    $0x0,%ebx
The debug output in the function hooks yields (disregarding the entry of main)

ENTER: 0x40247d @ 0x40254c
ENTER: 0x4024a6 @ 0x402556

The first argument matches the symbol address as can be seen from the callq argument. However, the second argument matches the lines after the call of foo1 or foo2. I can see in the disassembly of e.g. foo1 that this because of the offset 0x8 in the argument register:

  402481:       48 8b 45 08             mov    0x8(%rbp),%rax
  402485:       48 89 c6                mov    %rax,%rsi
  402488:       bf 7d 24 40 00          mov    $0x40247d,%edi
  40248d:       e8 4e 0a 00 00          callq  402ee0 <__cyg_profile_func_enter>

I wonder why this is the case. What is the reason for using this offset?
Especially, I want to match the addresses in the DWARF debug section of the binary to the function calls. There, the line number is increased for the addresses before the callq statement. This way, the DWARF addresses are shifted wrt. the call sites.

Best regards,
Christian


Dr. Christian Weiss
Benchmark Analyst
Tel: +49 211 5369 126

NEC Deutschland GmbH
Geschäftsführer  Yuichi Kojima
Handelsregister Düsseldorf HRB 57941; VAT ID DE129424743


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-30  7:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-30  7:16 call_site address of __cyg_profile_func Christian Weiss

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).