dwarf_aggregate_size() seems to fall over on pointer types

Mark Wielaard mjw at redhat.com
Wed Oct 1 18:33:26 UTC 2014


On Wed, Oct 01, 2014 at 10:46:52AM -0700, Josh Stone wrote:
> > Am I missing something? Is this a Clang bug or an elfutils bug?
> 
> I don't think it's strictly a bug in either.  Clang is not required to
> produce byte_size, and elfutils is just reporting what it knows.
> 
> Still, it might be nice if elfutils made that machine-class inference
> for you.  (But I worry about things like that mips pointer issue
> reported recently.)

Agreed. It seems reasonable for a consumer to assume that if any of
the reference/pointer types don't have an explicit size then they
should assume the type has address size. The DWARF spec does explicitly
call out DW_AT_address_class for pointer types. But that isn't really
helpful since it then only defines DW_ADDR_none and leaves any other
value as architecture defined.

How about the attached patch? (I haven't yet looked at the MIPS issue,
but think it reasonable to require the producer to add an explicit
DW_AT_byte_size if the assumption of address size is not correct.)

Thanks,

Mark
-------------- next part --------------
>From b29f1741856a179fd6a426534d19b1ed4807f6c1 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mjw at redhat.com>
Date: Wed, 1 Oct 2014 20:29:14 +0200
Subject: [PATCH] libdw: dwarf_aggregate_size return CU address_size for
 sizeless pointer/refs.

Signed-off-by: Mark Wielaard <mjw at redhat.com>
---
 libdw/ChangeLog              | 6 ++++++
 libdw/dwarf_aggregate_size.c | 9 ++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 410b31a..e6716d6 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,9 @@
+2014-10-01  Mark Wielaard  <mjw at redhat.com>
+
+	* dwarf_aggregate_size.c (aggregate_size): Return CU address_size
+	for sizeless DW_TAG_pointer_type, DW_TAG_reference_type or
+	DW_TAG_rvalue_reference_type.
+
 2014-09-12  Petr Machata  <pmachata at redhat.com>
 
 	* memory-access.h (read_ubyte_unaligned_inc): Allow only 4- and
diff --git a/libdw/dwarf_aggregate_size.c b/libdw/dwarf_aggregate_size.c
index 07c53a2..cfc2639 100644
--- a/libdw/dwarf_aggregate_size.c
+++ b/libdw/dwarf_aggregate_size.c
@@ -1,5 +1,5 @@
 /* Compute size of an aggregate type from DWARF.
-   Copyright (C) 2010 Red Hat, Inc.
+   Copyright (C) 2010, 2014 Red Hat, Inc.
    This file is part of elfutils.
 
    This file is free software; you can redistribute it and/or modify
@@ -205,6 +205,13 @@ aggregate_size (Dwarf_Die *die, Dwarf_Word *size, Dwarf_Die *type_mem)
 
     case DW_TAG_array_type:
       return array_size (die, size, &attr_mem, type_mem);
+
+    /* Assume references and pointers have pointer size if not given an
+       explicit DW_AT_byte_size.  */
+    case DW_TAG_pointer_type:
+    case DW_TAG_reference_type:
+    case DW_TAG_rvalue_reference_type:
+      return die->cu->address_size;
     }
 
   /* Most types must give their size directly.  */
-- 
1.9.3



More information about the elfutils-devel mailing list