blob: 8cab01c29a059aa6c7354571ff85e356d6e08984 [file] [log] [blame]
Andrew Geissler6aa7eec2023-03-03 12:41:14 -06001From: Mark Wielaard <mark@klomp.org>
2Date: Thu, 26 Jan 2023 17:19:15 +0000 (+0100)
3Subject: backends: Handle DW_TAG_unspecified_type in dwarf_peeled_die_type
4X-Git-Url: https://sourceware.org/git/?p=elfutils.git;a=commitdiff_plain;h=f2c522567ad63ac293535fba9704895e685ab5bc;hp=3fa98a6f29b0f370e32549ead7eb897c839af980
5
6backends: Handle DW_TAG_unspecified_type in dwarf_peeled_die_type
7
8binutils 2.40 introduces DW_TAG_unspecified_type for assembly
9functions with an unknown return type. This breaks the
10run-funcretval.sh testcase because dwfl_module_return_value_location
11returns an error for such functions because it cannot determine the
12return value location. Fix that by treating DW_TAG_unspecified_type
13as if the DIE doesn't have a DW_AT_type.
14
15Also update the testcase to explicitly checking for
16DW_TAG_unspecified_type and printing "returns unspecified type".
17
18https://sourceware.org/bugzilla/show_bug.cgi?id=30047
19
20Upstream-Status: Backport [https://sourceware.org/git/?p=elfutils.git;a=commitdiff;h=f2c522567ad63ac293535fba9704895e685ab5bc;hp=3fa98a6f29b0f370e32549ead7eb897c839af980]
21Signed-off-by: Mark Wielaard <mark@klomp.org>
22---
23
24--- a/backends/libebl_CPU.h
25+++ b/backends/libebl_CPU.h
26@@ -1,5 +1,6 @@
27 /* Common interface for libebl modules.
28 Copyright (C) 2000, 2001, 2002, 2003, 2005, 2013, 2014 Red Hat, Inc.
29+ Copyright (C) 2023 Mark J. Wielaard <mark@klomp.org>
30 This file is part of elfutils.
31
32 This file is free software; you can redistribute it and/or modify
33@@ -53,7 +54,9 @@ extern bool (*generic_debugscn_p) (const
34 dwarf_tag (_die); })
35
36 /* Get a type die corresponding to DIE. Peel CV qualifiers off
37- it. */
38+ it. Returns zero if the DIE doesn't have a type, or the type
39+ is DW_TAG_unspecified_type. Returns -1 on error. Otherwise
40+ returns the result tag DW_AT value. */
41 static inline int
42 dwarf_peeled_die_type (Dwarf_Die *die, Dwarf_Die *result)
43 {
44@@ -69,7 +72,14 @@ dwarf_peeled_die_type (Dwarf_Die *die, D
45 if (dwarf_peel_type (result, result) != 0)
46 return -1;
47
48- return DWARF_TAG_OR_RETURN (result);
49+ if (result == NULL)
50+ return -1;
51+
52+ int tag = dwarf_tag (result);
53+ if (tag == DW_TAG_unspecified_type)
54+ return 0; /* Treat an unspecified type as if there was no type. */
55+
56+ return tag;
57 }
58
59 #endif /* libebl_CPU.h */
60--- a/tests/funcretval.c
61+++ b/tests/funcretval.c
62@@ -1,5 +1,6 @@
63 /* Test program for dwfl_module_return_value_location.
64 Copyright (C) 2005 Red Hat, Inc.
65+ Copyright (C) 2023 Mark J. Wielaard <mark@klomp.org>
66 This file is part of elfutils.
67
68 This file is free software; you can redistribute it and/or modify
69@@ -67,7 +68,18 @@ handle_function (Dwarf_Die *funcdie, voi
70 error (EXIT_FAILURE, 0, "dwfl_module_return_value_location: %s",
71 dwfl_errmsg (-1));
72 else if (nlocops == 0)
73- puts ("returns no value");
74+ {
75+ // Check if this is the special unspecified type
76+ // https://sourceware.org/bugzilla/show_bug.cgi?id=30047
77+ Dwarf_Die die_mem, *typedie = &die_mem;
78+ Dwarf_Attribute attr_mem, *attr;
79+ attr = dwarf_attr_integrate (funcdie, DW_AT_type, &attr_mem);
80+ if (dwarf_formref_die (attr, typedie) != NULL
81+ && dwarf_tag (typedie) == DW_TAG_unspecified_type)
82+ puts ("returns unspecified type");
83+ else
84+ puts ("returns no value");
85+ }
86 else
87 {
88 printf ("return value location:");