public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] dwarf: use find_abstract_instance for vars and DW_AT_specification
@ 2022-08-07 17:19 Martin Liška
  2022-08-08 11:06 ` Nick Clifton
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Liška @ 2022-08-07 17:19 UTC (permalink / raw)
  To: binutils

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)
---
 bfd/dwarf2.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c
index 47618788513..fbe9dd2070b 100644
--- a/bfd/dwarf2.c
+++ b/bfd/dwarf2.c
@@ -1801,7 +1801,7 @@ struct varinfo
   /* The type of this variable.  */
   int tag;
   /* The name of the variable, if it has one.  */
-  char *name;
+  const char *name;
   /* The address of the variable.  */
   bfd_vma addr;
   /* Where the symbol is defined.  */
@@ -4094,11 +4094,12 @@ scan_unit_for_symbols (struct comp_unit *unit)
 		case DW_AT_specification:
 		  if (is_int_form (&attr) && attr.u.val)
 		    {
-		      struct varinfo * spec_var;
-
-		      spec_var = lookup_var_by_offset (attr.u.val,
-						       unit->variable_table);
-		      if (spec_var == NULL)
+		      bool is_linkage;
+		      if (!find_abstract_instance (unit, &attr, 0,
+						   &var->name,
+						   &is_linkage,
+						   &var->file,
+						   &var->line))
 			{
 			  _bfd_error_handler (_("DWARF error: could not find "
 						"variable specification "
@@ -4106,15 +4107,6 @@ scan_unit_for_symbols (struct comp_unit *unit)
 					      (unsigned long) attr.u.val);
 			  break;
 			}
-
-		      if (var->name == NULL)
-			var->name = spec_var->name;
-		      if (var->file == NULL && spec_var->file != NULL)
-			var->file = strdup (spec_var->file);
-		      if (var->line == 0)
-			var->line = spec_var->line;
-		      if (var->sec == NULL)
-			var->sec = spec_var->sec;
 		    }
 		  break;
 
-- 
2.37.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] dwarf: use find_abstract_instance for vars and DW_AT_specification
  2022-08-07 17:19 [PATCH] dwarf: use find_abstract_instance for vars and DW_AT_specification Martin Liška
@ 2022-08-08 11:06 ` Nick Clifton
  0 siblings, 0 replies; 2+ messages in thread
From: Nick Clifton @ 2022-08-08 11:06 UTC (permalink / raw)
  To: Martin Liška, binutils

Hi Martin,

> 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)

Approved - please apply.

I would ask for a testcase as well, but I am not sure if one could be
constructed that was independent of dwz.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-08-08 11:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-07 17:19 [PATCH] dwarf: use find_abstract_instance for vars and DW_AT_specification Martin Liška
2022-08-08 11:06 ` Nick Clifton

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).