[Bug,default/28060] Invalid offset for bitfields

Message ID bug-28060-9487-9EvVrXibEt@http.sourceware.org/bugzilla/
State New
Series [Bug,default/28060] Invalid offset for bitfields |

Commit Message

dodji at seketeli dot org July 8, 2021, 9:34 a.m. UTC

gprocida at google dot com changed:

           What    |Removed                     |Added
                 CC|                            |gprocida at google dot com

--- Comment #2 from gprocida at google dot com ---
The problem is in abidw, not abidiff.

I'm guessing that both DW_AT_data_member_location and DW_AT_data_bit_offset
need to be taken into consideration, not just one of them.

The problem exists with -gdwarf-3 and -gdwarf-4, but not -gdwarf-5.

$ head test.{0,1}.c
==> test.0.c <==
#include <inttypes.h>

struct bigstruct {
  char name[128];
  uint8_t bitfield0:1;

uint8_t foo(const struct bigstruct * big) { return big->bitfield0; }

==> test.1.c <==
#include <inttypes.h>

struct bigstruct {
  char name[128];
  uint8_t bitfield0:1;
  uint8_t bitfield1:1;

uint8_t foo(const struct bigstruct * big) { return big->bitfield0; }
$ for i in 0 1; do gcc -Wall -Wextra -g -c test.$i.c; abidw --no-show-locs
test.$i.o > test.$i.xml; done
$ diff -u test.{0,1}.xml
     <type-decl name='char' size-in-bits='8' id='type-id-1'/>
     <array-type-def dimensions='1' type-id='type-id-1' size-in-bits='1024'
       <subrange length='128' type-id='type-id-3' id='type-id-4'/>
@@ -18,6 +18,9 @@
       <data-member access='public' layout-offset-in-bits='0'>
         <var-decl name='bitfield0' type-id='type-id-7' visibility='default'/>
+      <data-member access='public' layout-offset-in-bits='1'>
+        <var-decl name='bitfield1' type-id='type-id-7' visibility='default'/>
+      </data-member>
     <qualified-type-def type-id='type-id-8' const='yes' id='type-id-9'/>
     <pointer-type-def type-id='type-id-9' size-in-bits='64' id='type-id-10'/>


--- test.0.xml  2021-07-08 10:21:30.460919575 +0100
+++ test.1.xml  2021-07-08 10:21:30.516919874 +0100
@@ -1,8 +1,8 @@ 
-<abi-corpus version='2.0' path='test.0.o' architecture='elf-amd-x86_64'>
+<abi-corpus version='2.0' path='test.1.o' architecture='elf-amd-x86_64'>
     <elf-symbol name='foo' type='func-type' binding='global-binding'
visibility='default-visibility' is-defined='yes'/>
-  <abi-instr address-size='64' path='test.0.c'
+  <abi-instr address-size='64' path='test.1.c'