public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: "mark at klomp dot org" <sourceware-bugzilla@sourceware.org>
To: elfutils-devel@sourceware.org
Subject: [Bug libdw/28294] dwarf_aggregate_size fails on some array types
Date: Sat, 11 Sep 2021 23:43:13 +0000	[thread overview]
Message-ID: <bug-28294-10460-3btSLILmJU@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-28294-10460@http.sourceware.org/bugzilla/>

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

--- Comment #2 from Mark Wielaard <mark at klomp dot org> ---
(In reply to Eli Boling from comment #0)
> In dwarf_aggregate_size.c, the helper function array_size unconditionally
> uses dwarf_formsdata to obtain the value of the DW_AT_upper_bound attribute
> for array types.  In many cases, this will return a negative value for C
> arrays that have positive upper bounds, causing the function to return a
> failure value, which propagates up through dwarf_aggregate_size.
> 
> This is an exemplary type (via readelf -w):
>  <1><90e>: Abbrev Number: 37 (DW_TAG_array_type)
>     <90f>   DW_AT_type        : <0x118>
>  <2><913>: Abbrev Number: 11 (DW_TAG_subrange_type)
>     <914>   DW_AT_type        : <0x2c>
>     <918>   DW_AT_upper_bound : 249
> 
> And the same type, via eu-readelf --debug-dump=info:
>  [   90e]    array_type           abbrev: 37
>              type                 (ref4) [   118]
>  [   913]      subrange_type        abbrev: 11
>                type                 (ref4) [    2c]
>                upper_bound          (data1) 249
> 
> If dwarf_aggregate_size is called on this type, when it gets the upper_bound
> attribute, it will get a value of -7, and fail.  For other array sizes, this
> will work.
> 
> Looking around a bit, the closest discussion I could find on the topic was
> this one about signed vs unsigned interpretation of array bounds back in
> 2005:
> http://www.dwarfstd.org/ShowIssue.php?issue=020702.1
> 
> I exchanged emails with Mark Wielaard on this, and he indicated that this
> did appear to be a bug, but he wasn't sure yet where the correct fix would
> be.

Could you try the attached patch?
I don't know if it works, it depends on the subrange_type at [2c].
If it doesn't work, could you post the full debug-dump or attach a test binary?

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

  parent reply	other threads:[~2021-09-11 23:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-31 11:51 [Bug libdw/28294] New: " egb.atos at gmail dot com
2021-09-11 23:39 ` [Bug libdw/28294] " mark at klomp dot org
2021-09-11 23:43 ` mark at klomp dot org [this message]
2021-10-06 20:42 ` mark at klomp dot org
2021-10-18 11:39 ` mark at klomp dot org
2021-10-18 11:43 ` mark at klomp dot org

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=bug-28294-10460-3btSLILmJU@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=elfutils-devel@sourceware.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).