[PATCH pahole] dwarf_loader: Represent union in same way as struct

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There is a mismatch between how struct/union/class is loaded and later
processed. On load, struct/class DIE causes creation of `struct class`,
while union DIE causes creation of just `struct type`, which for
structs/classes is nested within `struct class`.

When processing them for output, though, both structs/classes and unions
are assumed to be represented by `struct class` and are processed
uniformly. For DWARF loaded this causes first member to be skipped,
while for BTF loader reliably results in SIGSEGV.

This patches fixes the issue for DWARF loader.

Without fix:

 andriin@devvm$ ~/local/pahole/build/pahole -F dwarf -C fpregs_state ~/local/linux/net/ipv4/tcp.o
 union fpregs_state {
         struct fxregs_state        fxsave;             /*     0   512 */
         struct swregs_state        soft;               /*     0   136 */
         struct xregs_state         xsave;              /*     0   576 */
         u8                         __padding[4096];    /*     0  4096 */
 };

With fix:

 andriin@devvm$ ~/local/pahole/build/pahole -F btf -C fpregs_state ~/local/linux/net/ipv4/tcp.o
 union fpregs_state {
         struct fregs_state         fsave;              /*     0   112 */
         struct fxregs_state        fxsave;             /*     0   512 */
         struct swregs_state        soft;               /*     0   136 */
         struct xregs_state         xsave;              /*     0   576 */
         u8                         __padding[4096];    /*     0  4096 */
 };

Signed-off-by: Andrii Nakryiko <andriin@xxxxxx>
---
dwarf_loader.c | 24 +++---------------------
1 file changed, 3 insertions(+), 21 deletions(-)

diff --git a/dwarf_loader.c b/dwarf_loader.c
index 7e3d049..b02b2ec 100644
--- a/dwarf_loader.c
+++ b/dwarf_loader.c
@@ -1042,23 +1042,6 @@ static struct tag *die__create_new_namespace(Dwarf_Die *die, struct cu *cu)
	return namespace ? &namespace->tag : NULL;
}

-static struct tag *die__create_new_union(Dwarf_Die *die, struct cu *cu)
-{
-	Dwarf_Die child;
-	struct type *utype = type__new(die, cu);
-
-	if (utype != NULL &&
-	    dwarf_haschildren(die) != 0 &&
-	    dwarf_child(die, &child) == 0) {
-		if (die__process_class(&child, utype, cu) != 0) {
-			type__delete(utype, cu);
-			utype = NULL;
-		}
-	}
-
-	return utype ? &utype->namespace.tag : NULL;
-}
-
static struct tag *die__create_new_base_type(Dwarf_Die *die, struct cu *cu)
{
	struct base_type *base = base_type__new(die, cu);
@@ -1532,8 +1515,8 @@ static int die__process_function(Dwarf_Die *die, struct ftype *ftype,
		case DW_TAG_template_type_parameter:
		case DW_TAG_template_value_parameter:
			/* FIXME: probably we'll have to attach this as a list of
- 			 * template parameters to use at class__fprintf time... 
- 			 * See die__process_class */
+			 * template parameters to use at class__fprintf time...
+			 * See die__process_class */
			tag__print_not_supported(dwarf_tag(die));
			continue;
		case DW_TAG_formal_parameter:
@@ -1634,6 +1617,7 @@ static struct tag *__die__process_tag(Dwarf_Die *die, struct cu *cu,
	case DW_TAG_class_type:
	case DW_TAG_interface_type:
	case DW_TAG_structure_type:
+	case DW_TAG_union_type:
		tag = die__create_new_class(die, cu);		break;
	case DW_TAG_subprogram:
		tag = die__create_new_function(die, cu);	break;
@@ -1642,8 +1626,6 @@ static struct tag *__die__process_tag(Dwarf_Die *die, struct cu *cu,
	case DW_TAG_rvalue_reference_type:
	case DW_TAG_typedef:
		tag = die__create_new_typedef(die, cu);		break;
-	case DW_TAG_union_type:
-		tag = die__create_new_union(die, cu);		break;
	case DW_TAG_variable:
		tag = die__create_new_variable(die, cu);	break;
	default:
-- 
2.17.1



[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux