public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [Bug tools/24550] New: eu-readelf does not know about DW_AT_GNU_bias
@ 2019-05-13 17:54 tromey at sourceware dot org
  2019-05-14 18:36 ` [Bug tools/24550] eu-readelf does not know about DW_AT_GNU_{bias,numerator,denumerator} mark at klomp dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: tromey at sourceware dot org @ 2019-05-13 17:54 UTC (permalink / raw)
  To: elfutils-devel

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

            Bug ID: 24550
           Summary: eu-readelf does not know about DW_AT_GNU_bias
           Product: elfutils
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: tools
          Assignee: unassigned at sourceware dot org
          Reporter: tromey at sourceware dot org
                CC: elfutils-devel at sourceware dot org
  Target Milestone: ---

The Ada compiler can emit DW_AT_GNU_bias in some situations.

Here is "tt.adb":

with Text_IO; use Text_IO;
procedure Tt is
   type Small is range -7 .. -4;
   for Small'Size use 2;
   Y : Small := -5;

  type Repeat_Count_T is range 1 .. 2 ** 6;
  for Repeat_Count_T'Size use 6;
  X : Repeat_Count_T := 64;
begin
  Put_Line (X'Image);
  Put_Line (Y'Image);
end Tt;


Compile with

gcc -fgnat-encodings=minimal -g -c tt.adb

gdb's dwarf2.def says:

/* Biased integer extension.
   See https://gcc.gnu.org/wiki/DW_AT_GNU_bias .  */
DW_TAG (DW_AT_GNU_bias, 0x2305)

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

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

* [Bug tools/24550] eu-readelf does not know about DW_AT_GNU_{bias,numerator,denumerator}
  2019-05-13 17:54 [Bug tools/24550] New: eu-readelf does not know about DW_AT_GNU_bias tromey at sourceware dot org
@ 2019-05-14 18:36 ` mark at klomp dot org
  2019-05-15 16:13 ` tromey at sourceware dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: mark at klomp dot org @ 2019-05-14 18:36 UTC (permalink / raw)
  To: elfutils-devel

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

Mark Wielaard <mark at klomp dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mark at klomp dot org
            Summary|eu-readelf does not know    |eu-readelf does not know
                   |about DW_AT_GNU_bias        |about
                   |                            |DW_AT_GNU_{bias,numerator,d
                   |                            |enumerator}

--- Comment #1 from Mark Wielaard <mark at klomp dot org> ---
We are also missing GNU_AT_GNU_numerator and GNU_AT_GNU_denominator.

In theory all that is needed is add them to dwarf.h.
Since they are simple constant attributes.

diff --git a/libdw/dwarf.h b/libdw/dwarf.h
index dc5973352..71ca2baae 100644
--- a/libdw/dwarf.h
+++ b/libdw/dwarf.h
@@ -351,6 +351,12 @@ enum
     DW_AT_GNU_pubnames = 0x2134,
     DW_AT_GNU_pubtypes = 0x2135,

+    /* https://gcc.gnu.org/wiki/DW_AT_GNU_numerator_denominator  */
+    DW_AT_GNU_numerator = 0x2303,
+    DW_AT_GNU_denominator = 0x2304,
+    /* https://gcc.gnu.org/wiki/DW_AT_GNU_bias  */
+    DW_AT_GNU_bias = 0x2305,
+
     DW_AT_hi_user = 0x3fff
   };

But I want to make sure we get the type/signedness right.

Could you help me with creating gnat examples that compile and show their
usage?

If I try to compile your example I get two warnings:

tt.adb:4:04: warning: size clause forces biased representation for "Small"
tt.adb:8:03: warning: size clause forces biased representation for
"Repeat_Count_T"

Are those expected?

Also the subranges come out as:

 [    4e]      subrange_type        abbrev: 3
               lower_bound          (sdata) -7
               upper_bound          (sdata) -4
               GNU_bias             (sdata) -7
               name                 (strp) "tt__small"
               type                 (ref4) [    8d]
 [    8d]    base_type            abbrev: 7
             byte_size            (data1) 1
             encoding             (data1) signed (5)
             name                 (strp) "tt__TsmallB"
             artificial           (flag_present) yes

and

 [    6d]      subrange_type        abbrev: 6
               upper_bound          (sdata) 64
               GNU_bias             (sdata) 1
               name                 (strp) "tt__repeat_count_t"
               type                 (ref4) [    94]
 [    94]    base_type            abbrev: 7
             byte_size            (data1) 1
             encoding             (data1) signed (5)
             name                 (strp) "tt__Trepeat_count_tB"
             artificial           (flag_present) yes

There are three things that surprised me about this.
First that the byte_size is 1, are these types really using a full byte and not
2 or 6 bits?
And second that the bias is on the subrange_type and not the base_type. Is that
intended?
Finally, why is the last type signed?

Also could you help me create an compilable example of
https://gcc.gnu.org/wiki/DW_AT_GNU_numerator_denominator

Thanks,

Mark

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

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

* [Bug tools/24550] eu-readelf does not know about DW_AT_GNU_{bias,numerator,denumerator}
  2019-05-13 17:54 [Bug tools/24550] New: eu-readelf does not know about DW_AT_GNU_bias tromey at sourceware dot org
  2019-05-14 18:36 ` [Bug tools/24550] eu-readelf does not know about DW_AT_GNU_{bias,numerator,denumerator} mark at klomp dot org
@ 2019-05-15 16:13 ` tromey at sourceware dot org
  2019-05-15 18:02 ` tromey at sourceware dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: tromey at sourceware dot org @ 2019-05-15 16:13 UTC (permalink / raw)
  To: elfutils-devel

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

--- Comment #2 from Tom Tromey <tromey at sourceware dot org> ---
(In reply to Mark Wielaard from comment #1)

> Could you help me with creating gnat examples that compile and show their
> usage?

For bias, the above works.

> If I try to compile your example I get two warnings:
> 
> tt.adb:4:04: warning: size clause forces biased representation for "Small"
> tt.adb:8:03: warning: size clause forces biased representation for
> "Repeat_Count_T"
> 
> Are those expected?

Yes, though I don't know the rationale.

The numerator and denominator attributes are used for fixed-point types.
There is a test for this in git@github.com:pmderodat/dwarf-ada-testsuite.git

murgatroyd. readelf -wi tests/fixedpoint/foo.o |grep DW_AT_GNU_[dn]
    <229>   DW_AT_GNU_numerator: 1
    <22a>   DW_AT_GNU_denominator: 30
    <237>   DW_AT_GNU_numerator: 0
    <238>   DW_AT_GNU_denominator: 0


> Also the subranges come out as:
[...]
> There are three things that surprised me about this.
> First that the byte_size is 1, are these types really using a full byte and
> not 2 or 6 bits?

I'm not totally sure what is going on here.  Maybe the type needs to be
used in a packed record to see it actually shrink?  I will see if I can write
a test for this.

> And second that the bias is on the subrange_type and not the base_type. Is
> that intended?

Yes, the bias only applies to subrange types, not the base type.

> Finally, why is the last type signed?

I think that's the default.  You have to request an unsigned based type
explicitly, like:

   type Byte is mod 256;
   type Repeat_Count_T is new Byte range 1 .. 2 ** 6;

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

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

* [Bug tools/24550] eu-readelf does not know about DW_AT_GNU_{bias,numerator,denumerator}
  2019-05-13 17:54 [Bug tools/24550] New: eu-readelf does not know about DW_AT_GNU_bias tromey at sourceware dot org
  2019-05-14 18:36 ` [Bug tools/24550] eu-readelf does not know about DW_AT_GNU_{bias,numerator,denumerator} mark at klomp dot org
  2019-05-15 16:13 ` tromey at sourceware dot org
@ 2019-05-15 18:02 ` tromey at sourceware dot org
  2019-05-15 18:17 ` tromey at sourceware dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: tromey at sourceware dot org @ 2019-05-15 18:02 UTC (permalink / raw)
  To: elfutils-devel

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

--- Comment #3 from Tom Tromey <tromey at sourceware dot org> ---
> > There are three things that surprised me about this.
> > First that the byte_size is 1, are these types really using a full byte and
> > not 2 or 6 bits?
> 
> I'm not totally sure what is going on here.  Maybe the type needs to be
> used in a packed record to see it actually shrink?  I will see if I can write
> a test for this.

Thanks for noticing this.  I think the DWARF is incorrect here in a few
ways -- I am going to update the internal bug about it to get it fixed.

Meanwhile here is the updated test case I am using

--  Copyright 2019 Free Software Foundation, Inc.
--
--  This program is free software; you can redistribute it and/or modify
--  it under the terms of the GNU General Public License as published by
--  the Free Software Foundation; either version 3 of the License, or
--  (at your option) any later version.
--
--  This program is distributed in the hope that it will be useful,
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--  GNU General Public License for more details.
--
--  You should have received a copy of the GNU General Public License
--  along with this program.  If not, see <http://www.gnu.org/licenses/>.

procedure Bias is
   type Small is range -7 .. -4;
   for Small'Size use 2;
   Y : Small := -5;
   Y1 : Small := -7;

   type Byte is mod 256;
   type Repeat_Count_T is new Byte range 1 .. 2 ** 6;
   for Repeat_Count_T'Size use 6;
   X : Repeat_Count_T := 64;
   X1 : Repeat_Count_T := 1;

   type Char_Range is range 65 .. 68;
   for Char_Range'Size use 2;
   Cval : Char_Range := 65;

   type SomePackedRecord is record
      R: Small;
      S: Small;
   end record;
   pragma Pack (SomePackedRecord);
   SPR : SomePackedRecord := (R => -4, S => -5);

   type Packed_Array is array (1 .. 3) of Small;
   pragma pack (Packed_Array);
   A : Packed_Array := (-7, -5, -4);

begin
   null;
end Bias;

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

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

* [Bug tools/24550] eu-readelf does not know about DW_AT_GNU_{bias,numerator,denumerator}
  2019-05-13 17:54 [Bug tools/24550] New: eu-readelf does not know about DW_AT_GNU_bias tromey at sourceware dot org
                   ` (2 preceding siblings ...)
  2019-05-15 18:02 ` tromey at sourceware dot org
@ 2019-05-15 18:17 ` tromey at sourceware dot org
  2019-05-16 15:17 ` mark at klomp dot org
  2019-05-16 15:28 ` mark at klomp dot org
  5 siblings, 0 replies; 7+ messages in thread
From: tromey at sourceware dot org @ 2019-05-15 18:17 UTC (permalink / raw)
  To: elfutils-devel

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

--- Comment #4 from Tom Tromey <tromey at sourceware dot org> ---
BTW some of the oddities encountered might be good for dwarflint...

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

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

* [Bug tools/24550] eu-readelf does not know about DW_AT_GNU_{bias,numerator,denumerator}
  2019-05-13 17:54 [Bug tools/24550] New: eu-readelf does not know about DW_AT_GNU_bias tromey at sourceware dot org
                   ` (3 preceding siblings ...)
  2019-05-15 18:17 ` tromey at sourceware dot org
@ 2019-05-16 15:17 ` mark at klomp dot org
  2019-05-16 15:28 ` mark at klomp dot org
  5 siblings, 0 replies; 7+ messages in thread
From: mark at klomp dot org @ 2019-05-16 15:17 UTC (permalink / raw)
  To: elfutils-devel

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

Mark Wielaard <mark at klomp dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED

--- Comment #5 from Mark Wielaard <mark at klomp dot org> ---
Thanks for the analysis. For now I'll just go with adding the constants. They
seem to be printed as expected. But having examples in the testsuite might not
be the right time now since you might still fix some things about the actual
DWARF emitted.

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

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

* [Bug tools/24550] eu-readelf does not know about DW_AT_GNU_{bias,numerator,denumerator}
  2019-05-13 17:54 [Bug tools/24550] New: eu-readelf does not know about DW_AT_GNU_bias tromey at sourceware dot org
                   ` (4 preceding siblings ...)
  2019-05-16 15:17 ` mark at klomp dot org
@ 2019-05-16 15:28 ` mark at klomp dot org
  5 siblings, 0 replies; 7+ messages in thread
From: mark at klomp dot org @ 2019-05-16 15:28 UTC (permalink / raw)
  To: elfutils-devel

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

Mark Wielaard <mark at klomp dot org> changed:

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

--- Comment #6 from Mark Wielaard <mark at klomp dot org> ---
commit a117891a00507d188fdab415bd25554ace9ed7ba
Author: Mark Wielaard <mark@klomp.org>
Date:   Thu May 16 17:20:35 2019 +0200

    libdw: Add DW_AT_GNU_numerator, DW_AT_GNU_denominator and DW_AT_GNU_bias.

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

    Signed-off-by: Mark Wielaard <mark@klomp.org>

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

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

end of thread, other threads:[~2019-05-16 15:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-13 17:54 [Bug tools/24550] New: eu-readelf does not know about DW_AT_GNU_bias tromey at sourceware dot org
2019-05-14 18:36 ` [Bug tools/24550] eu-readelf does not know about DW_AT_GNU_{bias,numerator,denumerator} mark at klomp dot org
2019-05-15 16:13 ` tromey at sourceware dot org
2019-05-15 18:02 ` tromey at sourceware dot org
2019-05-15 18:17 ` tromey at sourceware dot org
2019-05-16 15:17 ` mark at klomp dot org
2019-05-16 15:28 ` 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).