]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb] Fix data race in bitfield
authorTom de Vries <tdevries@suse.de>
Fri, 15 Jul 2022 16:08:50 +0000 (18:08 +0200)
committerTom de Vries <tdevries@suse.de>
Thu, 21 Jul 2022 13:06:40 +0000 (15:06 +0200)
Data race between:
...
  Write of size 4 at 0x7b8009b483f0 by thread T2:
    #0 set_type_align(type*, unsigned long) /home/vries/gdb_versions/devel/src/gdb/gdbtypes.c:3751 (gdb+0x961e08)
...
and:
...
  Previous read of size 1 at 0x7b8009b483f1 by thread T4:
    #0 type::instance_flags() const /home/vries/gdb_versions/devel/src/gdb/gdbtypes.h:1092 (gdb+0x59e74b)
...
corresponding to:
...
  unsigned align_log2 : TYPE_ALIGN_BITS;
  unsigned m_instance_flags : 9;
...

Fix this by wrapping them using "struct { ... };".

For now, don't worry about size increase, we might have to address this later
using packed.

Still, is this a correct fix?  Maybe the problem is modifying a type from
different thread.  If so, having this patch for now may expose that problem.

gdb/gdbtypes.h

index 3a4d644d671b42dd6a4c7d6fe104b5710c3b9ef3..751f21b206f1c02eee452d84184131cdd5898770 100644 (file)
@@ -1488,7 +1488,9 @@ struct type
      value of 1 means the alignment is 1, and a value of 9 means the
      alignment is 256.  */
 
-  unsigned align_log2 : TYPE_ALIGN_BITS;
+  struct {
+    unsigned align_log2 : TYPE_ALIGN_BITS;
+  };
 
   /* * Flags specific to this instance of the type, indicating where
      on the ring we are.
@@ -1500,7 +1502,9 @@ struct type
      instance flags are completely inherited from the target type.  No
      qualifiers can be cleared by the typedef.  See also
      check_typedef.  */
-  unsigned m_instance_flags : 9;
+  struct {
+    unsigned m_instance_flags : 9;
+  };
 
   /* * Length of storage for a value of this type.  The value is the
      expression in host bytes of what sizeof(type) would return.  This