From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id AC2703858D1E for ; Fri, 10 Nov 2023 03:12:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AC2703858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AC2703858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699585971; cv=none; b=YSg0GHSR5Q4D6Y7jCLMSV4mdrzLMGodXOVXkwzFrfiAx0B392N6X68WPodVOxdBO/WlpVkFHVzTzg5Chdyu7gy39mmCKRyr+aNg9ZD7Rf/fQNBlAuvRqAgQFbVrwe411z+VtXwQo1pK4A0QDYRvzquQheensiALjY36PyRF6/pk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699585971; c=relaxed/simple; bh=Y0LX96C2vV9wuq0XCH9gDegYGm/CMTqAICOEmVUHSXk=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=sbhOeB/vdgSTtd+btnGwojVNGm3ej3H0aW4Ktnf+Y+dgvnca4KkGG7pMXk4F8G9/dyR17ntec9XICqRlM2FaCcHjIOM3QqqSEa7E4iKyR//kWv6nlVLppKrZgFQn4NeGPEqE8scBLXbf6518HrcEYb6Gu6XX0IPcNGm9UWbqlDM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1699585970; bh=Y0LX96C2vV9wuq0XCH9gDegYGm/CMTqAICOEmVUHSXk=; h=Date:Subject:To:References:From:In-Reply-To:From; b=ktR5XSKEZ9rfx0sxLS5kxISSVfyX5BvNDdXH8tCPk9vnH/wN57PXd0y+ps12hky80 7nd1KuC1IGSMK+bzr34lrTT8gWn4vf5Mg1V3P/X1aCDqu252EfA/61/UamyfVCHEZs Efm1BCbbrMosP8AgxldtBt8Xf7AsuTBcd5n/9PxY= Received: from [10.0.0.11] (modemcable238.237-201-24.mc.videotron.ca [24.201.237.238]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 039501E00F; Thu, 9 Nov 2023 22:12:49 -0500 (EST) Message-ID: Date: Thu, 9 Nov 2023 22:12:44 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: potential bug in pv_subtract in prologue-value.c Content-Language: en-US To: CF Bolz-Tereick , gdb@sourceware.org References: <95ecebf4-d1a5-4628-aa4f-26b6ce389427@gmx.de> From: Simon Marchi In-Reply-To: <95ecebf4-d1a5-4628-aa4f-26b6ce389427@gmx.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2023-11-06 10:19, CF Bolz-Tereick via Gdb wrote: > Hi all! > > this is pretty random, but I was reading some code in prologue-value.c > out of curiosity, and spotted something that looked rather > suspicious/buggy to me. isn't the call to constant_last in pv_subtract > wrong? constant_last potentially swaps the arguments of pv_subtract, > which looks wrong, because subtraction is not commutative: > > https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gdb/prologue-value.c;h=13bf4362069e99301dba7d99f039f547768b264d;hb=HEAD#l128 > > This is of course a very theoretical bug, I would suspect it's pretty > hard to demonstrate this problem in any "real" machine code that is > thrown at prologue analysis on one of the platforms that uses it. but > I'd be happy to write a patch with a fix and a unit test if somebody > else finds it weird too. > > Cheers, > > CF Hi, I was not familiar with prologue values until now (never had to deal with them). But indeed, I find that strange as well. Since this code seems to not have any external dependency, it should be fairly easy to write unit tests in the form of selftests (search for selftests::register_test in the code base to see examples) and prove that something is wrong. If you are up for the challenge, you could also try to hand-write an assembly program for an architecture that uses pv_subtract, like AArch64, to try to hit that code path. Simon