public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
From: Christian Weiss <Christian.Weiss@EMEA.NEC.COM>
To: "libc-help@sourceware.org" <libc-help@sourceware.org>
Cc: Felix Uhl <Felix.Uhl@EMEA.NEC.COM>
Subject: call_site address of __cyg_profile_func
Date: Tue, 30 Nov 2021 07:16:51 +0000	[thread overview]
Message-ID: <f850c8fa6f8e4d958029bf8fbe4e8f0e@EUX13SRV2.EU.NEC.COM> (raw)

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


                 reply	other threads:[~2021-11-30  7:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f850c8fa6f8e4d958029bf8fbe4e8f0e@EUX13SRV2.EU.NEC.COM \
    --to=christian.weiss@emea.nec.com \
    --cc=Felix.Uhl@EMEA.NEC.COM \
    --cc=libc-help@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).