GNU bug report logs - #74296
[PATCH 0/1] Fix abi mismatch error on boot for cross-compiled images

Previous Next

Package: guix-patches;

Reported by: Christoph Buck <dev <at> icepic.de>

Date: Sun, 10 Nov 2024 17:42:02 UTC

Severity: normal

Tags: patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 74296 in the body.
You can then email your comments to 74296 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix <at> cbaines.net, dev <at> jpoiret.xyz, ludo <at> gnu.org, othacehe <at> gnu.org, zimon.toutoune <at> gmail.com, me <at> tobias.gr, guix-patches <at> gnu.org:
bug#74296; Package guix-patches. (Sun, 10 Nov 2024 17:42:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Christoph Buck <dev <at> icepic.de>:
New bug report received and forwarded. Copy sent to guix <at> cbaines.net, dev <at> jpoiret.xyz, ludo <at> gnu.org, othacehe <at> gnu.org, zimon.toutoune <at> gmail.com, me <at> tobias.gr, guix-patches <at> gnu.org. (Sun, 10 Nov 2024 17:42:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Christoph Buck <dev <at> icepic.de>
To: guix-patches <at> gnu.org
Cc: Christoph Buck <dev <at> icepic.de>
Subject: [PATCH 0/1] Fix abi mismatch error on boot for cross-compiled images
Date: Sun, 10 Nov 2024 17:43:39 +0100
Hi!

The following patch fixes the `record-abi-mismatch-error` early on boot during
execution of initrd.cpio.gz if the image was cross-compiled on x64 for an
32bit platform (e.g arm32 or i868).

For a comprehensive analysis see the correspond thread [1] on the guix-help
mailing list.

The root cause of the issue is as follows:

During compilation guix stores a hash of the record field names in the
compiled go files. On runtime this has is recalcuated and checked against the
stored hash to verify that no abi mismatch occured. As described in [1] this
hash differs if the corresponding record was compiled in a cross-compiled
context. Guile uses internally an `unsigned long` to store the hash, which
results in hashes of different sizes depending on the platform the guile
compiler is executed on. Guix already tries to work around this problem by
limiting the size of the hash in a cross-compile context to the most positive
fixnum size of the target, but this is insufficient, because, as one can look
up in the guile source code, the size is limited by an modulo operation after
the hash was already calculated for an 8byte unsigned long. Therefore the
resulting hashes during compilation and execution are different and an abi
mismatch error is erroneously reported during runtime.

An easy workaround is documented in the guile src namely in an comment of the
`JENKINS_LOOKUP3_HASHWORD2`, which is used to calculate the hash:

> Scheme can access symbol-hash, which exposes this value. For
>cross-compilation reasons, we ensure that the high 32 bits of the hash on a
>64-bit system are equal to the hash on a 32-bit system.  The low 32 bits just
>add more entropy.

This suggest the following workaround. Always limit the hash size to 32bit
even if executed on a 64bit platform (or to be more specific a platform where
ulong is 8bytes big). Do this by right shift the hash value 32bits and don't
rely on the size parameter of the `string-hash` function. This is what this
patch tries to accomplish.

Imho this approach has two drawbacks. Lost entropy on 64 bit machines and the
abi break because on new compilation the hash values on 64bit platforms will
change. The lost entropy is irrelevant because the hash is not used in an
cryptophically relevant context. For the abi break i am not sure how severe
this change is.


[1] ABI mismatch on boot on arm32 system

(https://lists.gnu.org/archive/html/help-guix/2024-11/msg00022.html)


Christoph Buck (1):
  guix: records: Fix abi check in cross compile context

 guix/records.scm | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)


base-commit: 2a6d96425eea57dc6dd48a2bec16743046e32e06
-- 
2.45.1





Information forwarded to guix <at> cbaines.net, dev <at> jpoiret.xyz, ludo <at> gnu.org, othacehe <at> gnu.org, zimon.toutoune <at> gmail.com, me <at> tobias.gr, guix-patches <at> gnu.org:
bug#74296; Package guix-patches. (Mon, 11 Nov 2024 00:22:01 GMT) Full text and rfc822 format available.

Message #8 received at 74296 <at> debbugs.gnu.org (full text, mbox):

From: Christoph Buck <dev <at> icepic.de>
To: 74296 <at> debbugs.gnu.org
Cc: Christoph Buck <dev <at> icepic.de>
Subject: [PATCH 1/1] guix: records: Fix abi check in cross compile context
Date: Sun, 10 Nov 2024 19:23:01 +0100
* guix/records.scm: Use 32bit hash value for abi check to prevent
`record-abi-mismatch-error` in a cross-compile context

Change-Id: I889747b1a2837bee8bf9b4de5729fdcf1b165380
---
 guix/records.scm | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/guix/records.scm b/guix/records.scm
index dca1e3c2e7..2084499e36 100644
--- a/guix/records.scm
+++ b/guix/records.scm
@@ -415,11 +415,13 @@ (define-syntax define-record-type*
       ;; list of symbols.
       (syntax-case field-specs ()
         (((field get properties ...) ...)
-         (string-hash (object->string
-                       (syntax->datum #'((field properties ...) ...)))
-                      (cond-expand
-                        (guile-3 (target-most-positive-fixnum))
-                        (else most-positive-fixnum))))))
+         (let ((hash-value
+                (string-hash
+                 (object->string (syntax->datum #'((field properties ...) ...))))))
+           (cond
+            ((< most-positive-fixnum (ash 1 32)) hash-value)
+            ((< most-positive-fixnum (ash 1 64)) (ash hash-value -32))
+            (else (error "unexpected!" most-positive-fixnum)))))))
 
     (syntax-case s ()
       ((_ type syntactic-ctor ctor pred
-- 
2.45.1





Information forwarded to guix-patches <at> gnu.org:
bug#74296; Package guix-patches. (Tue, 12 Nov 2024 22:43:02 GMT) Full text and rfc822 format available.

Message #11 received at 74296 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Christoph Buck <dev <at> icepic.de>
Cc: Josselin Poiret <dev <at> jpoiret.xyz>,
 Simon Tournier <zimon.toutoune <at> gmail.com>, Mathieu Othacehe <othacehe <at> gnu.org>,
 Tobias Geerinckx-Rice <me <at> tobias.gr>, 74296 <at> debbugs.gnu.org,
 Christopher Baines <guix <at> cbaines.net>
Subject: Re: [bug#74296] [PATCH 0/1] Fix abi mismatch error on boot for
 cross-compiled images
Date: Tue, 12 Nov 2024 23:40:08 +0100
Hi Christoph,

Christoph Buck <dev <at> icepic.de> skribis:

> During compilation guix stores a hash of the record field names in the
> compiled go files. On runtime this has is recalcuated and checked against the
> stored hash to verify that no abi mismatch occured. As described in [1] this
> hash differs if the corresponding record was compiled in a cross-compiled
> context. Guile uses internally an `unsigned long` to store the hash, which
> results in hashes of different sizes depending on the platform the guile
> compiler is executed on. Guix already tries to work around this problem by
> limiting the size of the hash in a cross-compile context to the most positive
> fixnum size of the target, but this is insufficient, because, as one can look
> up in the guile source code, the size is limited by an modulo operation after
> the hash was already calculated for an 8byte unsigned long. Therefore the
> resulting hashes during compilation and execution are different and an abi
> mismatch error is erroneously reported during runtime.
>
> An easy workaround is documented in the guile src namely in an comment of the
> `JENKINS_LOOKUP3_HASHWORD2`, which is used to calculate the hash:
>
>> Scheme can access symbol-hash, which exposes this value. For
>>cross-compilation reasons, we ensure that the high 32 bits of the hash on a
>>64-bit system are equal to the hash on a 32-bit system.  The low 32 bits just
>>add more entropy.
>
> This suggest the following workaround. Always limit the hash size to 32bit
> even if executed on a 64bit platform (or to be more specific a platform where
> ulong is 8bytes big). Do this by right shift the hash value 32bits and don't
> rely on the size parameter of the `string-hash` function. This is what this
> patch tries to accomplish.

Woow, thanks for the investigation & explanation!

(I would say that the ‘scm_ihash’ implementation as a mere modulo is
dubious, but that’s hard to change anyway.)

> Imho this approach has two drawbacks. Lost entropy on 64 bit machines and the
> abi break because on new compilation the hash values on 64bit platforms will
> change. The lost entropy is irrelevant because the hash is not used in an
> cryptophically relevant context. For the abi break i am not sure how severe
> this change is.

Capping at 32-bits means that potentially some ABI changes could go
unnoticed, but that’s extremely unlikely if the hash function is good
enough.

I believe the ABI break is fine too: developers will have to
“make clean-go && make”, but that’s okay.

Thoughts?  Opinions?

Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#74296; Package guix-patches. (Wed, 13 Nov 2024 14:06:05 GMT) Full text and rfc822 format available.

Message #14 received at 74296 <at> debbugs.gnu.org (full text, mbox):

From: Christoph Buck <dev <at> icepic.de>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: Josselin Poiret <dev <at> jpoiret.xyz>,
 Simon Tournier <zimon.toutoune <at> gmail.com>, Mathieu Othacehe <othacehe <at> gnu.org>,
 Tobias Geerinckx-Rice <me <at> tobias.gr>, 74296 <at> debbugs.gnu.org,
 Christopher Baines <guix <at> cbaines.net>
Subject: Re: [bug#74296] [PATCH 0/1] Fix abi mismatch error on boot for
 cross-compiled images
Date: Wed, 13 Nov 2024 13:45:49 +0100
Ludovic Courtès <ludo <at> gnu.org> writes:

> Woow, thanks for the investigation & explanation!

Your are welcome :) I usually keep notes during investigation of bugs
and append them to my patches. This keeps my train of thought
transparent and makes it easier for others to follow along or spot
obvious errors on my side. However, it can get a little bit noisy. So
let met now if i should "keep it done" more.

> Capping at 32-bits means that potentially some ABI changes could go
> unnoticed, but that’s extremely unlikely if the hash function is good
> enough.

Yes, but this problem exits for 32bit builds in general.

> I believe the ABI break is fine too: developers will have to
> “make clean-go && make”, but that’s okay.

Good to know.

-- 
Best regards

Christoph




Information forwarded to guix-patches <at> gnu.org:
bug#74296; Package guix-patches. (Sat, 16 Nov 2024 10:59:02 GMT) Full text and rfc822 format available.

Message #17 received at 74296 <at> debbugs.gnu.org (full text, mbox):

From: Simon Tournier <zimon.toutoune <at> gmail.com>
To: Christoph Buck <dev <at> icepic.de>, Ludovic Courtès
 <ludo <at> gnu.org>
Cc: Christopher Baines <guix <at> cbaines.net>, Mathieu Othacehe <othacehe <at> gnu.org>,
 Josselin Poiret <dev <at> jpoiret.xyz>, Tobias Geerinckx-Rice <me <at> tobias.gr>,
 74296 <at> debbugs.gnu.org
Subject: Re: [bug#74296] [PATCH 0/1] Fix abi mismatch error on boot for
 cross-compiled images
Date: Sat, 16 Nov 2024 08:05:07 +0100
Hi Christoph,

On Wed, 13 Nov 2024 at 13:45, Christoph Buck <dev <at> icepic.de> wrote:

>> Woow, thanks for the investigation & explanation!
>
> Your are welcome :) I usually keep notes during investigation of bugs
> and append them to my patches. This keeps my train of thought
> transparent and makes it easier for others to follow along or spot
> obvious errors on my side. However, it can get a little bit noisy. So
> let met now if i should "keep it done" more.

I like this sentence attributed to Leslie Lamport: « If you're thinking
without writing, you only think you’re thinking. ».  For what my opinion
is worth, your explanations appears to me the good ratio between the
“too much details” and the “help outsider to follow”.


Cheers,
simon




Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Mon, 18 Nov 2024 10:08:02 GMT) Full text and rfc822 format available.

Notification sent to Christoph Buck <dev <at> icepic.de>:
bug acknowledged by developer. (Mon, 18 Nov 2024 10:08:02 GMT) Full text and rfc822 format available.

Message #22 received at 74296-done <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Christoph Buck <dev <at> icepic.de>
Cc: Josselin Poiret <dev <at> jpoiret.xyz>,
 Simon Tournier <zimon.toutoune <at> gmail.com>, Mathieu Othacehe <othacehe <at> gnu.org>,
 Tobias Geerinckx-Rice <me <at> tobias.gr>, 74296-done <at> debbugs.gnu.org,
 Christopher Baines <guix <at> cbaines.net>
Subject: Re: [bug#74296] [PATCH 0/1] Fix abi mismatch error on boot for
 cross-compiled images
Date: Mon, 18 Nov 2024 11:07:24 +0100
Hi,

Christoph Buck <dev <at> icepic.de> skribis:

> Ludovic Courtès <ludo <at> gnu.org> writes:

[...]

>> I believe the ABI break is fine too: developers will have to
>> “make clean-go && make”, but that’s okay.
>
> Good to know.

I added a summary of your explanation as a comment in the code, so our
future selves get an idea of why things are done this way, and pushed as
23cbbe6860782c5d4a0ba599ea1cda0642e91661.

Time for “make clean-go && make”!

Thanks,
Ludo’.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 16 Dec 2024 12:24:16 GMT) Full text and rfc822 format available.

This bug report was last modified 187 days ago.

Previous Next


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