From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id B56433947420 for ; Thu, 27 Jan 2022 17:15:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B56433947420 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 20RHElrL012762 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 27 Jan 2022 12:14:53 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 20RHElrL012762 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id A83091ECEB; Thu, 27 Jan 2022 12:14:47 -0500 (EST) Message-ID: <0597e6a6-e3ec-f496-3bbb-3444cd2f5ff5@polymtl.ca> Date: Thu, 27 Jan 2022 12:14:47 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH v2] gdb: work around negative DW_AT_data_member_location GCC 11 bug Content-Language: en-US To: Lancelot SIX Cc: gdb-patches@sourceware.org References: <20220126195547.1891750-1-simon.marchi@polymtl.ca> <20220126234600.c3jjbqwkwdazajpp@Plymouth> From: Simon Marchi In-Reply-To: <20220126234600.c3jjbqwkwdazajpp@Plymouth> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Thu, 27 Jan 2022 17:14:47 +0000 X-Spam-Status: No, score=-3039.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Jan 2022 17:15:58 -0000 On 2022-01-26 18:46, Lancelot SIX wrote: > Hi, > > I have minor comments below: > >> diff --git a/gdb/dwarf2/cu.c b/gdb/dwarf2/cu.c >> index 019165f6e6c5..20aecd4da4d6 100644 >> --- a/gdb/dwarf2/cu.c >> +++ b/gdb/dwarf2/cu.c >> @@ -31,7 +31,8 @@ dwarf2_cu::dwarf2_cu (dwarf2_per_cu_data *per_cu, >> has_loclist (false), >> checked_producer (false), >> producer_is_gxx_lt_4_6 (false), >> - producer_is_gcc_lt_4_3 (false), >> + producer_is_gcc_lt_4_3 (false), >> + producer_is_gcc_11 (false), > ^ > > You seem to be changing the indentation here (this changes 4 spaces for > 1 tab). Ah, thanks. That's what happens when you work on multiple projects in parallel, I had the wrong config loaded. >> producer_is_icc (false), >> producer_is_icc_lt_14 (false), >> producer_is_codewarrior (false), >> diff --git a/gdb/dwarf2/cu.h b/gdb/dwarf2/cu.h >> index 078479a56988..bce0a3de63a4 100644 >> --- a/gdb/dwarf2/cu.h >> +++ b/gdb/dwarf2/cu.h >> @@ -253,6 +253,7 @@ struct dwarf2_cu >> bool checked_producer : 1; >> bool producer_is_gxx_lt_4_6 : 1; >> bool producer_is_gcc_lt_4_3 : 1; >> + bool producer_is_gcc_11 : 1; >> bool producer_is_icc : 1; >> bool producer_is_icc_lt_14 : 1; >> bool producer_is_codewarrior : 1; >> diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c >> index f7cb95b40cba..1a749eac334f 100644 >> --- a/gdb/dwarf2/read.c >> +++ b/gdb/dwarf2/read.c >> @@ -14320,6 +14320,7 @@ check_producer (struct dwarf2_cu *cu) >> { >> cu->producer_is_gxx_lt_4_6 = major < 4 || (major == 4 && minor < 6); >> cu->producer_is_gcc_lt_4_3 = major < 4 || (major == 4 && minor < 3); >> + cu->producer_is_gcc_11 = major == 11; >> } >> else if (producer_is_icc (cu->producer, &major, &minor)) >> { >> @@ -14464,6 +14465,19 @@ handle_member_location (struct die_info *die, struct dwarf2_cu *cu, >> if (attr->form_is_constant ()) >> { >> LONGEST offset = attr->constant_value (0); >> + >> + /* Work around this GCC 11 bug, where it would erroneously use -1 >> + data member locations, instead of 0: >> + >> + Negative DW_AT_data_member_location >> + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101378 >> + */ >> + if (offset == -1 && cu->producer_is_gcc_11) >> + { >> + complaint (_("DW_AT_data_member_location value of -1, assuming 0")); >> + offset = 0; >> + } >> + >> field->set_loc_bitpos (offset * bits_per_byte); >> } >> else if (attr->form_is_section_offset ()) >> diff --git a/gdb/testsuite/gdb.dwarf2/negative-data-member-location.c b/gdb/testsuite/gdb.dwarf2/negative-data-member-location.c >> new file mode 100644 >> index 000000000000..4871b2f12036 >> --- /dev/null >> +++ b/gdb/testsuite/gdb.dwarf2/negative-data-member-location.c >> @@ -0,0 +1,29 @@ >> +/* Copyright (C) 2021 Free Software Foundation, Inc. > > The year needs to be updated to 2021-2022. Done. > >> + >> + This file is part of GDB. >> + >> + 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 . */ >> + >> +struct the_struct >> +{ >> + char x[4]; >> +}; >> + >> +struct the_struct s = { { 0x11, 0x22, 0x22, 0x11 } }; >> + >> +int >> +main (void) >> +{ >> + return 0; >> +} >> diff --git a/gdb/testsuite/gdb.dwarf2/negative-data-member-location.exp b/gdb/testsuite/gdb.dwarf2/negative-data-member-location.exp >> new file mode 100644 >> index 000000000000..9d05f208958b >> --- /dev/null >> +++ b/gdb/testsuite/gdb.dwarf2/negative-data-member-location.exp >> @@ -0,0 +1,77 @@ >> +# Copyright 2021 Free Software Foundation, Inc. > Same, update the year from 2021 to 2021-2022. Done. Simon