Bug 29442 - objdump: DWARF error: could not find variable specification at offset 0x3d3 with dwz
Summary: objdump: DWARF error: could not find variable specification at offset 0x3d3 w...
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.37
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-08-03 14:32 UTC by Martin Liska
Modified: 2022-08-08 11:53 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Liska 2022-08-03 14:32:28 UTC
The following simple test case fails when dwz is used:

$ cat demo.C
namespace std {
  enum { _S_fixed, _S_floatfield = _S_fixed };
  struct {
    struct {};
  }
  __ioinit;
}

int main() {
  return 0;
}

$ g++ demo.C -g && cp a.out b.out && dwz -m xxx.so a.out b.out && objdump -S a.out >/dev/null
objdump: DWARF error: could not find variable specification at offset 0x3d3

As seen the reference is defined in xxx.so shared part:

$ eu-readelf -w -N a.out | grep -A3 -B3 3d3
             decl_column          (data1) 11
             sibling              (ref_udata) [   387]
 [   387]    variable             abbrev: 30
             specification        (GNU_ref_alt) [   3d3]
             location             (exprloc) 
              [ 0] addr 0x404019
 [   396]    subprogram           abbrev: 32

$ eu-readelf -w -N a.out | less

...

 Compilation unit at offset 920:
 Version: 5, Abbreviation section offset: 0, Address size: 8, Offset size: 4
 Unit type: partial (3)
...
 [   3d3]      variable             abbrev: 31
               name                 (strp) "__ioinit"
               decl_file            (data1) demo.C (10)
               decl_line            (data1) 6
               decl_column          (data1) 3
               type                 (ref_udata) [   3c4]
               declaration          (flag_present) yes
Comment 1 Martin Liska 2022-08-03 14:48:18 UTC
I likely know how to fix it.
Comment 2 Martin Liska 2022-08-08 06:58:59 UTC
Patch has been sent here:
https://sourceware.org/pipermail/binutils/2022-August/122272.html
Comment 3 cvs-commit@gcc.gnu.org 2022-08-08 11:52:33 UTC
The master branch has been updated by Martin Liska <marxin@sourceware.org>:

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

commit 06ce017c7d73f90db1c99f9e6a56c486b0313864
Author: Martin Liska <mliska@suse.cz>
Date:   Wed Aug 3 22:31:09 2022 +0200

    dwarf: use find_abstract_instance for vars and DW_AT_specification
    
    The following simple test case fails when dwz is used:
    
    $ cat demo.C
    namespace std {
      enum { _S_fixed, _S_floatfield = _S_fixed };
      struct {
        struct {};
      }
      __ioinit;
    }
    
    int main() {
      return 0;
    }
    
    $ g++ demo.C -g && cp a.out b.out && dwz -m xxx.so a.out b.out && objdump -S a.out >/dev/null
    objdump: DWARF error: could not find variable specification at offset 0x3d3
    
    As seen the reference is defined in xxx.so shared part:
    
    $ eu-readelf -w -N a.out | grep -A3 -B3 3d3
                 decl_column          (data1) 11
                 sibling              (ref_udata) [   387]
     [   387]    variable             abbrev: 30
                 specification        (GNU_ref_alt) [   3d3]
                 location             (exprloc)
                  [ 0] addr 0x404019
     [   396]    subprogram           abbrev: 32
    
    $ eu-readelf -w -N a.out | less
    
    ...
    
     Compilation unit at offset 920:
     Version: 5, Abbreviation section offset: 0, Address size: 8, Offset size: 4
     Unit type: partial (3)
    ...
     [   3d3]      variable             abbrev: 31
                   name                 (strp) "__ioinit"
                   decl_file            (data1) demo.C (10)
                   decl_line            (data1) 6
                   decl_column          (data1) 3
                   type                 (ref_udata) [   3c4]
                   declaration          (flag_present) yes
    
    With the patch the same output is emitted as before usage of dwz.
    
    bfd/ChangeLog:
    
            PR 29442
            * dwarf2.c (struct varinfo): Use const char * type.
            (scan_unit_for_symbols): Call find_abstract_instance for
            DW_AT_specification for variables that can be in a different CU
            (e.g. done by dwz)
Comment 4 Martin Liska 2022-08-08 11:53:22 UTC
Fixed, will be available in 2.40.