public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: CF Bolz-Tereick <cfbolz@gmx.de>, gdb@sourceware.org
Subject: Re: potential bug in pv_subtract in prologue-value.c
Date: Thu, 9 Nov 2023 22:12:44 -0500	[thread overview]
Message-ID: <ab7d2e63-9ffd-4b76-8e02-ac1b97e6cdba@simark.ca> (raw)
In-Reply-To: <95ecebf4-d1a5-4628-aa4f-26b6ce389427@gmx.de>



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

      reply	other threads:[~2023-11-10  3:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-06 15:19 CF Bolz-Tereick
2023-11-10  3:12 ` Simon Marchi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ab7d2e63-9ffd-4b76-8e02-ac1b97e6cdba@simark.ca \
    --to=simark@simark.ca \
    --cc=cfbolz@gmx.de \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).