From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074104.outbound.protection.outlook.com [40.92.74.104]) by sourceware.org (Postfix) with ESMTPS id 99B83385BF83 for ; Mon, 6 Apr 2020 18:48:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 99B83385BF83 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=hotmail.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bernd.edlinger@hotmail.de ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ezxappI4YFWfcJ+FkJXrA1dItd2lviNON46Bsi7jSI6lL4Cqw3FcBxwYu94D6xxuznl1kdmxLqOmN/Gu9gU9mLUTSHkQFslXfvR0N1SPR/vM9udigjuIMe51xNzABmCtCzQ6AnhLejx8VY2O9exzDQDZ1fE6ZD1WeotOhbHDCj1CTbv8RUuD1rynCATxw7c0U0zWGT0TGZV7hZ/WPJrOdOZTFvsj6VhzpPRj5U4kUuEjAsQ09tIu4oS/sDQi57MAWmrB28M4arYEP3yh1I8hQTMFyy+E60CDFk6mw1QDFiTkkMO1kD52SluhVlm/Mvpma/WTQoH+nW0LkJBVGNWNPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9VQhWfSwQ17fv1bq7BmUo9lKC7s1uIcAm5n+C7h6JqE=; b=nOwdKt7NasNa9X8S6WtAuLEFKsF738Ap6gfwzcn6/gDT5M57UsbYu/BQL0FfzzbyPZzaqTgqe9QEdzeoROUjdXpZZ+VXRygj8wslFuSYluKM9D1vG8Z49WfhwuXvnjcWCBtNnvU4C5sx+eLxsG0wW1zQ4pq3lmxKvBOldrm/vBXL3roygxm6QOXZ6ROqBl3AVuuAspPioEzENN96ovaxmJ8wkzd/5hncOPupZy18uGkMp7A5WrL7yTEdAeyz+ENn0kLPpegEvI7LKN6NtNbOtGdWy0852F8dh8JqCJf1JPlGySMUPkMUqtDEXUr6dGlW1Hgb0YK9r5lvnr2Swx2RnA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=hotmail.de; dmarc=pass action=none header.from=hotmail.de; dkim=pass header.d=hotmail.de; arc=none Received: from DB3EUR04FT038.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0c::4d) by DB3EUR04HT236.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0c::137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2878.15; Mon, 6 Apr 2020 18:48:43 +0000 Received: from AM6PR03MB5170.eurprd03.prod.outlook.com (2a01:111:e400:7e0c::4c) by DB3EUR04FT038.mail.protection.outlook.com (2a01:111:e400:7e0c::462) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2878.15 via Frontend Transport; Mon, 6 Apr 2020 18:48:43 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:36F472407A900780A2AC6C93C0367F04E7C01BB799BAAEA2C09DFDDC4D23C066; UpperCasedChecksum:1D90F182FE25F43E98F3B8104DEA165824DCF95C5016D1DAB430F62D15CC99DB; SizeAsReceived:8069; Count:50 Received: from AM6PR03MB5170.eurprd03.prod.outlook.com ([fe80::d57:5853:a396:969d]) by AM6PR03MB5170.eurprd03.prod.outlook.com ([fe80::d57:5853:a396:969d%7]) with mapi id 15.20.2878.018; Mon, 6 Apr 2020 18:48:43 +0000 Subject: Re: [PATCH v3 2/2] Fix an undefined behavior in record_line To: Andrew Burgess Cc: "gdb-patches@sourceware.org" References: <20200404230327.GD3917@embecosm.com> <20200406174413.GB2524@embecosm.com> From: Bernd Edlinger Message-ID: Date: Mon, 6 Apr 2020 20:48:41 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 In-Reply-To: <20200406174413.GB2524@embecosm.com> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: AM4PR08CA0047.eurprd08.prod.outlook.com (2603:10a6:205:2::18) To AM6PR03MB5170.eurprd03.prod.outlook.com (2603:10a6:20b:ca::23) X-Microsoft-Original-Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.1.101] (92.77.140.102) by AM4PR08CA0047.eurprd08.prod.outlook.com (2603:10a6:205:2::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2878.15 via Frontend Transport; Mon, 6 Apr 2020 18:48:42 +0000 X-Microsoft-Original-Message-ID: X-TMN: [/I05clhB0bL9c2XRhVEvjWOKMfdhzZpr] X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 387b1778-696f-4f41-5d63-08d7da5b215f X-MS-TrafficTypeDiagnostic: DB3EUR04HT236: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AgR/XaEs579y5UGfo1jagHtF2zpN5SaSlA3J9l8tCufNo87Xu5TsNQF01UcLQv0WMVWAZJc8DkJj2mXEtcimiuxzuxDfxBUDwbmlpWizthTUkEncl00KciTzqiqSSDdIC6Iroaes/6roYxXHqn68u0+RW535de1BJDpo3TUxXaVyMyTPRnsR/ztdNLsT3sWS X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:0; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR03MB5170.eurprd03.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:; DIR:OUT; SFP:1901; X-MS-Exchange-AntiSpam-MessageData: ouBGJjaX9C3tfUqWQopeIQpHRD/rRywBiEZQcaG/mkMBJU1vE/LkUXsrgK/FkjpsojamhmfEQXypRTUzVWzkyjkS5fcmYmYkyQbcarqYnU6F1FcxMiKmAMmdMGqV4u+79Rx+2ILGY2+eZGgMbohyJw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 387b1778-696f-4f41-5d63-08d7da5b215f X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Apr 2020 18:48:43.5710 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3EUR04HT236 X-Spam-Status: No, score=-17.0 required=5.0 tests=BAYES_00, FORGED_MUA_MOZILLA, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_DMARC_STATUS, MSGID_FROM_MTA_HEADER, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Mon, 06 Apr 2020 18:48:46 -0000 Hi Andrew, On 4/6/20 7:44 PM, Andrew Burgess wrote: > * Andrew Burgess [2020-04-05 00:03:27 +0100]: > Hmm, I overlooked this mail in my inbox. Sorry, I had a very difficul discussion with Linus Torvalds at that weekend. So I was not able to look at all messages, and this one dropped. Sorry for that. >> * Bernd Edlinger [2020-03-27 04:50:29 +0100]: >> >>> Additionally do not completely remove symbols >>> at the same PC than the end marker, instead >>> make them non-is-stmt breakpoints. >>> >>> 2020-03-27 Bernd Edlinger >>> * buildsym.c (record_line): Fix undefined behavior and preserve >>> lines at eof. >>> --- >>> gdb/buildsym.c | 34 ++++++++++++++++++---------------- >>> 1 file changed, 18 insertions(+), 16 deletions(-) >>> >>> diff --git a/gdb/buildsym.c b/gdb/buildsym.c >>> index 2d1e441..46c5bb1 100644 >>> --- a/gdb/buildsym.c >>> +++ b/gdb/buildsym.c >>> @@ -705,27 +705,29 @@ struct blockvector * >>> * sizeof (struct linetable_entry)))); >>> } >>> >>> - /* Normally, we treat lines as unsorted. But the end of sequence >>> - marker is special. We sort line markers at the same PC by line >>> - number, so end of sequence markers (which have line == 0) appear >>> - first. This is right if the marker ends the previous function, >>> - and there is no padding before the next function. But it is >>> - wrong if the previous line was empty and we are now marking a >>> - switch to a different subfile. We must leave the end of sequence >>> - marker at the end of this group of lines, not sort the empty line >>> - to after the marker. The easiest way to accomplish this is to >>> - delete any empty lines from our table, if they are followed by >>> - end of sequence markers. All we lose is the ability to set >>> - breakpoints at some lines which contain no instructions >>> - anyway. */ >>> + /* The end of sequence marker is special. We need to reset the >>> + is_stmt flag on previous lines at the same PC, otherwise these >>> + lines may cause problems since they might be at the same address >>> + as the following function. For instance suppose a function calls >>> + abort there is no reason to emit a ret after that point (no joke). >>> + So the label may be at the same address where the following >>> + function begins. A similar problem appears if a label is at the >>> + same address where an inline function ends we cannot reliably tell >>> + if this is considered part of the inline function or the calling >>> + program or even the next inline function, so stack traces may >>> + give surprising results. Expect gdb.cp/step-and-next-inline.exp >>> + to fail if these lines are not modified here. */ >> >> Out of interest I tried reverting this patch and don't see any >> failures in gdb.cp/step-and-next-inline.exp. Could you expand on >> which tests specifically you expect to see fail, and maybe which >> version of GCC you're using? I'm on 9.3.1. It'll be Monday before I >> can try my other machine which has a wider selection of compiler >> versions. >> >> I also don't understand what part of the previous behaviour was >> undefined, could you help me to understand please. Sorry, as I said, I overlooked this mail, I am rather under stress, since I have to take precautions for my safety and my family all the time, you know we have a corona pandemic out there. It is decrementing e before the beginning of the array, that is undefined. The code before, with the undefined behavior was this: e = subfile->line_vector->item + subfile->line_vector->nitems - 1; while (subfile->line_vector->nitems > 0 && e->pc == pc) { e--; subfile->line_vector->nitems--; } So when you start e = pointer + nitems - 1; decrement each time e and nitems by one. and the exit condition is nitems > 0 or e -> pc == pc. What happens when there is no element with pc == pc, then the exit condition is when nitems = 0 and e = pointer - 1; since e is now before the beginning of the array, gcc can assume you guarantee that this undefined behavior is not happening so you guarantee the e-> pc == pc is the only exit condition where no undefined behavior happens. so gcc can and will transform that loop to: e = subfile->line_vector->item + subfile->line_vector->nitems - 1; while (e->pc == pc) { e--; subfile->line_vector->nitems--; } That has already happened, in the gmp test suite if I remember correctly. > > I reverted this patch and tested with GCC versions: > That part of the patch was a gratuitous fix, I have been testing it twice before committing, but since Luis notified me of the regression in aarch64 I became aware that changing the is-stmt bits causes real problems and I wanted to fix that with the other patch, but I can also make that an extra patch, if that is necessary. > 10.x - from 2020-02-05 - no regressions, > 9.3.1 - (from previous) - no regressions, > 9.2.0 - no regressions, > 8.3.0 - no regressions, > 7.4.0 - doesn't compile as the compiler doesn't support > '-gstatement-frontiers.'. > > The 7.4.0 result seems to indicate that the test doesn't apply for > compilers before then. > > So, what exactly does this patch fix? Or what new functionality does > it bring to GDB? Or what version of GCC should I use and expect to > see a difference in the test results? > Undefined behavior, and I need to really remove the lines at the end of the function. That behavior we need to restore. I would like to not do the destructive step when the cu changes, that is probably wrong, and causes the missing lines that your other patch is trying to fix. Thanks, Bernd. PS: what is T-J-Teru ?