[applied] dwarf-reader: Bug 29932 - Handle function DIE as type as needed

Message ID 87wn6eb9uz.fsf@seketeli.org
State New
Headers
Series [applied] dwarf-reader: Bug 29932 - Handle function DIE as type as needed |

Commit Message

Dodji Seketeli Dec. 26, 2022, 12:57 p.m. UTC
  Hello,

When building the IR for a function type, the DWARF reader considers
the function DIE we are looking at as a type DIE.

In dwarf::reader::lookup_fn_type_from_die_repr_per_tu, the call to
get_die_pretty_representation doesn't enforce the fact that the DIE we
are looking at must be considered as a type.  This is usually not a
problem because even if get_die_pretty_representation considers the
function DIE as a decl, the representation of a function and a
function type are almost the same.

In this particular case, we run into a function DIE that has an empty
name:

 [ 51e54]    subprogram           abbrev: 18
             external             (flag_present) yes
             name                 (strp) ""
             decl_file            (data1) catgets.c (1)
             decl_line            (data1) 89
             prototyped           (flag_present) yes
             type                 (ref4) [ 51ac5]
             low_pc               (addr) +0x0000000000034cc0
             high_pc              (data8) 133 (+0x0000000000034d45)
             frame_base           (exprloc)
              [ 0] call_frame_cfa
             GNU_all_call_sites   (flag_present) yes
             sibling              (ref4) [ 51edb]

Note that this is from the /lib64/libc-2.17.so from the
https://vault.centos.org/7.6.1810/os/x86_64/Packages/glibc-2.17-260.el7.x86_64.rpm
package, associated with the debuginfo package at http://debuginfo.centos.org/7/x86_64/glibc-debuginfo-2.17-260.el7.x86_64.rpm.

In that case, get_die_pretty_representation returns an empty string
because it doesn't expects a function decl with an empty name.

If we make dwarf::reader::lookup_fn_type_from_die_repr_per_tu
explicitly be in the context of a type by invoking
get_die_pretty_type_representation instead, the problem disapears as
the latter function treats the DIE as a function type DIE, so it
doesn't need its name.

Thus, this patch makes
dwarf::reader::lookup_fn_type_from_die_repr_per_tu invoke
get_die_pretty_type_representation instead.

	* src/abg-dwarf-reader.cc
	(reader::lookup_fn_type_from_die_repr_per_tu): Invoke
	get_die_pretty_type_representation instead of
	get_die_pretty_representation when looking at a function DIE
	without a name.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
---
 src/abg-dwarf-reader.cc | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Patch

diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc
index 5df1516d..668f970d 100644
--- a/src/abg-dwarf-reader.cc
+++ b/src/abg-dwarf-reader.cc
@@ -3509,8 +3509,9 @@  public:
     if (!die_is_function_type(die))
       return function_type_sptr();
 
-    interned_string repr =
-      get_die_pretty_representation(die, /*where=*/0);
+    interned_string repr = die_name(die).empty() ?
+      get_die_pretty_type_representation(die, /*where=*/0)
+      : get_die_pretty_representation(die, /*where=*/0);
     ABG_ASSERT(!repr.empty());
 
     istring_fn_type_map_type::const_iterator i =