The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: Ralph Corderoy <ralph@inputplus.co.uk>
To: tuhs@tuhs.org
Subject: Re: [TUHS] OT: compiler back-end bug
Date: Sun, 29 Sep 2019 11:50:16 +0100	[thread overview]
Message-ID: <20190929105016.92665200AB@orac.inputplus.co.uk> (raw)
In-Reply-To: <20190929100336.GA2390@minnie.tuhs.org>

Hi Warren,

> Good point Ralph:
> https://minnie.tuhs.org/wktcloud/index.php/s/HQjsggHb4i6wdWM?path=%2FSfiles

I've always tried to avoid x86 and friends for ARM, so I may be wrong,
but the run up to the first of the two memcpy() calls looks the same to
me.  Here's the assembler, values given an RBP of 100, and the stack
contents.  Good version first, bad second.

                                rbp = 100
    L29:
        movq  -8(%rbp),%rax     rax = *92
        pushq %rax                                            *92
        movq  16(%rbp),%rax     rax = *116
        pushq %rax                                            *92 *116
        movq  $64,%rax          rax = 64
        pushq %rax                                            *92 *116 64
        movq  32(%rbp),%rax     rax = *132
        popq  %rcx              rcx = 64                      *92 *116
        addq  %rcx,%rax         rcx = 64+*132
        movq  (%rax),%rax       rax = *(64+*132)
        pushq %rax                                            *92 *116 *(64+*132)
        movq  $40,%rax          rax = 40
        pushq %rax                                            *92 *116 *(64+*132) 40
        movq  32(%rbp),%rax     rax = *132
        popq  %rcx              rcx = 40                      *92 *116 *(64+*132)
        addq  %rcx,%rax         rax = 40+*132
        movq  (%rax),%rax       rax = *(40+*132)
        popq  %rcx              rcx = *(64+*132)              *92 *116
        addq  %rcx,%rax         rax = *(64+*132)+*(40+*132)
        pushq %rax                                            *92 *116 *(64+*132)+*(40+*132)
        call  Cmemcpy

                                rbp = 100
    L29:
        movq  -8(%rbp),%r8      r8 = *92
        pushq %r8                                             *92
        movq  16(%rbp),%r8      r8 = *116
        pushq %r8                                             *92 *116
        movq  $64,%r8           r8 = 64
        movq  32(%rbp),%r9      r9 = *132
        addq  %r9,%r8           r8 = *132+64
        movq  (%r8),%r8         r8 = *(*132+64)
        movq  $40,%r9           r9 = 40
        movq  32(%rbp),%r10     r10 = *132
        addq  %r10,%r9          r9 = *132+40
        movq  (%r9),%r9         r9 = *(*132+40)
        addq  %r9,%r8           r8 = *(*132+64)+*(*132+40)
        pushq %r8                                             *92 *116 *(*132+64)+*(*132+40)
        call  Cmemcpy

A glance at the second memcpy() call look equivalent too.

So perhaps it's not calculating the parameters to memcpy() that's wrong,
but the inputs into those calculations being faulty?  I'd use gdb(1) to
break at particular instructions, examine memory, etc., to work
backwards through the bad version until spotting where good data becomes
bad.

-- 
Cheers, Ralph.

  reply	other threads:[~2019-09-29 10:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-29  9:21 Warren Toomey
2019-09-29  9:47 ` Ralph Corderoy
2019-09-29 10:03   ` Warren Toomey
2019-09-29 10:50     ` Ralph Corderoy [this message]
2019-10-03 20:03       ` Steve Johnson
2019-10-03 20:03         ` Nemo Nusquam

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=20190929105016.92665200AB@orac.inputplus.co.uk \
    --to=ralph@inputplus.co.uk \
    --cc=tuhs@tuhs.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 NNTP newsgroup(s).