public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [Bug libdw/22546] New: dwarf_aggregate_size() doesn't work for multi-dimensional arrays
@ 2017-12-04 23:05 sourceware at dima dot secretsauce.net
  2017-12-04 23:06 ` [Bug libdw/22546] " sourceware at dima dot secretsauce.net
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: sourceware at dima dot secretsauce.net @ 2017-12-04 23:05 UTC (permalink / raw)
  To: elfutils-devel

https://sourceware.org/bugzilla/show_bug.cgi?id=22546

            Bug ID: 22546
           Summary: dwarf_aggregate_size() doesn't work for
                    multi-dimensional arrays
           Product: elfutils
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libdw
          Assignee: unassigned at sourceware dot org
          Reporter: sourceware at dima dot secretsauce.net
                CC: elfutils-devel at sourceware dot org
  Target Milestone: ---

Hi. I'm observing that dwarf_aggregate_size() returns bogus results when
looking at double-dimensional arrays. For instance, looking at

  double dd[3][5];

It says the aggregate is 64-bytes long instead of 120. The bug is that it ends
up computing (3+5)*8 instead of 3*5*8.

I'm attaching a simple test case. It loads the current process's debug
information, and prints out the size of dd, defined as above. It shows the
failure:

  dima@fatty:/tmp$ gcc -g -ldw -lelf dwarf_aggregate_size_bug.c -o
dwarf_aggregate_size_bug

  dima@fatty:/tmp$ ./dwarf_aggregate_size_bug                                   
  Found DIE for 'dd'. size: 64

I'm using libelf1 0.168-1 on Debian/sid, although at least version 0.170 has
the bug too.

I'm attaching a proof-of-concept patch to solve this. Note that this patch
isn't final: previously we would compute a separate stride for each dimension,
while the patch only computes the stride once. I don't know what case
specifically that is meant to handle. Tests pass before and after.

If for some reason dwarf_aggregate_size() isn't meant to be used this way, then
it should still be changed to fail in a more obvious way. Answering 64 here is
NEVER the right answer.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libdw/22546] dwarf_aggregate_size() doesn't work for multi-dimensional arrays
  2017-12-04 23:05 [Bug libdw/22546] New: dwarf_aggregate_size() doesn't work for multi-dimensional arrays sourceware at dima dot secretsauce.net
@ 2017-12-04 23:06 ` sourceware at dima dot secretsauce.net
  2017-12-04 23:18 ` sourceware at dima dot secretsauce.net
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: sourceware at dima dot secretsauce.net @ 2017-12-04 23:06 UTC (permalink / raw)
  To: elfutils-devel

https://sourceware.org/bugzilla/show_bug.cgi?id=22546

--- Comment #1 from dima kogan <sourceware at dima dot secretsauce.net> ---
Created attachment 10662
  --> https://sourceware.org/bugzilla/attachment.cgi?id=10662&action=edit
Prototype fix

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libdw/22546] dwarf_aggregate_size() doesn't work for multi-dimensional arrays
  2017-12-04 23:05 [Bug libdw/22546] New: dwarf_aggregate_size() doesn't work for multi-dimensional arrays sourceware at dima dot secretsauce.net
  2017-12-04 23:06 ` [Bug libdw/22546] " sourceware at dima dot secretsauce.net
@ 2017-12-04 23:18 ` sourceware at dima dot secretsauce.net
  2017-12-08  9:47 ` sourceware at dima dot secretsauce.net
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: sourceware at dima dot secretsauce.net @ 2017-12-04 23:18 UTC (permalink / raw)
  To: elfutils-devel

https://sourceware.org/bugzilla/show_bug.cgi?id=22546

--- Comment #2 from dima kogan <sourceware at dima dot secretsauce.net> ---
Created attachment 10663
  --> https://sourceware.org/bugzilla/attachment.cgi?id=10663&action=edit
Demo program

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libdw/22546] dwarf_aggregate_size() doesn't work for multi-dimensional arrays
  2017-12-04 23:05 [Bug libdw/22546] New: dwarf_aggregate_size() doesn't work for multi-dimensional arrays sourceware at dima dot secretsauce.net
  2017-12-04 23:06 ` [Bug libdw/22546] " sourceware at dima dot secretsauce.net
  2017-12-04 23:18 ` sourceware at dima dot secretsauce.net
@ 2017-12-08  9:47 ` sourceware at dima dot secretsauce.net
  2017-12-08  9:49 ` sourceware at dima dot secretsauce.net
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: sourceware at dima dot secretsauce.net @ 2017-12-08  9:47 UTC (permalink / raw)
  To: elfutils-devel

https://sourceware.org/bugzilla/show_bug.cgi?id=22546

--- Comment #3 from dima kogan <sourceware at dima dot secretsauce.net> ---
Created attachment 10672
  --> https://sourceware.org/bugzilla/attachment.cgi?id=10672&action=edit
Update to the test suite to show this problem

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libdw/22546] dwarf_aggregate_size() doesn't work for multi-dimensional arrays
  2017-12-04 23:05 [Bug libdw/22546] New: dwarf_aggregate_size() doesn't work for multi-dimensional arrays sourceware at dima dot secretsauce.net
                   ` (2 preceding siblings ...)
  2017-12-08  9:47 ` sourceware at dima dot secretsauce.net
@ 2017-12-08  9:49 ` sourceware at dima dot secretsauce.net
  2017-12-11 16:31 ` mark at klomp dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: sourceware at dima dot secretsauce.net @ 2017-12-08  9:49 UTC (permalink / raw)
  To: elfutils-devel

https://sourceware.org/bugzilla/show_bug.cgi?id=22546

--- Comment #4 from dima kogan <sourceware at dima dot secretsauce.net> ---
Here's a patch to add the failing case to the test suite. This test update
fails in the stock sources, but succeeds with my patch applied. Note that this
patch contains a diff to a binary file (that's how the test suite works), and
this binary piece will be recognized by 'git am' only.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libdw/22546] dwarf_aggregate_size() doesn't work for multi-dimensional arrays
  2017-12-04 23:05 [Bug libdw/22546] New: dwarf_aggregate_size() doesn't work for multi-dimensional arrays sourceware at dima dot secretsauce.net
                   ` (3 preceding siblings ...)
  2017-12-08  9:49 ` sourceware at dima dot secretsauce.net
@ 2017-12-11 16:31 ` mark at klomp dot org
  2017-12-11 22:55 ` mark at klomp dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: mark at klomp dot org @ 2017-12-11 16:31 UTC (permalink / raw)
  To: elfutils-devel

https://sourceware.org/bugzilla/show_bug.cgi?id=22546

Mark Wielaard <mark at klomp dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mark at klomp dot org

--- Comment #5 from Mark Wielaard <mark at klomp dot org> ---
Thanks I think you are right. I am looking at how to correctly handle the
stride. I believe this only happens with Fortran code.

While reviewing the code I noticed something else that looks wrong.
Independent from what you discovered.

We do the following:

dwarf_aggregate_size (Dwarf_Die *die, Dwarf_Word *size)
{
  Dwarf_Die type_mem;

  if (INTUSE (dwarf_peel_type) (die, die) != 0)
    return -1;

  return aggregate_size (die, size, &type_mem);
}

The caller probably doesn't really care, but it isn't really nice to change the
die the caller gave us. So I propose to change it like so:

int
dwarf_aggregate_size (Dwarf_Die *die, Dwarf_Word *size)
{
  Dwarf_Die die_mem, type_mem;

  if (INTUSE (dwarf_peel_type) (die, &die_mem) != 0)
    return -1;

  return aggregate_size (&die_mem, size, &type_mem);
}

Just wanted to note that before I forgot investigating the real issue.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libdw/22546] dwarf_aggregate_size() doesn't work for multi-dimensional arrays
  2017-12-04 23:05 [Bug libdw/22546] New: dwarf_aggregate_size() doesn't work for multi-dimensional arrays sourceware at dima dot secretsauce.net
                   ` (4 preceding siblings ...)
  2017-12-11 16:31 ` mark at klomp dot org
@ 2017-12-11 22:55 ` mark at klomp dot org
  2017-12-12  8:10 ` sourceware at dima dot secretsauce.net
  2017-12-12  9:52 ` mark at klomp dot org
  7 siblings, 0 replies; 9+ messages in thread
From: mark at klomp dot org @ 2017-12-11 22:55 UTC (permalink / raw)
  To: elfutils-devel

https://sourceware.org/bugzilla/show_bug.cgi?id=22546

--- Comment #6 from Mark Wielaard <mark at klomp dot org> ---
I believe your fix is correct. And we really do want to calculate the stride
only once based on the array element type, not for each dimension. I am not
sure what the original code tried to do. It probably just was never tested
against multi-dimensional arrays. So the testcase addition is great too.

Would you mind sending a complete patch plus the testcase addition to the
mailinglist as describe in the CONTRIBUTING document?
https://sourceware.org/git/?p=elfutils.git;a=blob_plain;f=CONTRIBUTING;hb=HEAD

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libdw/22546] dwarf_aggregate_size() doesn't work for multi-dimensional arrays
  2017-12-04 23:05 [Bug libdw/22546] New: dwarf_aggregate_size() doesn't work for multi-dimensional arrays sourceware at dima dot secretsauce.net
                   ` (5 preceding siblings ...)
  2017-12-11 22:55 ` mark at klomp dot org
@ 2017-12-12  8:10 ` sourceware at dima dot secretsauce.net
  2017-12-12  9:52 ` mark at klomp dot org
  7 siblings, 0 replies; 9+ messages in thread
From: sourceware at dima dot secretsauce.net @ 2017-12-12  8:10 UTC (permalink / raw)
  To: elfutils-devel

https://sourceware.org/bugzilla/show_bug.cgi?id=22546

--- Comment #7 from dima kogan <sourceware at dima dot secretsauce.net> ---
Thanks for looking at it. I submitted the patch.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug libdw/22546] dwarf_aggregate_size() doesn't work for multi-dimensional arrays
  2017-12-04 23:05 [Bug libdw/22546] New: dwarf_aggregate_size() doesn't work for multi-dimensional arrays sourceware at dima dot secretsauce.net
                   ` (6 preceding siblings ...)
  2017-12-12  8:10 ` sourceware at dima dot secretsauce.net
@ 2017-12-12  9:52 ` mark at klomp dot org
  7 siblings, 0 replies; 9+ messages in thread
From: mark at klomp dot org @ 2017-12-12  9:52 UTC (permalink / raw)
  To: elfutils-devel

https://sourceware.org/bugzilla/show_bug.cgi?id=22546

Mark Wielaard <mark at klomp dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #8 from Mark Wielaard <mark at klomp dot org> ---
Fix has been pushed to master:
https://sourceware.org/ml/elfutils-devel/2017-q4/msg00103.html

A patch for the separate issue mentioned in comment #5 has been submitted:
https://sourceware.org/ml/elfutils-devel/2017-q4/msg00106.html

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-12-12  9:52 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-04 23:05 [Bug libdw/22546] New: dwarf_aggregate_size() doesn't work for multi-dimensional arrays sourceware at dima dot secretsauce.net
2017-12-04 23:06 ` [Bug libdw/22546] " sourceware at dima dot secretsauce.net
2017-12-04 23:18 ` sourceware at dima dot secretsauce.net
2017-12-08  9:47 ` sourceware at dima dot secretsauce.net
2017-12-08  9:49 ` sourceware at dima dot secretsauce.net
2017-12-11 16:31 ` mark at klomp dot org
2017-12-11 22:55 ` mark at klomp dot org
2017-12-12  8:10 ` sourceware at dima dot secretsauce.net
2017-12-12  9:52 ` mark at klomp dot org

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).