public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Conrad Rad <cse.cem@gmail.com>
To: elfutils-devel@lists.fedorahosted.org
Subject: Re: dwarf_aggregate_size() seems to fall over on pointer types
Date: Wed, 01 Oct 2014 15:26:34 -0400	[thread overview]
Message-ID: <CAG6CVpXYLAz+UH98z33qo9Ju3_kDdFsHxQ_+he6driYn8qdo=Q@mail.gmail.com> (raw)
In-Reply-To: CAG6CVpVuLt_z40N==1v3=PwXqEuS_wJtB5PSoRm3iBNoggL63g@mail.gmail.com

[-- Attachment #1: Type: text/plain, Size: 1115 bytes --]

On Wed, Oct 1, 2014 at 3:23 PM, Conrad Rad <cse.cem@gmail.com> wrote:
> On Wed, Oct 1, 2014 at 3:10 PM, Conrad Rad <cse.cem@gmail.com> wrote:
>> On Wed, Oct 1, 2014 at 2:33 PM, Mark Wielaard <mjw@redhat.com> wrote:
>>> On Wed, Oct 01, 2014 at 10:46:52AM -0700, Josh Stone wrote:
>>> 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.)
>>
>> On my repro, it fixes the pointer member, but not the array-of-pointer member.
>
> Oh, wow, I misread. No, that's wrong.
>
>> struct b {
>>         char *d;
>>         void *e[3];
>> ...
>> };
>>
>> $ ./repro a.out:
>> ...
>>         agg_size(b. (type  ) d): 8, 0xffffffff
>
> This should be 0, 0x8. The size goes in the *size, return value of
> dwarf_aggregate_size() should be zero on success, not 8. The patch is
> not good as is.
>
> Thanks,
> Conrad

With the fixed patch (attached), it works:

        agg_size(b.d): 0, 0x8
        agg_size(b.e): 0, 0x18

Thanks,
Conrad

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: a.patch --]
[-- Type: text/x-patch, Size: 1658 bytes --]

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 410b31a..e6716d6 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,5 +1,11 @@
+2014-10-01  Mark Wielaard  <mjw@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@redhat.com>
 
 	* memory-access.h (read_ubyte_unaligned_inc): Allow only 4- and
 	8-byte quantities.  Consequently, rename to...
 	(read_addr_unaligned_inc): ... this.
diff --git a/libdw/dwarf_aggregate_size.c b/libdw/dwarf_aggregate_size.c
index 07c53a2..5d23541 100644
--- a/libdw/dwarf_aggregate_size.c
+++ b/libdw/dwarf_aggregate_size.c
@@ -1,7 +1,7 @@
 /* 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
    it under the terms of either
 
@@ -203,10 +203,18 @@ aggregate_size (Dwarf_Die *die, Dwarf_Word *size, Dwarf_Die *type_mem)
       return aggregate_size (get_type (die, &attr_mem, type_mem),
 			     size, type_mem); /* Tail call.  */
 
     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:
+      *size = die->cu->address_size;
+      return 0;
     }
 
   /* Most types must give their size directly.  */
   return -1;
 }

             reply	other threads:[~2014-10-01 19:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-01 19:26 Conrad Rad [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-10-02 20:56 Mark Wielaard
2014-10-02 12:50 Conrad Rad
2014-10-02 12:05 Mark Wielaard
2014-10-01 20:33 Roland McGrath
2014-10-01 19:23 Conrad Rad
2014-10-01 19:10 Conrad Rad
2014-10-01 18:47 Josh Stone
2014-10-01 18:34 Conrad Rad
2014-10-01 18:33 Mark Wielaard
2014-10-01 17:46 Josh Stone
2014-10-01 17:15 Conrad Rad

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAG6CVpXYLAz+UH98z33qo9Ju3_kDdFsHxQ_+he6driYn8qdo=Q@mail.gmail.com' \
    --to=cse.cem@gmail.com \
    --cc=elfutils-devel@lists.fedorahosted.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).