Bug 1501014 - objdump can not list source code when disassembling code with debug info
Summary: objdump can not list source code when disassembling code with debug info
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: binutils
Version: 26
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Nick Clifton
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-10-12 03:00 UTC by Aaron Lu
Modified: 2017-11-07 22:18 UTC (History)
5 users (show)

Fixed In Version: binutils-2.27-28.fc26
Doc Type: Bug Fix
Doc Text:
Cause: A bug in a previous update to the binutils package meant that it would fail to decode DWARF debug information correctly. Consequence: Tools that attempted to relate locations in binary files to locations in the source code that created them would be told that there was no such relationship. These tools would then provide less information to their users. Fix: Undo the part of the previous update that was broken. Result: Tools like objdump and gprof now correctly relate binary addresses to source code locations.
Clone Of:
Environment:
Last Closed: 2017-11-07 22:18:24 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Aaron Lu 2017-10-12 03:00:24 UTC
Description of problem:
I have built the kernel with debug info, when I:
$ objdump -S -j .text vmlinux

I didn't see source listing mixed with instructions.

I tried objdump from a self built binutils-2.29.1, there is no such problem.

Version-Release number of selected component (if applicable):
binutils-2.27-24.fc26.x86_64

How reproducible:
Always

Steps to Reproduce:
1. build kernel with debug info
2. objdump with -S to disassemble vmlinux with source
3. 

Actual results:
no source code listed with instruction

Expected results:
source code listed with instruction

Additional info:

Comment 1 Nick Clifton 2017-10-12 14:44:20 UTC
Hi Aaron,

Never having built a kernel, with or without debugging, please can you tell how to do this ?

Alternatively, does it have to be the kernel that you disassemble ?  Is the same problem present if you try to disassemble an ordinary program, eg hello world ?

Cheers
  Nick

Comment 2 Aaron Lu 2017-10-13 01:46:10 UTC
Good point Nick, we probably do not need the trouble of building the kernel.

Take the below code as an example:

static int f(int a)
{
        return a*a;
}

int main(void)
{
        return f(5);
}

$ cc -g -o hello hello.c

With objdump shipped with Fedora 26:
$ objdump -S -j .text hello
... ...
0000000000400487 <f>:
static int f(int a)
{
  400487:       55                      push   %rbp
  400488:       48 89 e5                mov    %rsp,%rbp
  40048b:       89 7d fc                mov    %edi,-0x4(%rbp)
        return a*a;
  40048e:       8b 45 fc                mov    -0x4(%rbp),%eax
  400491:       0f af 45 fc             imul   -0x4(%rbp),%eax
}
  400495:       5d                      pop    %rbp
  400496:       c3                      retq   

0000000000400497 <main>:

int main(void)
{
  400497:       55                      push   %rbp
  400498:       48 89 e5                mov    %rsp,%rbp
  40049b:       bf 05 00 00 00          mov    $0x5,%edi
  4004a0:       e8 e2 ff ff ff          callq  400487 <f>
  4004a5:       5d                      pop    %rbp
  4004a6:       c3                      retq   
  4004a7:       66 0f 1f 84 00 00 00    nopw   0x0(%rax,%rax,1)
  4004ae:       00 00 

00000000004004b0 <__libc_csu_init>:
  4004b0:       41 57                   push   %r15
  4004b2:       41 56                   push   %r14
... ...

Note the source that calls to f(5) is missing in main.

As a comparison, with objdump of binutils-2.29.1:
... ...
0000000000400487 <f>:
static int f(int a)
{
  400487:       55                      push   %rbp
  400488:       48 89 e5                mov    %rsp,%rbp
  40048b:       89 7d fc                mov    %edi,-0x4(%rbp)
        return a*a;
  40048e:       8b 45 fc                mov    -0x4(%rbp),%eax
  400491:       0f af 45 fc             imul   -0x4(%rbp),%eax
}
  400495:       5d                      pop    %rbp
  400496:       c3                      retq   

0000000000400497 <main>:

int main(void)
{
  400497:       55                      push   %rbp
  400498:       48 89 e5                mov    %rsp,%rbp
        return f(5);
  40049b:       bf 05 00 00 00          mov    $0x5,%edi
  4004a0:       e8 e2 ff ff ff          callq  400487 <f>
}
  4004a5:       5d                      pop    %rbp
  4004a6:       c3                      retq   
  4004a7:       66 0f 1f 84 00 00 00    nopw   0x0(%rax,%rax,1)
  4004ae:       00 00 

00000000004004b0 <__libc_csu_init>:
  4004b0:       41 57                   push   %r15
  4004b2:       41 56                   push   %r14
... ...

Note there is the 'return f(5);' listed in the disassembly of main.

I'm not entirely sure if this is the same problem as the kernel built since the problem here is less severe in that it at least showed some source for function f(), only missed in main(). While in the disassembly of the kernel's vmlinux image, there are a lot of functions missing source listing entirely.

Comment 3 Aaron Lu 2017-10-13 02:33:01 UTC
BTW, objdump from Fedora 25's binutils-2.26.1-1.fc25.x86_64 shows similar output as binutils-2.29.1.

Comment 4 Nick Clifton 2017-10-13 13:46:39 UTC
Hi Aaron,

Ah this old banana.  Yes, I remember this problem now.  Fortunately there is a fix.  I have imported the patch into the F26 binutils and if you try out binutils-2.27-28.fc26 you should find that it works.

Cheers
  Nick

Comment 5 Aaron Lu 2017-10-15 05:48:32 UTC
Works for me, thanks!

Comment 6 Aaron Lu 2017-11-02 06:01:32 UTC
It's been a while, I wonder when will this be pushed to update?

Comment 7 Fedora Update System 2017-11-02 09:37:28 UTC
binutils-2.27-28.fc26 has been submitted as an update to Fedora 26. https://bodhi.fedoraproject.org/updates/FEDORA-2017-d1f8de129b

Comment 8 Fedora Update System 2017-11-03 14:23:42 UTC
binutils-2.27-28.fc26 has been pushed to the Fedora 26 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2017-d1f8de129b

Comment 9 Fedora Update System 2017-11-07 22:18:24 UTC
binutils-2.27-28.fc26 has been pushed to the Fedora 26 stable repository. If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.