Bug 23843 - shouldn't "objdump -e dwarf=links" print multiple entries?
Summary: shouldn't "objdump -e dwarf=links" print multiple entries?
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.32
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-10-29 15:36 UTC by Mitchell Blank Jr
Modified: 2019-02-22 10:40 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2019-02-21 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mitchell Blank Jr 2018-10-29 15:36:51 UTC
When multiple objects that were compiled with "-gsplit-dwarf" are later linked together the resulting ELF binary will have references to multiple *.dwo files, which "objdump --dwarf=info" shows correctly.  However "objdump -dwarf=links" only prints the last(?) one  and silently ignores the rest which seems incorrect to me.

For an example, see the reproduction case attached to the (unrelated) Bug 23842 that I just filed.  After compiling it, you see:

$ ~/git/binutils-gdb/binutils/objdump --dwarf=info exe/exe | egrep 'DW_AT_GNU_dwo_name|DW_AT_comp_dir'
    <20>   DW_AT_GNU_dwo_name: (indirect string, offset: 0x0): exe.dwo
    <24>   DW_AT_comp_dir    : (indirect string, offset: 0x8): /home/mitch/split-dwarf-multidir/exe
    <54>   DW_AT_GNU_dwo_name: (indirect string, offset: 0x53): a.dwo
    <58>   DW_AT_comp_dir    : (indirect string, offset: 0x2d): /home/mitch/split-dwarf-multidir/liba
    <88>   DW_AT_GNU_dwo_name: (indirect string, offset: 0x7f): b.dwo
    <8c>   DW_AT_comp_dir    : (indirect string, offset: 0x59): /home/mitch/split-dwarf-multidir/libb

$ ~/git/binutils-gdb/binutils/objdump --dwarf=links exe/exe

exe/exe:     file format elf64-x86-64

The .debug_info section contains a link to a dwo file:
  Name:      b.dwo
  Directory: /home/mitch/split-dwarf-multidir/libb
  ID:        b3 d9 32 5b a3 75 ed 4d


Forgive me if this is user error; I am new to -gsplit-dwarf.
Comment 1 Nick Clifton 2019-02-21 16:33:13 UTC
(In reply to Mitchell Blank Jr from comment #0)
Hi Mitchell,

>  However "objdump
> -dwarf=links" only prints the last(?) one  and silently ignores the rest
> which seems incorrect to me.

This is definitely a binutils bug - I am investigating...

> Forgive me if this is user error; I am new to -gsplit-dwarf.

So am I.  I was not expecting there to be multiple links in a single file.
Comment 2 Sourceware Commits 2019-02-22 10:37:46 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=24841daa74f092f7c5639ee8f1fb303c7694dee7

commit 24841daa74f092f7c5639ee8f1fb303c7694dee7
Author: Nick Clifton <nickc@redhat.com>
Date:   Fri Feb 22 10:36:24 2019 +0000

    Extend readelf and objdump so that they will display and follow multiple links to separate debug information files.
    
    	PR 23843
    	* dwarf.h (struct separate_info): New structure for containing
    	information on separate debug info files.
    	* dwarf.c (struct dwo_info): New structure for containing dwo
    	links.
    	(first_dwo_info): Chain of dwo_info structures.
    	(first_separate_file): Chain of separate_info structures.
    	(separate_debug_file, separate_debug_filename): Delete.
    	(fetch_alt_indirect_string): Scan all separate debug info files
    	for the requested string.
    	(add_dwo_info): New function.
    	(add_dwo_name): New function.
    	(add_dwo_dir): New function.
    	(add_dwo_id: New function.
    	(free_dwo_info): New function.
    	(read_and_display_attr_value): Store DWO data using the new
    	functions.
    	(load_debug_section_with_follow): If necessary, scan the list of
    	separate debug info files for the requested section.
    	(add_separate_debug_file): New function.
    	(load_separate_debug_info): Call add_separate_debug_file to store
    	the information on the newly loaded file.
    	(load_dwo_file): Likewise.
    	(load_separate_debif_file): Rename to load_separate_debug_files.
    	Change return type to boolean.  If following links then attempt to
    	load all separate debug info files, not just the first one.
    	(free_debug_memory): Release memory in dwo_info and separate_info
    	chains.
    	* objdump.c (dump_dwarf): Iterate over all loaded debg info files.
    	* readelf.c (process_object): Likewise.
    	* doc/debug.options.texi: Update descriptions of links and
    	follow-links options.
    	* testsuite/binutils-all/objdump.WK2: Update expected output.
    	* testsuite/binutils-all/readelf.k2: Likewise.
    	* NEWS: Announce the new feature.
Comment 3 Nick Clifton 2019-02-22 10:40:38 UTC
Hi Mitchell,

  Right - I have now checked in a large patch which should fix this problem.
  It extends both readelf and objdump so that they will display multiple
  separate debug info file links, if multiple entries are present.  The
  patch also updates the follow-links option so that all links will be
  followed, not just the first one.

Cheers
  Nick