diff options
author | Tom de Vries <tdevries@suse.de> | 2022-07-11 11:36:54 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2022-07-11 11:36:54 +0200 |
commit | 53a7a7e17c5d21b7b182ddf6bd8bfc092af196f5 (patch) | |
tree | 5f9c61268e942a84c0e5ca8b19fc17586a8c422f /gdb/dwarf2/index-write.c | |
parent | a4ca6efe0589d0a030920a4686b692208c82a028 (diff) | |
download | gdb-53a7a7e17c5d21b7b182ddf6bd8bfc092af196f5.zip gdb-53a7a7e17c5d21b7b182ddf6bd8bfc092af196f5.tar.gz gdb-53a7a7e17c5d21b7b182ddf6bd8bfc092af196f5.tar.bz2 |
[gdb/symtab] Fix data race in per_cu->length
With gdb build with -fsanitize=thread and test-case
gdb.dwarf2/dw4-sig-types.exp and target board cc-with-dwz-m we run into a data
race between:
...
Write of size 4 at 0x7b2800002268 by thread T4:^M
#0 cutu_reader::cutu_reader(dwarf2_per_cu_data*, dwarf2_per_objfile*, \
abbrev_table*, dwarf2_cu*, bool, abbrev_cache*) gdb/dwarf2/read.c:6236 \
(gdb+0x82f525)^M
...
and this read:
...
Previous read of size 4 at 0x7b2800002268 by thread T1:^M
#0 dwarf2_find_containing_comp_unit gdb/dwarf2/read.c:23444 \
(gdb+0x86e22e)^M
...
In other words, between this write:
...
this_cu->length = cu->header.get_length ();
...
and this read:
...
&& mid_cu->sect_off + mid_cu->length > sect_off))
...
of per_cu->length.
Fix this similar to the per_cu->dwarf_version case, by only setting it if
needed, and otherwise verifying that the same value is used. [ Note that the
same code is already present in the other cutu_reader constructor. ]
Move this logic into into a member function set_length to make sure it's used
consistenly, and make the field private in order to enforce access through the
member functions, and rename it to m_length.
This exposes (running test-case gdb.dwarf2/fission-reread.exp) that in
fill_in_sig_entry_from_dwo_entry, the m_length field is overwritten.
For now, allow for that exception.
While we're at it, make sure that the length is set before read.
Tested on x86_64-linux.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29344
Diffstat (limited to 'gdb/dwarf2/index-write.c')
-rw-r--r-- | gdb/dwarf2/index-write.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index c3aad8d..efd154d 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -1214,7 +1214,7 @@ write_gdbindex (dwarf2_per_objfile *per_objfile, sig_type->signature); } else - cu_list.append_uint (8, BFD_ENDIAN_LITTLE, per_cu->length); + cu_list.append_uint (8, BFD_ENDIAN_LITTLE, per_cu->length ()); ++this_counter; } |