GNU bug report logs - #38369
Guile 2.9.5 miscompiles crc32 procedure

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: guile; Reported by: Ludovic Courtès <ludo@HIDDEN>; dated Mon, 25 Nov 2019 21:33:40 UTC; Maintainer for guile is bug-guile@HIDDEN.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 25 Nov 2019 12:58:10 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Nov 25 07:58:10 2019
Received: from localhost ([127.0.0.1]:47862 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1iZDwP-0005Y3-J3
	for submit <at> debbugs.gnu.org; Mon, 25 Nov 2019 07:58:09 -0500
Received: from lists.gnu.org ([209.51.188.17]:49370)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <ludo@HIDDEN>) id 1iZDqa-0005JQ-Ue
 for submit <at> debbugs.gnu.org; Mon, 25 Nov 2019 07:52:09 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10]:48124)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <ludo@HIDDEN>) id 1iYyvS-0006zZ-OD
 for bug-Guile@HIDDEN; Sun, 24 Nov 2019 15:56:12 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=-1.5 required=5.0 tests=ALL_TRUSTED,BAYES_05
 autolearn=disabled version=3.3.2
Received: from fencepost.gnu.org ([2001:470:142:3::e]:52683)
 by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <ludo@HIDDEN>)
 id 1iYyvS-0007E6-KM
 for bug-Guile@HIDDEN; Sun, 24 Nov 2019 15:56:10 -0500
Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=38422 helo=ribbon)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <ludo@HIDDEN>) id 1iYyvR-0006Gh-He
 for bug-Guile@HIDDEN; Sun, 24 Nov 2019 15:56:10 -0500
From: =?utf-8?Q?Ludovic_Court=C3=A8s?= <ludo@HIDDEN>
To: bug-Guile@HIDDEN
Subject: Guile 2.9.5 miscompiles crc32 procedure
X-Debbugs-Cc: Andy Wingo <wingo@HIDDEN>
X-URL: http://www.fdn.fr/~lcourtes/
X-Revolutionary-Date: 4 Frimaire an 228 de la =?utf-8?Q?R=C3=A9volution?=
X-PGP-Key-ID: 0x090B11993D9AEBB5
X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc
X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4  0CFB 090B 1199 3D9A EBB5
X-OS: x86_64-pc-linux-gnu
Date: Sun, 24 Nov 2019 21:56:07 +0100
Message-ID: <871rtxyowo.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

The (guix build debug-link) module has this function:

--8<---------------cut here---------------start------------->8---
(define %crc32-table
  ;; CRC table taken from "(gdb) Separate Debug Files".
  ;; TODO: Wouldn't it be nice to generate it "from source" with a macro?
  #(#x00000000 #x77073096 #xee0e612c #x990951ba #x076dc419
    #x706af48f #xe963a535 #x9e6495a3 #x0edb8832 #x79dcb8a4
    #xe0d5e91e #x97d2d988 #x09b64c2b #x7eb17cbd #xe7b82d07
    #x90bf1d91 #x1db71064 #x6ab020f2 #xf3b97148 #x84be41de
    #x1adad47d #x6ddde4eb #xf4d4b551 #x83d385c7 #x136c9856
    #x646ba8c0 #xfd62f97a #x8a65c9ec #x14015c4f #x63066cd9
    #xfa0f3d63 #x8d080df5 #x3b6e20c8 #x4c69105e #xd56041e4
    #xa2677172 #x3c03e4d1 #x4b04d447 #xd20d85fd #xa50ab56b
    #x35b5a8fa #x42b2986c #xdbbbc9d6 #xacbcf940 #x32d86ce3
    #x45df5c75 #xdcd60dcf #xabd13d59 #x26d930ac #x51de003a
    #xc8d75180 #xbfd06116 #x21b4f4b5 #x56b3c423 #xcfba9599
    #xb8bda50f #x2802b89e #x5f058808 #xc60cd9b2 #xb10be924
    #x2f6f7c87 #x58684c11 #xc1611dab #xb6662d3d #x76dc4190
    #x01db7106 #x98d220bc #xefd5102a #x71b18589 #x06b6b51f
    #x9fbfe4a5 #xe8b8d433 #x7807c9a2 #x0f00f934 #x9609a88e
    #xe10e9818 #x7f6a0dbb #x086d3d2d #x91646c97 #xe6635c01
    #x6b6b51f4 #x1c6c6162 #x856530d8 #xf262004e #x6c0695ed
    #x1b01a57b #x8208f4c1 #xf50fc457 #x65b0d9c6 #x12b7e950
    #x8bbeb8ea #xfcb9887c #x62dd1ddf #x15da2d49 #x8cd37cf3
    #xfbd44c65 #x4db26158 #x3ab551ce #xa3bc0074 #xd4bb30e2
    #x4adfa541 #x3dd895d7 #xa4d1c46d #xd3d6f4fb #x4369e96a
    #x346ed9fc #xad678846 #xda60b8d0 #x44042d73 #x33031de5
    #xaa0a4c5f #xdd0d7cc9 #x5005713c #x270241aa #xbe0b1010
    #xc90c2086 #x5768b525 #x206f85b3 #xb966d409 #xce61e49f
    #x5edef90e #x29d9c998 #xb0d09822 #xc7d7a8b4 #x59b33d17
    #x2eb40d81 #xb7bd5c3b #xc0ba6cad #xedb88320 #x9abfb3b6
    #x03b6e20c #x74b1d29a #xead54739 #x9dd277af #x04db2615
    #x73dc1683 #xe3630b12 #x94643b84 #x0d6d6a3e #x7a6a5aa8
    #xe40ecf0b #x9309ff9d #x0a00ae27 #x7d079eb1 #xf00f9344
    #x8708a3d2 #x1e01f268 #x6906c2fe #xf762575d #x806567cb
    #x196c3671 #x6e6b06e7 #xfed41b76 #x89d32be0 #x10da7a5a
    #x67dd4acc #xf9b9df6f #x8ebeeff9 #x17b7be43 #x60b08ed5
    #xd6d6a3e8 #xa1d1937e #x38d8c2c4 #x4fdff252 #xd1bb67f1
    #xa6bc5767 #x3fb506dd #x48b2364b #xd80d2bda #xaf0a1b4c
    #x36034af6 #x41047a60 #xdf60efc3 #xa867df55 #x316e8eef
    #x4669be79 #xcb61b38c #xbc66831a #x256fd2a0 #x5268e236
    #xcc0c7795 #xbb0b4703 #x220216b9 #x5505262f #xc5ba3bbe
    #xb2bd0b28 #x2bb45a92 #x5cb36a04 #xc2d7ffa7 #xb5d0cf31
    #x2cd99e8b #x5bdeae1d #x9b64c2b0 #xec63f226 #x756aa39c
    #x026d930a #x9c0906a9 #xeb0e363f #x72076785 #x05005713
    #x95bf4a82 #xe2b87a14 #x7bb12bae #x0cb61b38 #x92d28e9b
    #xe5d5be0d #x7cdcefb7 #x0bdbdf21 #x86d3d2d4 #xf1d4e242
    #x68ddb3f8 #x1fda836e #x81be16cd #xf6b9265b #x6fb077e1
    #x18b74777 #x88085ae6 #xff0f6a70 #x66063bca #x11010b5c
    #x8f659eff #xf862ae69 #x616bffd3 #x166ccf45 #xa00ae278
    #xd70dd2ee #x4e048354 #x3903b3c2 #xa7672661 #xd06016f7
    #x4969474d #x3e6e77db #xaed16a4a #xd9d65adc #x40df0b66
    #x37d83bf0 #xa9bcae53 #xdebb9ec5 #x47b2cf7f #x30b5ffe9
    #xbdbdf21c #xcabac28a #x53b39330 #x24b4a3a6 #xbad03605
    #xcdd70693 #x54de5729 #x23d967bf #xb3667a2e #xc4614ab8
    #x5d681b02 #x2a6f2b94 #xb40bbe37 #xc30c8ea1 #x5a05df1b
    #x2d02ef8d))

(define (debuglink-crc32 port)
  "Compute the 32-bit CRC used in in '.gnu_debuglink' over the data read fr=
om
PORT and return it."                      ;(info "(gdb) Separate Debug File=
s")
  (let loop ((crc #xffffffff))
    (let ((byte (get-u8 port)))
      (if (eof-object? byte)
          (logand (lognot crc) #xffffffff)
          (let* ((index (logand (logxor crc byte) #xff))
                 (lhs   (vector-ref %crc32-table index)))
            (loop (logxor lhs (ash crc -8))))))))
--8<---------------cut here---------------end--------------->8---

The valid result is:

--8<---------------cut here---------------start------------->8---
scheme@(guix build debug-link)> (debuglink-crc32 (open-input-string "a"))
$5 =3D 3904355907
scheme@(guix build debug-link)> (version)
$6 =3D "2.2.6"
--8<---------------cut here---------------end--------------->8---

The incorrect result is:

--8<---------------cut here---------------start------------->8---
scheme@(guix build debug-link)> (debuglink-crc32 (open-input-string "a"))
$9 =3D 397917763
scheme@(guix build debug-link)> (version)
$10 =3D "2.9.5"
--8<---------------cut here---------------end--------------->8---

When adding =E2=80=98pk=E2=80=99 calls, I see that (ash crc -8) returns crc=
 as-is.

Thoughts?

The interpreter gets it right:

--8<---------------cut here---------------start------------->8---
scheme@(guix build debug-link)> ,o interp #t
scheme@(guix build debug-link)> (define (debuglink-crc32 port)
  "Compute the 32-bit CRC used in in '.gnu_debuglink' over the data read fr=
om
PORT and return it."                      ;(info "(gdb) Separate Debug File=
s")
  (let loop ((crc #xffffffff))
    (let ((byte (get-u8 port)))
      (if (eof-object? byte)
          (logand (lognot crc) #xffffffff)
          (let* ((index (logand (logxor crc byte) #xff))
                 (lhs   (vector-ref %crc32-table index)))
            (loop (logxor lhs (ash crc -8))))))))

scheme@(guix build debug-link)> (debuglink-crc32 (open-input-string "a"))
$13 =3D 3904355907
scheme@(guix build debug-link)> (version)
$14 =3D "2.9.5"
--8<---------------cut here---------------end--------------->8---

Ludo=E2=80=99.




Acknowledgement sent to Ludovic Courtès <ludo@HIDDEN>:
New bug report received and forwarded. Copy sent to wingo@HIDDEN, bug-guile@HIDDEN. Full text available.
Report forwarded to wingo@HIDDEN, bug-guile@HIDDEN:
bug#38369; Package guile. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 25 Nov 2019 21:45:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.