Bug 629 - Addr2line reports function name that is inconsistent with file/line info
Summary: Addr2line reports function name that is inconsistent with file/line info
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-31 16:51 UTC by Fred Fish
Modified: 2005-01-05 10:42 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Last reconfirmed:


Attachments
Proposed patch to fix the reported problem (1.22 KB, patch)
2004-12-31 16:52 UTC, Fred Fish
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fred Fish 2004-12-31 16:51:17 UTC
Currently addr2line reports inconsistent values for the function name
and file+line info for inlined functions.  For example, consider:

  int add2 (int a, int b)
  {
    return (a + b);
  }

  inline int add3 (int a, int b, int c)
  {
    return (a + add2 (b , c));
  }

  main ()
  {
    printf ("%d\n", add3 (2, 3, 4));
  }

Run:

  /usr/bin/gcc -g -O2 -o t t.c
  /usr/bin/readelf --debug-dump t >t.dwarf
  /usr/bin/objdump --disassemble t >t.dis

Examine the t.dwarf file to ensure that you have a dwarf entry that
looks something like:

 <2><ec>: Abbrev Number: 13 (DW_TAG_inlined_subroutine)
     DW_AT_abstract_origin: <5f>
     DW_AT_low_pc      : 0x8048398
     DW_AT_high_pc     : 0x80483a4

The generated code for my test run, with the inlined subroutine
marked with '***' is:

        0804838c <main>:
         804838c:       55                      push   %ebp
         804838d:       89 e5                   mov    %esp,%ebp
         804838f:       83 ec 08                sub    $0x8,%esp
         8048392:       83 e4 f0                and    $0xfffffff0,%esp
         8048395:       83 ec 10                sub    $0x10,%esp
  ***    8048398:       6a 04                   push   $0x4
  ***    804839a:       6a 03                   push   $0x3
  ***    804839c:       e8 c7 ff ff ff          call   8048368 <add2>
  ***    80483a1:       83 c0 02                add    $0x2,%eax
         80483a4:       50                      push   %eax
         80483a5:       68 94 84 04 08          push   $0x8048494
         80483aa:       e8 01 ff ff ff          call   80482b0 <printf@plt>
         80483af:       c9                      leave
         80483b0:       c3                      ret

With an unpatched addr2line you get:

  $ /usr/bin/addr2line -f -e t 8048398
  main
  /build/sourceware/binutils/i686-pc-linux-gnu/binutils/gcc-3.4.2-6.fc3/t.c:8

I have a patch that fixes this and will try to attach it to the bug report.
With this patch I get:

  $ addr2line -f -e t 8048398
  add3
  /build/sourceware/binutils/i686-pc-linux-gnu/binutils/gcc-3.4.2-6.fc3/t.c:8
Comment 1 Fred Fish 2004-12-31 16:52:38 UTC
Created attachment 330 [details]
Proposed patch to fix the reported problem
Comment 2 Nick Clifton 2005-01-04 15:53:03 UTC
Hi Fred,

  This patch is fine - please apply it and close the PR.  

  In fact if you can think of a way to add this test case to the binutils
testsuite that would be even better.

Cheers
  Nick
Comment 3 Fred Fish 2005-01-05 10:42:28 UTC
Patch approved and applied.